Skip to content

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.

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).

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}, plus GET /v1/ops (catalog with JSON Schema) and GET /v1/openapi.json.
  • RPC: env.API.invoke(actor, name, input) for other Workers.
  • MCP: one tool per staff operation (orders.advance becomes orders_advance), and the same catalog as a typed crm API 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.

Every call runs as an actor: { kind: "staff" | "customer" | "agent" | "system", userId, email, name, role, accountId? }.

  • Public requests are authenticated by asking AUTH to resolve the cookie, API key or bearer token; cemco-api then 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 accountId by the dispatcher, never by the client.

These are enforced in cemco-api and covered by tests:

  1. Valid order = signed quote document + signed-quote received date + balance remaining. An order cannot move past received until valid; the error names what is missing.
  2. 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.
  3. Commissioning sets warranty start and end (12 months) on every machine of the order and creates 30, 90 and 365-day check-ins.
  4. A down priority ticket marks its machine down; resolving it returns it to operating.
  5. Ticket states: new, diagnosing, parts_on_order, scheduled, waiting_on_customer, resolved, follow_up_complete.
  6. Stock changes only through stock_movements; shipping a parts order deducts stock.
  7. An email with the same Gmail message id is stored once.
  8. A customer sees only their own account’s orders, machines and documents.
  9. Duplicate checks on normalized company name and case-insensitive contact email.
  10. Documents open through short-lived signed links (15 minutes).
  • 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.