Files
piik/docs/adr/0016-shared-rust-core.md
T
AAA 6584e7d936 docs(adr): remove decision records for the 2.x line and ended experiments
ADR-0001, 0002, 0004, 0005, 0006, 0007, 0010, 0011 and 0012 describe published
2.x or experiments that ended; their own scope lines hand 3.0 to ADR-0016, the
canon and the 3.0 models. No living 3.0 document relied on them: the media
standard's two ADR-0007 citations were obsolete, since the standard states the
3.0 codec rules itself and the 3.0 preflight probes the real track rather than
ADR-0007's synthetic one; it now points to the preflight code. Citations from
the records that stay (ADR-0008, 0009, 0014, 0016) and from 2.x research now
link the records on main, and the hygiene path list no longer requires
ADR-0001 and ADR-0010. History stays in Git and on main.
2026-11-25 23:57:48 +08:00

4.6 KiB

ADR-0016: Shared Rust Core For 3.0

  • Status: accepted for 3.0
  • Date: 2026-11-25

Context

Published 2.x runs a Go backend (ADR-0012) with one Host per room, memory-resident rooms (ADR-0002) and an embedded SFU as the fallback route. Its room, signaling and routing rules live in that server.

3.0 changes what a room is. Several people share at once, and a room carries conversation with history, files, room voice and synchronized viewing. A room can be operated by a Browser page, the desktop App or a Server, so the same admission, ordering and routing rules must run in all three. Writing them once per runtime would let the three diverge, which is the cost ADR-0010 and ADR-0012 each accepted a larger runtime to avoid.

The isolated 3.0 line implements this shared-core architecture.

Decision

  1. One Rust crate, channel-core, owns domain admission, room authority, signed conversation and history rules, activity and publication plans, and transport leases. Callers supply connection identity and time and deliver events. The domain rules are separate from the optional SQLite persistence implementation packaged in the same crate.
  2. Three adapters execute that crate and own their local resources: Browser through WASM with IndexedDB, Native with SQLite and the RTC SDK, and Server for domain HTTP and WebSocket I/O, which also composes the App. Adapters bind runtime identities, invoke the shared rules for their role and execute the resulting effects.
  3. The hierarchy is Channel, Room, Activity. A channel owns identities, the room directory and signaling. Each available room has exactly one writer, which commits history before it confirms. Each activity selects its own delivery paths over one channel pool of confirmed endpoint pairs.
  4. The channel's hosting mode places the room writer: on the creator's Browser or App in a lightweight channel, on the Server in a hosted one. Access is a separate room setting.
  5. Media stays automatic and peer-to-peer first. ICE, DTLS, SRTP, SCTP and congestion control belong to Browser WebRTC and the Native RTC SDK. Native forwards encoded media; a Browser that relays decodes and encodes again.
  6. For 3.0 this replaces the backend architecture selected by ADR-0012. Published 2.x keeps its own records on main until the cutover that versioning defines.

Authority Of Documents

This record and the engineering maps state the architecture. The network, room-data, forwarding and hosting documents describe the running prototype and its target designs, with their measurements and dates. Source schemas own exact wire and storage shapes. The latest explicit user decision and the accepted design for the applicable version govern intended behavior. Code and measurements establish current behavior. Track unresolved design conflicts in TODO.

Consequences

  • One implementation of the rules runs in three runtimes, and a Browser can operate a room with no server holding its history.
  • The Web build depends on the Rust toolchain and a WASM binding.
  • Two storage adapters exist. Their decisions belong in the core; a shared scenario replayed by both adapters keeps the remaining code equivalent.
  • A Browser relay costs a decode and an encode per hop, which a route through Native does not.
  • This runtime does not serve the 2.x wire, storage or deployment contracts. Major-upgrade guidance owns what an existing site and its users are told at the cutover.
  • Route calibration, relay preference and field measurement stay open in TODO; this record does not decide them.

The documentation owner map distinguishes this architecture decision from detailed domain models and measured behavior.

References