PaprikaPaprikaDocs
HomeGitHubPortuguês

Reference

ADR 0004: Peer-to-peer team sync (Iroh transport, Loro CRDT, Rust sidecar)

#Context

A small team wants each person to run their own local Paprika, with their own agents, and see everyone else (people and agents) editing the same workspaces, without a central server. The maintainer already chose the building blocks:

  1. Transport: Iroh: QUIC connections dialed by public key, hole punching, relays as a fallback, ed25519 identities.
  2. Convergence by CRDT, with no arbiter. Undo and batches have to become CRDT operations.
  3. Security: an allowlist of the team's public keys (a team file), operations signed by their author (person or agent), and invites by link or QR that expire. Approval roles come later.

Two facts shape how this fits Paprika:

#Decision

#1. Bridge: a Rust sidecar, paprika-sync, spoken to over stdio

paprika serve starts paprika-sync as a child process when the instance belongs to a team and talks to it with newline-delimited JSON on stdin/stdout. The sidecar owns the network, the CRDT documents and the keys; the Go server stays the only writer of SQLite and the only place where applyOps runs.

Option Why not
Sidecar process (chosen) Two binaries to build and ship. In exchange: the Go build stays pure Go (CGO_ENABLED=0, modernc.org/sqlite), a crash in the network stack cannot take the canvas down, and the sidecar can be tested on its own.
iroh-ffi bindings Official targets are Python, Swift, Kotlin and JavaScript. Go would need uniffi-bindgen-go (third party) and cgo, and the FFI surface lags the Rust API.
Rust static library through cgo Gives up the pure-Go build and cross compilation, puts a Tokio runtime inside the Go process and makes every Rust panic a server crash.
Rewrite the transport in Go (quic-go) Iroh's value is hole punching, relays and address lookup by key; reimplementing that is the project, not a bridge.

Without the sidecar binary the server works as before (local only); team features report sidecar not found.

#2. CRDT: Loro, with the node tree in a LoroTree

Loro 1.x Automerge 0.12
Language Rust core (JS/WASM, Swift bindings) Rust core (JS, C)
Tree with concurrent moves Native LoroTree: moves are CRDT operations, cycles are impossible by construction, siblings ordered by fractional index No tree type; a move is delete + insert, so concurrent moves duplicate nodes and the app must repair cycles
Per-field merge LoroMap per node (last writer wins per key) Map per node (same)
Incremental export export(updates from version vector), import buffers out-of-order changes Equivalent
Blob metadata without importing decode_import_blob_meta (which peers a blob carries) Must load the changes

Paprika's document is a tree whose structure changes all the time (move, group, ungroup, pages), so the native movable tree decides it. Mapping:

#3. The Go server stays authoritative for validity

#4. Identity, signatures and the team file

#5. Discovery and relays

The default endpoint uses Iroh's public relays and DNS address lookup, which only help peers find each other and carry end-to-end encrypted QUIC when hole punching fails: they never see document contents and have no authority. A team can point to its own relay. Tests run with relays and lookup disabled, over loopback.

#Consequences

Edit this page on GitHub