Skip to content

Architecture overview ​

Brilliant is four (plus) Cloudflare Workers and a container image organised around one rule: agent + generated apps are untrusted; every privilege is a short-lived signed token or a service binding checked at a platform edge.

Long form in-repo: docs/ARCHITECTURE.md (source-cited, marks unverified), narrative walkthrough docs/ARCHITECTURE-EXPLAINED.md. Prefer code when they disagree.

Pieces ​

PieceArtifactResponsibility
Studio / control planeapps/control-planeTenants, users, memberships, workspaces, apps, tokens, access policy, SPA; since #516 also the collection directory and current permission snapshots (Permissions & app data)
Marketing site (#318 + #361 merged)apps/sitePrerendered apex marketing Worker; staging cutover code on main (brilliant.rocks → site, app. → studio) — see Marketing site.
Conductorservices/conductorWorkspaceDO + container; Pi Durable (PiHarness) in-isolate (OpenCode until #546); LLM proxies; preview; D1 lifecycle; deploy
Dispatchservices/dispatchWFP published apps; mint x-brilliant-context; RealtimeDO; AppRpc / PlatformData
Templatepackages/templateSeed app: TanStack Start, @workspace/data, @brilliant/db
Agent imageinfra/agent-imageDebian + syncd + bun/node + baked template under /opt. Native (side envs, #239): entrypoint tini -- sleep infinity, no /sandbox. Legacy (staging/prod until cutover): @cloudflare/sandbox entrypoint /sandbox
Coding agentservices/conductor/src/coding-agent/Pi runtime (pi/), tools, prompts, skills (Conductor — Pi Durable)

Five journeys (summary) ​

  1. Create app / workspace — Control plane inserts rows, fires conductor init (seed template, provision per-workspace D1 / data script). Container boot is not on the HTTP critical path.
  2. Agent turn — Studio talks the Brilliant agent wire /w/:ws/agent/* (packages/rpc; Pi events plus Brilliant frames) with a ws: capability token. Before #546 this was OpenCode's API on /w/:id/oc. Pi Durable runs in the DO; shell/LSP/build run in the workspace container (native ctx.container on side envs; Sandbox SDK on staging/prod until cutover). Source stays DO-authoritative and syncs one-way to plain /workspace disk (Conductor).
  3. Live preview — Opening a workspace fires POST …/warm first (fire-and-forget ensureDevServer, no agent boot) so the container is warming before the iframe asks (#308, merged). Then iframe on preview host → conductor → ensureDevServer (vite) with session token for draft DB access.
  4. Publish — Build in container → upload assets + script into WFP dispatch namespace; record deploy state. Studio UX since #803 (merged 2026-10-11): clicking Publish reserves a blank tab before the async deploy (keeps popup permission), then on success opens the published URL there with no opener; the draft canvas and preview iframe stay as they were (no Live tab switch, no preview-token remint). The tab closes on failure; a blocked popup does not fail the publish, and the published-app link stays available.
  5. End user of published app — Hit dispatch (path mode /a/<script>/ when APPS_DOMAIN unset; with APPS_DOMAIN from #413 merged: https://<script>.<apps-domain>/a/<script>/) → auth (capability token / guard / public policy) → mint context JWT → user Worker + D1.

Details and caveats: subsystem pages below. Access-policy enforcement has had serious bugs historically; treat Dispatch + ADRs as living docs.

Trust boundaries (short) ​

BoundaryMechanism
Browser ↔ control planeSession cookie (studio login)
Control plane ↔ conductorService binding + shared guard header
Browser ↔ conductor (preview / agent wire)User capability tokens (ws: scope)
Conductor ↔ containerSession capability only; real provider keys stay in Worker proxies
Dispatch ↔ user WorkerStrip inbound cookies/guard/context; mint fresh x-brilliant-context

Full token catalogue: see docs/ARCHITECTURE.md §5 (“token zoo”). Do not document secret values here.

Authoritative stores ​

StoreAuthoritative for
Postgres (Aurora via Hyperdrive)Identity, tenancy, app catalog, billing/usage projections
Per-workspace D1Generated app user data (until the #516 cutover)
Collection DO (SQLite), one per collectionGenerated app user data on main after #516: platform-governed, owned by a source app, reached only through the PlatformData gateway. See Permissions & app data
DO Workspace store (SQLite)Draft app source — sole authority; container /workspace is a disposable replica
DO storageTurn / deploy / D1 id caches for that workspace (same DO as the file store)
Dispatch namespace + assetsWhat end users actually run

Where a change goes ​

Change typePrimary location
Identity / policy / billing schemaapps/control-plane (+ migrations)
Agent tools / promptsservices/conductor/src/coding-agent/
Preview / deploy / container lifecycleservices/conductor
Published routing / edge identityservices/dispatch
Every new generated app’s shapepackages/template (+ agent image rebuild for baked template)
Durable cloud resourcesinfra/pulumi