Reference
ADR 0001: Go server with SQLite storage
Note (2026-11): the app described here,
web-legacy, was replaced byapps/weband removed from the tree; paths to it below are historical and no longer resolve.
- Status: accepted (2026-11-21); amended 2026-11-21 (see Follow-up)
- Scope:
server/(new). The TypeScript server (packages/server) and core (packages/core) stay as they are.
#Context
The owner asked for the Paprika server to be reimplemented in Go, keeping the same contract: the MCP tools, the .paprika.json format, atomic operations with shared undo/redo, live WebSocket sync for the canvas, lint and export. While this work was in progress the owner asked where the data is stored (only the JSON file, at the time) and chose SQLite. Asked which role SQLite should have, the owner picked "SQLite only; JSON through import/export".
#Decision
- One Go binary (
server/cmd/paprika) withserve,mcp(stdio),import,exportandlist. - SQLite is the only storage of the Go server (pure-Go driver
modernc.org/sqlite, no cgo). Tables:documents,tokens,nodes(one row per node, with the validated JSON plustype/name/parent_idcolumns for plain SQL queries),history(undo and redo stacks) andmeta. One database can hold several documents; a server process serves one of them (--doc, default: the most recently updated). .paprika.jsononly enters or leaves throughpaprika import/paprika export(andGET /api/export). There is no automatic mirror and no file watching.exportoutput is byte-identical to the TypeScript server's file (JSON.stringify(doc, null, 2)+ newline), so it can still be versioned with git.- Undo/redo survives restarts: both stacks are committed in the same SQLite transaction as the document change.
- Every write is committed before it is acknowledged (MCP tools,
POST /api/ops, WebSocketack). If the commit fails, the in-memory state is rolled back. - Two processes on the same database (e.g.
paprika servepluspaprika mcpover stdio) see each other's commits: each process pollsPRAGMA data_versionand reloads the document and history when another connection committed. This replaces the TypeScript server's file watcher. - The TypeScript core stays the reference.
server/internal/coreis a port of@paprika/core(schema,applyOps,History,nodeStyle, render/export, lint, outline, path). Parity is locked by fixtures generated from the TypeScript core (server/scripts/gen-golden.mjs): 72 operation cases, 23 documents (outline, lint, HTML, React, CSS per node), 21 paths, colors and 25 seeded random runs (500 steps of transactions, undo and redo). The Go tests must reproduce every output byte for byte. Validation messages come from a small port of zod v4 (internal/zod) so agents get exactly the same errors. - The MCP contract is shared, not re-described.
server/scripts/gen-contract.mjsdumpstools/list, the instructions and the server info from the TypeScript server intoserver/contract/mcp.json, which the Go binary embeds and serves verbatim.
#Consequences
- The canvas (
web-legacy) is unchanged and still uses the TypeScriptnodeStyle; the Go server serves its build. - Any change to
packages/coreor to the MCP tools must be followed bypnpm go:goldenand a passingpnpm go:test;pnpm check:gofails if the fixtures are stale. - The same black-box suites run against both servers:
packages/server/test/external/parity.test.tsand the canvas E2E (PAPRIKA_SERVER_BIN=…). - Differences from the TypeScript server: storage (SQLite instead of the file),
/api/healthreports the database path infileplusstorageanddocId, the extraGET /api/export,GET /mcpanswers 405 (stateless server, no standalone SSE stream), and the history keeps the entry when an undo fails instead of dropping it. - Screenshots use headless Chromium over CDP (
chromedp), found viaPAPRIKA_CHROMIUM, Playwright's browser cache or the system.
#Alternatives considered
- SQLite as the source with the JSON mirrored on every change (recommended at first): keeps the git workflow automatic, but two sources of truth would need conflict handling. Not chosen by the owner.
- JSON as the source, SQLite only for history: smallest change, but does not answer "store the data in a database".
- Running the TypeScript core inside Go (goja/V8) to avoid a port: no duplicated logic, but heavy, slower and hard to debug; the golden fixtures give the same guarantee.
#Follow-up: TypeScript server removed
- Date: 2026-11-21. Decided by the owner: keep only the Go server.
packages/serverwas deleted. The black-box suites moved topackages/e2eand run only against the Go binary (test:api, the former parity suite, andtest:e2e); CI runs them once instead of once per server.- Decision 8 changes: there is no TypeScript server to dump the contract from, so
server/contract/mcp.jsonandguide.pt-BR.mdare now the contract itself, edited by hand and checked bypackages/e2e/test/api.test.ts.scripts/gen-contract.mjsbecamescripts/gen-measure.mjs, which only copies the measure script from@paprika/core. - Decision 7 stays:
packages/coreis still the reference (the canvas runs it) and the golden fixtures still lock the Go port to it.