Layers with one direction of dependency
The web app depends on domain contracts; domain contracts depend on nothing but Zod and TypeScript. Firebase and the inference adapters sit behind interfaces, which is why the product runs in local demo mode with no backend at all.
The layers
Responsibilities as they are implemented in the repository, not as a future diagram.
| Layer | Responsibility |
|---|---|
| apps/web · routes | Next.js App Router with strict TypeScript. Public pages are static; workspace pages are client components behind auth and onboarding gates. |
| apps/web · design system | CSS custom properties for six themes, plus UI primitives (button, card, field, dialog, table) that every surface reuses. |
| apps/web · domain | Zod schemas for every stored shape, a typed error taxonomy with recovery text, the entitlement engine and the plan catalog. |
| apps/web · inference | The capability probe, the routing decision and the local/cloud adapters. Every decision carries a reason code. |
| apps/web · persistence | IndexedDB repositories for local records; Firestore and Storage clients only when Firebase is configured. |
| functions · callables | One wrapper for authentication, App Check, input parsing, correlation ids, rate limits and error translation. |
| functions · modules | Identity, organizations, roles, entitlements, usage, inference, agents, workflows, knowledge, integrations, payments, SSO, notifications and admin. |
| Firebase services | Auth, Firestore, Cloud Storage, AI Logic (Gemini) and App Check, each with rules or configuration as code. |
Contracts do the heavy lifting
A callable cannot return an untyped failure, and a stored document cannot bypass its schema.
- One callable envelope
- Authentication, App Check, input parsing, correlation id and error translation happen once, above every handler. Handlers fail only through the taxonomy.
- Errors travel intact
- The backend ships a WireError {code, message, recovery, retryable, correlationId}. The client preserves the server's code so the UI shows the same explanation the server decided on.
- Schemas at the edges
- Inputs are parsed with Zod before a handler runs; stored shapes are parsed on read. A malformed document surfaces as DOCUMENT_INVALID rather than a half-filled screen.
- Events, not side effects
- Cross-module effects use named events (PaymentSettled.v1, EntitlementGranted.v1, …) delivered at least once and consumed idempotently, deduplicated by event id.
Runtime shape
One region per deployment, set by configuration. Nothing here assumes a specific cloud region.
Functions run on the Node 22 runtime with a configured region (default us-central1 in the repository configuration). Global settings cap instances and allow concurrent requests per instance; scheduled jobs cover renewals, expiry sweeps, abuse detection, webhook delivery and data purge.
The browser never holds a server credential. Provider secrets live in Secret Manager; the web client reads only public identifiers from its environment.
Read the contracts themselves
The API reference maps every callable to its authorization rule, idempotency behaviour and error codes.