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

86 lines
4.6 KiB
Markdown

# 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](https://github.com/TNTcraftHIM/Piik/blob/main/docs/adr/0012-shared-go-backend-core.md))
with one Host per room, memory-resident rooms
([ADR-0002](https://github.com/TNTcraftHIM/Piik/blob/main/docs/adr/0002-memory-resident-protected-rooms.md)) 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`](../../prototype/channel-core/src), 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](../../prototype/channel-browser) through WASM with IndexedDB,
[Native](../../prototype/channel-native) with SQLite and the RTC SDK, and
[Server](../../prototype/channel-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](../standards/versioning.md) defines.
## Authority Of Documents
This record and the [engineering maps](../standards/engineering.md#module-map)
state the architecture. The [network](../research/channel-network-design.md),
[room-data](../research/channel-storage-and-identity.md),
[forwarding](../research/channel-forwarding-plan.md) and
[hosting](../research/server-hosting-plan.md) 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](../standards/versioning.md#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](../todo.md); this record does not decide them.
The [documentation owner map](../standards/documentation.md#owners) distinguishes
this architecture decision from detailed domain models and measured behavior.
## References
- [Project memory](../project-memory.md) and [status](../status.md)
- [Sans-I/O protocol design](https://sans-io.readthedocs.io/how-to-sans-io.html):
protocol logic that performs no I/O can be driven by any runtime.
- [str0m](https://github.com/algesten/str0m), the Native RTC SDK, follows the
same separation.