Linora

0002. Layering and dependency rules

Status: Accepted (2026-11-27, revised for ADRs 0019-0022)

Context

The render loop must stay isolated from sync and UI. Server tiers must reuse document rules without pulling in WebGL/DOM, and the realtime tier must never materialize documents.

Decision

Allowed imports (anything not listed is forbidden):

Package May import Runtime APIs
shared nothing ES2022 only
packages/doc shared ES2022 only
packages/sync-client shared, doc ES2022 + global WebSocket/fetch
packages/engine shared, doc DOM, WebGL2
packages/editor shared, doc, engine; sync-client types only (DocSession) DOM
packages/server-common shared Node
apps/web shared, doc, engine, editor, sync-client DOM
apps/realtime shared, server-common, doc only ScanBatch, StructIndex, structure codec Node, uWS.js
apps/api shared, server-common, doc only JSON <-> op helpers Node
apps/docworker shared, server-common, doc Node, resvg
apps/mcp shared, doc pure helpers, sync-client connection only Node

Rules:

  1. erasableSyntaxOnly everywhere except legacy web code: no enums, namespaces or parameter properties (Node runs .ts unbundled). Use as const objects.
  2. Relative imports carry .ts extensions.
  3. The engine reads the doc through DocCore.cols and drainChanges() only.
  4. Nothing on the render path allocates per frame or touches the network; nothing on the realtime hot path builds per-op objects.
  5. No tier talks to the database on another tier’s behalf; the only cross-tier entry points are the public API, the realtime protocol and the internal links in ADR 0021.
  6. Enforced by tools/check-deps.mjs (zero-dependency import scanner, including the “only” restrictions via an allow-list of entry files) in npm run check.

Consequences

Client and server validation share one implementation (packages/doc rule tables), and the realtime tier cannot accidentally load a document.