Deploying to Cloudflare
The platform deploys as five Workers. Run deploys from a machine that is logged in to Cloudflare (wrangler login or
CLOUDFLARE_API_TOKEN).
bun run deploy # preview: *.workers.dev, "-preview" data resourcesbun run deploy:production # production: the cemco.app custom domainsBoth build everything first (bun run build), then deploy in dependency order, applying D1 migrations before the
Worker that owns the database:
cemco-auth: migrations, deploycemco-api: migrations, deploy (bindsAUTH)cemco-agents(bindsAPI,AUTH)cemco-mcp(bindsAPI,AUTH)cemco-web(bindsAPI,AUTH,AGENTS)
Add --dry-run to print the steps without running them.
Environments
Section titled “Environments”| Preview (default) | Production (--env production) |
|
|---|---|---|
| Worker names | cemco-web, cemco-api, … |
cemco-web-production, cemco-api-production, … |
| Hosts | *.workers.dev (one host for all three sites, see preview routing) |
custom domains below |
| Data | cemco-crm-preview, cemco-auth-preview, cemco-documents-preview, cemco-events-preview, cemco-agent-events-preview, workflow cemco-import-preview |
cemco-crm, cemco-auth, cemco-documents, cemco-events, cemco-agent-events, workflow cemco-import |
ENVIRONMENT |
preview |
production |
A preview deploy therefore cannot touch production data.
Resources
Section titled “Resources”| Resource | Binding | Owner | Create |
|---|---|---|---|
D1 cemco-crm |
DB |
api | wrangler d1 create cemco-crm before the first deploy (migrations run first) |
D1 cemco-auth |
DB |
auth | wrangler d1 create cemco-auth before the first deploy |
R2 cemco-documents |
DOCS |
api | wrangler r2 bucket create cemco-documents |
Queue cemco-events |
EVENTS (producer and consumer) |
api | wrangler queues create cemco-events |
Queue cemco-agent-events |
AGENT_EVENTS (api produces, agents consume) |
api, agents | wrangler queues create cemco-agent-events |
KV cemco-cache |
CACHE |
api | auto-provisioned |
| Workers AI | AI |
api, mcp, agents | nothing to create |
| Worker Loader | LOADER |
mcp, agents | nothing to create |
| Durable Objects | AssistantAgent, EmailAgent, AccountWatcherAgent |
agents | created by the migration in wrangler.jsonc |
Workflow cemco-import |
IMPORT_WORKFLOW |
agents | created on deploy |
| Send email | EMAIL |
api, auth, agents | needs Email Routing on the domain (below) |
Database and KV ids are left out of the configs. Wrangler can provision the KV namespace on deploy, but create both
databases yourself (see the caution above) and add their database_id to the wrangler.jsonc of the owning Worker if
your wrangler version does not find them by name. Create the queues and the R2 bucket (with -preview names for
preview) before the first deploy as well.
Secrets
Section titled “Secrets”Set each with wrangler secret put <NAME> inside the Worker’s folder (add --env production for production).
| Worker | Secret | Required | What |
|---|---|---|---|
| api | DOCUMENT_SIGNING_SECRET |
yes | Signs the 15-minute document links. A long random string |
| api | ANTHROPIC_API_KEY |
no | Anthropic models for nameplate reading and other AI features |
| auth | BETTER_AUTH_SECRET |
yes | Signs sessions and encrypts stored Google tokens. Without it sign-in reports not connected |
| auth | GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET |
for Google sign-in | OAuth client from Google Cloud; redirect https://auth.cemco.app/auth/callback/google. Enable the Gmail and Calendar APIs for email filing and calendar sync |
| auth | BOOTSTRAP_TOKEN |
first run only | Lets one person create the first admin login at /auth/bootstrap; stops working once a staff login exists. Delete it afterwards |
| agents | ANTHROPIC_API_KEY |
no | Anthropic models for the assistant and email agent (otherwise Workers AI) |
| agents | AGENTS_WEBHOOK_SECRET |
no | Shared secret for POST /agents/v1/watcher/events |
Plain settings are in each wrangler.jsonc under vars (every one is listed with an explanation in the Worker’s
.dev.vars.example): APP_URL, API_URL, AUTH_URL, MCP_URL, COOKIE_DOMAIN (.cemco.app in production),
ADMIN_EMAILS, STAFF_EMAIL_DOMAIN, EMAIL_FROM, EMAIL_ENABLED, and optionally AI_GATEWAY_ID. On cemco-web,
API_ORIGIN is the API’s public origin, which the app’s CSP allows for document previews. Connecting Claude over
OAuth needs both AUTH_URL and MCP_URL on cemco-auth; until both are set, the OAuth endpoints answer not
connected.
Generate a secret with openssl rand -base64 48.
Custom domains
Section titled “Custom domains”The production configs declare custom domains, which Cloudflare creates (DNS and certificates) on deploy when the
cemco.app zone is on the same account:
| Host | Worker |
|---|---|
cemco.app (redirects to www), www.cemco.app, app.cemco.app, docs.cemco.app |
cemco-web-production |
api.cemco.app |
cemco-api-production |
auth.cemco.app |
cemco-auth-production |
mcp.cemco.app |
cemco-mcp-production |
agents.cemco.app |
cemco-agents-production |
- Turn on Email Routing for
cemco.appin the dashboard. - Set up
crm@cemco.appas a sender for theEMAILbindings (customer status emails, invites, sign-in codes), then setEMAIL_ENABLEDto"true"oncemco-apiandcemco-auth. Until then sign-in emails report not connected and the API stores outgoing mail as skipped. - Route
crm@cemco.appto thecemco-agents-productionWorker so mail that staff forward is filed. The Worker accepts mail only from active admins and editors whose message passes DMARC (INBOUND_AUTHSERV_IDnames the authentication service whose results it trusts).
Optional: Cloudflare Access
Section titled “Optional: Cloudflare Access”To add a second gate for staff, create a Zero Trust Access application for app.cemco.app and api.cemco.app that
allows the Google Workspace domain, and bypass it for /portal, /auth/* and the public API routes customers use.
No code change is needed.
After the first deploy
Section titled “After the first deploy”- Sign in at
https://app.cemco.appwith Google using an address inADMIN_EMAILS; it becomes admin. Without Google, useBOOTSTRAP_TOKENathttps://auth.cemco.app/auth/bootstraponce, then remove the secret. - Load data with Import, starting with a dry run.
- Connect Claude to
https://mcp.cemco.app/mcp(see Using the CRM inside Claude).