Linora grows from a single-page WebGL canvas POC into a multiplayer design tool: projects -> files -> pages, Postgres persistence, live cursors, one public API, and an MCP adapter that lets agents edit as collaborators. Two hard constraints shape everything:
npm run bench against docs/perf/baseline.json (ADR 0015).One Vite app, no backend, no tests.
| File | Role today | Problem for the product |
|---|---|---|
src/scene.ts |
Render store: 10 x u32 primitives in z-order, objects = primitive ranges, 1,024-primitive chunks, LOD impostors, hit test, marquee, undo snapshots | Also the only data model: no ids, no tree, world coordinates, text only as glyphs |
src/renderer.ts, shaders.ts |
WebGL2 instanced renderer, dirty-chunk uploads, LOD, GPU drag preview | Good; keep |
src/editor.ts |
Input, all tools and commands, camera, benchmarks (1,242 lines) | Writes primitives directly; no op layer |
src/history.ts |
Undo as closures over primitive snapshots | Cannot do multiplayer undo |
src/overlay.ts |
Canvas2D selection/handles/marquee | No remote cursors/selections |
src/font.ts |
SDF atlas from system-ui |
Metrics differ per OS (ADR 0014) |
src/ui/* |
Toolbar, virtualised layer list, properties, perf panel | Flat list; no shell |
src/stress.ts, website.ts |
Benchmark generators writing primitives | Must generate doc nodes |
Browser (apps/web) Agents (MCP clients) Scripts / integrations
shell + panels + editor + engine apps/mcp (adapter, PAT) (PAT)
sync-client replica (packages/doc) │ │
│ HTTPS /v1 (JSON) │ WSS /v1/realtime (binary) │ both │ HTTPS /v1
▼ ▼ ▼ ▼
┌─────────────────────────── Edge load balancer (TLS, HSTS) ────────────────────────────┐
│ /v1/realtime?file=F and /v1/files/F/pages/*/ops -> hash(F) -> realtime instance │
│ other /v1/* -> any API instance static web app -> CDN │
└───────┬─────────────────────────────────────────────┬─────────────────────────────────┘
▼ ▼
┌──────────────────────────────┐ internal WS ┌──────────────────────────────────────────┐
│ API service (apps/api) │ ──────────────► │ Realtime (apps/realtime), one per box │
│ stateless: auth, sessions, │ (HTTP op │ gateway threads: sockets, token verify, │
│ PATs, projects, members, │ batches as │ ScanBatch, presence, native fan-out │
│ audit, files, pages, │ the caller) │ room-owner threads (hash fileId): │
│ snapshot streaming, query │ │ StructIndex (14 B/node, lazy), seq, │
│ proxy, realtime tokens │ │ dedupe, journal COPY, rings │
└───┬───────────┬──────────────┘ └───────┬───────────────────▲──────────────┘
│ HTTP │ SQL (pool) SQL (1 conn/owner)│ internal subscriber│
▼ ▼ ▼ │
┌──────────────────────┐ ┌──────────────────────────────────────┐ ┌───────┴────────────────┐
│ Doc workers │◄────│ Postgres: users, sessions, tokens, │ │ Doc workers follow live │
│ (apps/docworker) │ SQL │ projects, members, audit, files, │ │ batches of cached pages │
│ LRU of full pages, │ │ pages, page_ops (journal), │ └────────────────────────┘
│ queries, render │ │ snapshot metadata │
└──────────┬───────────┘ └──────────────────▲───────────────────┘
│ read │ write snapshots
▼ │
┌──────────────────────┐ ┌───────────┴──────────────┐
│ Blob store │◄───────────│ Compactor processes │
│ snapshots + structure│ write │ (docworker --mode=compactor)
└──────────────────────┘ └──────────────────────────┘
Tier boundaries and protocols: ADR 0021. Runtime and capacity: ADR 0020. Validation authority: ADR 0019. API: ADR 0022. Security: ADR 0023, security.md.
| Module | Doc | Depends on |
|---|---|---|
shared/ contracts (ids, props, ops, codec, API schemas, realtime messages, MCP schemas, interfaces) |
shared/src/*.ts |
- |
packages/doc document core, ScanBatch, StructIndex |
document-core.md | shared |
packages/engine render engine |
render-engine.md | shared, doc |
packages/editor tools, commands, gestures, overlay |
editor.md | shared, doc, engine |
packages/sync-client connection + replica session |
sync.md | shared, doc |
apps/realtime |
realtime.md | shared, server-common, doc (validation only) |
apps/api |
api.md | shared, server-common, doc (JSON helpers) |
apps/docworker (+ compactor) |
doc-workers.md | shared, server-common, doc |
| Postgres + blob store | persistence.md | - |
apps/mcp |
mcp.md | shared, doc (helpers), sync-client (connection) |
apps/web shell + panels |
web-app.md | client packages |
| Security | security.md | - |
| Testing | testing.md | - |
Dependency rules: ADR 0002, enforced by tools/check-deps.mjs.
| Now | Target |
|---|---|
src/scene.ts (primitives, chunks, LOD, bounds, hit test) |
packages/engine/src/renderScene.ts |
src/scene.ts (objects, kinds, names, undo snapshots) |
replaced by packages/doc |
src/renderer.ts, shaders.ts, font.ts, camera.ts, perf.ts |
packages/engine/src/ |
src/editor.ts |
packages/editor/src/ split into editor.ts, tools/*, commands.ts, keymap.ts, bench.ts |
src/history.ts |
removed; undo stacks live in packages/sync-client (ADR 0008) |
src/overlay.ts |
packages/editor/src/overlay.ts (+ remote cursors/selections) |
src/ui/* |
apps/web/src/panels/* |
src/main.ts, style.css, index.html |
apps/web/ |
src/stress.ts, website.ts |
packages/doc/src/gen/ (emit node blocks) |
src/color.ts |
shared/src/color.ts |
Local edit. Tool -> ops -> session.commit -> doc.apply(local) with inverse -> undo stack + send queue (flushed once per frame) -> the engine drains changes next frame and re-derives the dirty chunks from the doc’s columns. Drags apply nothing until pointer-up; the GPU preview runs as today and presence carries the affine to peers.
Op pipeline (WS or HTTP). Token -> role/scope -> ScanBatch (gateway, zero-copy) -> ring -> StructIndex.check + seq (owner) -> COPY commit (10 ms window) -> ACK with verdicts to the author, BROADCAST of the accepted ops (one buffer, N sockets).
Remote edit. BROADCAST -> sync-client masks pending keys / rebases pending structural ops -> doc.apply(sequenced) -> engine drains. O(changed nodes).
Open a page. GET /v1/files/F -> GET .../snapshot (gzip blob, inflated by the browser, decoded in a Web Worker into typed arrays) -> engine builds buffers in paint order -> realtime token -> WS subscribe(sinceSeq) -> tail -> live.
Agent edit. MCP tool -> API reads (doc workers) as needed -> ops over its realtime connection (same pipeline) -> ACK -> result with seq; humans see the agent’s cursor and edits live.
Client: CPU + GPU, ADR 0024 (the doc’s columns are the render source; no CPU primitive mirror). Estimates; the memory gate measures them.
| Scene | Today | E1 (first integration) | E2 (optimized) |
|---|---|---|---|
| 4,000 pages (682K nodes, 11M prims) | ~1,106 MB (CPU 585 + GPU 521) | ~605 MB (-45%; CPU 84) | ~589 MB (-47%; CPU 68) |
| 5M shapes | ~549 MB (CPU 312 + GPU 237) | ~545 MB (-1%; CPU 308) | ~500 MB (-9%; CPU 263) |
Realtime instance at 100k connections: ~2.7 GB typical, ~6.5 GB worst case (table in ADR 0020). The structural index is 14 B/node, only for rooms edited in the last 10 minutes (~1.4 GB of that typical total).