Architecture
The Cemco platform runs entirely on Cloudflare: five Workers in one Bun monorepo, wired with Service Bindings. Only
cemco-api touches the CRM database and the document bucket; every other surface reaches the data through it.
Hosts and Workers
Section titled “Hosts and Workers”| Host | Worker | What it is |
|---|---|---|
app.cemco.app, www.cemco.app, docs.cemco.app (and the apex cemco.app, redirected to www) |
cemco-web (workers/web) |
Static assets for the three sites, routed by host name. On app. it proxies /api/*, /auth/* and /agents/* so the browser stays same-origin. See Web Worker and hosts. |
api.cemco.app |
cemco-api (workers/api) |
Hono HTTP API and the CrmService RPC entrypoint. Owns D1 cemco-crm, R2 cemco-documents, Queue cemco-events, KV cemco-cache, the daily cron and outbound email. |
auth.cemco.app |
cemco-auth (workers/auth) |
better-auth: staff and customer sign-in, sessions, API keys, the OAuth 2.1 server for MCP clients. Owns D1 cemco-auth. Exposes AuthService over RPC. |
mcp.cemco.app |
cemco-mcp (workers/mcp) |
Remote MCP server (Agents SDK createMcpHandler, MCP SDK v2): one tool per staff operation, codemode search and execute, MCP Apps views. Holds no data. |
agents.cemco.app |
cemco-agents (workers/agents) |
Durable Object agents (in-app assistant, email filing, account watcher) and the import Workflow. |
browser ──> cemco-web ──(API, AUTH, AGENTS bindings)──┐Claude ──> cemco-mcp ──(API, AUTH)──────────────────┤mail/cron ─> cemco-agents ──(API, AUTH)──────────────┼──> cemco-api ──> D1, R2, Queue, KV cemco-auth <─────┘ (API asks AUTH to resolve sessions)Binding names are fixed across Workers: API (entrypoint CrmService), AUTH (entrypoint AuthService), AGENTS,
DB, DOCS (R2), EVENTS (Queue), CACHE (KV), AI (Workers AI), LOADER (Worker Loader for codemode) and
EMAIL (send email).
One registry, every surface
Section titled “One registry, every surface”Every capability is one operation, defined once in packages/core/src/operations/ with a name, roles and Zod
schemas for input and output. From that single definition:
- HTTP:
POST /v1/ops/{name}, plusGET /v1/ops(catalog with JSON Schema) andGET /v1/openapi.json. - RPC:
env.API.invoke(actor, name, input)for other Workers. - MCP: one tool per staff operation (
orders.advancebecomesorders_advance), and the same catalog as a typedcrmAPI inside codemode. - Agents: AI SDK tools built from the catalog.
- Docs: the API reference on this site is generated from it at build time.
This is how the requirement “works the same in the web app and through Claude” holds: there is only one implementation of each rule. See The operation registry.
Actors
Section titled “Actors”Every call runs as an actor: { kind: "staff" | "customer" | "agent" | "system", userId, email, name, role, accountId? }.
- Public requests are authenticated by asking
AUTHto resolve the cookie, API key or bearer token;cemco-apithen maps the identity to an actor with its CRM role. - The API trusts an actor passed directly only from a Service Binding caller.
- A customer actor is always forced to its own
accountIdby the dispatcher, never by the client.
Business rules
Section titled “Business rules”These are enforced in cemco-api and covered by tests:
- Valid order = signed quote document + signed-quote received date + balance remaining. An order cannot move past
receiveduntil valid; the error names what is missing. - Order stages in order: received, in_build, ready_to_ship, shipped, delivered, set_up, commissioned, trained,
closed. Each move writes
order_events, emits a queue event (customer status email, portal update) and is audited. - Commissioning sets warranty start and end (12 months) on every machine of the order and creates 30, 90 and 365-day check-ins.
- A
downpriority ticket marks its machinedown; resolving it returns it tooperating. - Ticket states: new, diagnosing, parts_on_order, scheduled, waiting_on_customer, resolved, follow_up_complete.
- Stock changes only through
stock_movements; shipping a parts order deducts stock. - An email with the same Gmail message id is stored once.
- A customer sees only their own account’s orders, machines and documents.
- Duplicate checks on normalized company name and case-insensitive contact email.
- Documents open through short-lived signed links (15 minutes).
Front ends
Section titled “Front ends”apps/app: Vue 3 + Vite SPA, the staff app and the customer portal (/portal), built on the Rapport shell from the SaaS Launch Kit with Cemco tokens. An installable PWA with an offline cache and a queue of pending edits.apps/www: the Astro landing page.apps/docs: this site (Astro Starlight).packages/views: the MCP Apps in-chat views (Lit), each built to one self-contained HTML file.
The design contract for every UI surface is docs/design/DESIGN.md in the repository.