PaprikaPaprikaDocs
HomeGitHubPortuguês

Reference

ADR 0001: Go server with SQLite storage

Note (2026-11): the app described here, web-legacy, was replaced by apps/web and removed from the tree; paths to it below are historical and no longer resolve.

#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

  1. One Go binary (server/cmd/paprika) with serve, mcp (stdio), import, export and list.
  2. 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 plus type/name/parent_id columns for plain SQL queries), history (undo and redo stacks) and meta. One database can hold several documents; a server process serves one of them (--doc, default: the most recently updated).
  3. .paprika.json only enters or leaves through paprika import / paprika export (and GET /api/export). There is no automatic mirror and no file watching. export output is byte-identical to the TypeScript server's file (JSON.stringify(doc, null, 2) + newline), so it can still be versioned with git.
  4. Undo/redo survives restarts: both stacks are committed in the same SQLite transaction as the document change.
  5. Every write is committed before it is acknowledged (MCP tools, POST /api/ops, WebSocket ack). If the commit fails, the in-memory state is rolled back.
  6. Two processes on the same database (e.g. paprika serve plus paprika mcp over stdio) see each other's commits: each process polls PRAGMA data_version and reloads the document and history when another connection committed. This replaces the TypeScript server's file watcher.
  7. The TypeScript core stays the reference. server/internal/core is 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.
  8. The MCP contract is shared, not re-described. server/scripts/gen-contract.mjs dumps tools/list, the instructions and the server info from the TypeScript server into server/contract/mcp.json, which the Go binary embeds and serves verbatim.

#Consequences

#Alternatives considered

#Follow-up: TypeScript server removed

Edit this page on GitHub