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
| Piece | Artifact | Responsibility |
|---|---|---|
| Studio / control plane | apps/control-plane | Tenants, 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/site | Prerendered apex marketing Worker; staging cutover code on main (brilliant.rocks → site, app. → studio) — see Marketing site. |
| Conductor | services/conductor | WorkspaceDO + container; Pi Durable (PiHarness) in-isolate (OpenCode until #546); LLM proxies; preview; D1 lifecycle; deploy |
| Dispatch | services/dispatch | WFP published apps; mint x-brilliant-context; RealtimeDO; AppRpc / PlatformData |
| Template | packages/template | Seed app: TanStack Start, @workspace/data, @brilliant/db |
| Agent image | infra/agent-image | Debian + 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 agent | services/conductor/src/coding-agent/ | Pi runtime (pi/), tools, prompts, skills (Conductor — Pi Durable) |
Five journeys (summary)
- 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. - Agent turn — Studio talks the Brilliant agent wire
/w/:ws/agent/*(packages/rpc; Pi events plus Brilliant frames) with aws: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 (nativectx.containeron side envs; Sandbox SDK on staging/prod until cutover). Source stays DO-authoritative and syncs one-way to plain/workspacedisk (Conductor). - Live preview — Opening a workspace fires
POST …/warmfirst (fire-and-forgetensureDevServer, 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. - 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.
- End user of published app — Hit dispatch (path mode
/a/<script>/whenAPPS_DOMAINunset; withAPPS_DOMAINfrom #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)
| Boundary | Mechanism |
|---|---|
| Browser ↔ control plane | Session cookie (studio login) |
| Control plane ↔ conductor | Service binding + shared guard header |
| Browser ↔ conductor (preview / agent wire) | User capability tokens (ws: scope) |
| Conductor ↔ container | Session capability only; real provider keys stay in Worker proxies |
| Dispatch ↔ user Worker | Strip 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
| Store | Authoritative for |
|---|---|
| Postgres (Aurora via Hyperdrive) | Identity, tenancy, app catalog, billing/usage projections |
| Per-workspace D1 | Generated app user data (until the #516 cutover) |
| Collection DO (SQLite), one per collection | Generated 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 storage | Turn / deploy / D1 id caches for that workspace (same DO as the file store) |
| Dispatch namespace + assets | What end users actually run |
Where a change goes
| Change type | Primary location |
|---|---|
| Identity / policy / billing schema | apps/control-plane (+ migrations) |
| Agent tools / prompts | services/conductor/src/coding-agent/ |
| Preview / deploy / container lifecycle | services/conductor |
| Published routing / edge identity | services/dispatch |
| Every new generated app’s shape | packages/template (+ agent image rebuild for baked template) |
| Durable cloud resources | infra/pulumi |