Ratspeak app architecture and contributing
The Ratspeak desktop and mobile application pairs a layered Rust workspace (edition 2024, resolver = "3", MSRV 1.90+) with a separate Tauri 2 shell workspace (src-tauri/, edition 2021) and a zero-framework vanilla HTML/CSS/JS frontend (dashboard/).
1. Crate layering & responsibilities
| Workspace crate / dir | Role & dependency boundary |
|---|---|
crates/ratspeak-core | Pure domain types, delivery state machine, Emitter trait, and AppError. Zero Tauri, SQLite, or Reticulum dependencies. |
crates/ratspeak-db | SQLite persistence (bundled rusqlite + r2d2 pool), sequential schema migrations (SCHEMA_VERSION in ratspeak-db/src/db.rs), and query helpers. Depends only on ratspeak-core. |
crates/ratspeak-runtime | Wires rsReticulum, rsLXMF, lrgp-rs, and optional rsLXST (lxst-voice). Owns AppState, .ratspeak-host.lock profile locking, auto-announce loop (default 1 hour via tokio::sync::watch), and async poll loops. Zero Tauri dependencies. |
crates/ratspeak-tauri | #[tauri::command] handlers across domain modules (messaging, contacts, interfaces, network, identity, channels, games, voice, etc.) and TauriEmitter implementing ratspeak_core::Emitter. |
crates/rsnode-update | Firmware update helper crate (provisional tier). |
src-tauri/ | Separate Cargo workspace (edition 2021, own src-tauri/Cargo.lock) hosting the Tauri 2 binary shell, native window/tray integration, and platform capabilities. |
dashboard/ | Vanilla HTML/CSS/JS frontend — no bundler and no npm install. 18 modular CSS files in dashboard/static/css/ concatenate into dashboard/static/style.css via ./dashboard/build-css.sh. JS modules in dashboard/static/js/ load in dependency order from dashboard/index.html under the RS namespace (the only third-party asset is vendor/jsQR.js). |
2. Startup sequence & IPC flow
- Tauri's
.setup()insrc-tauri/src/lib.rscallsratspeak_tauri::init_core(data_dir, app_handle). - The core acquires the exclusive profile lock (
.ratspeak-host.lock) and opens/migrates the SQLite pool viaratspeak-db. AppHandleis wrapped inTauriEmitter(Arc<dyn Emitter>) and attached toAppState.ratspeak_runtime::init_rns_lxmf()spawns asynchronously: starts the Reticulum runtime, initializes the LXMF router/delivery manager, registers destinations, and begins background poll/announce loops.- In parallel, the WebView loads
dashboard/index.htmldirectly via Tauri's asset protocol. All frontend↔backend traffic useswindow.__TAURI__.core.invokeandwindow.__TAURI__.event.listen— there is no embedded localhost HTTP server.
3. SQLite lock & migration contract
Contributors modifying storage or lifecycle code must preserve three safety invariants:
- Single-instance profile lock (
.ratspeak-host.lock): On startup,ratspeak-runtimeacquires an OS file lock in the.ratspeakdata root. If another Ratspeak process already holds the profile, startup halts cleanly withstartup_error(code: "profile_in_use") without touching the database. On filesystems that do not support locking, the core warns viaprofile_lock_warning. - WAL mode &
r2d2pooling:ratspeak.dbruns in SQLite WAL mode (ratspeak.db-wal/ratspeak.db-shm). Blocking SQLite work must stay on established worker threads — anasync fnsignature alone does not keep blocking queries off Tokio executor threads. Never delete-walfiles out from under a profile. - Sequential, one-way migrations (
SCHEMA_VERSION): Schema migrations live inratspeak-db/src/db.rs(schema54on Ratspeak 1.1.x). Opening a profile created by a newer schema version fails closed withstartup_error(code: "schema_newer"withfoundandsupportedversions) and opens the database read-only rather than risking downgrade corruption.
4. Cargo feature gates
| Feature | Default | Purpose |
|---|---|---|
serial | On (desktop) | USB/serial RNode, Serial, and KISS interfaces via serialport. Disabled on mobile (default-features = false). |
ble | On (desktop/mobile) | Bluetooth LE RNode and Bluetooth Peer mesh across rns-interface, rns-runtime, and ratspeak-runtime. |
seed | On (ratspeak-runtime) | Pure-Rust BIP-39 12-word mnemonic identity derivation via rns-ratkey (no PC/SC dependency). |
hardware | On (desktop src-tauri) | Experimental YubiKey 5 PIV identities via rns-ratkey/hardware (implies seed). |
lxst-voice | On (src-tauri) | Experimental voice calls via rsLXST + cpal (non-commercial LXST license; omit with --no-default-features). |
rnode-tcp | On (mobile) | RNode-over-TCP interface support for iOS/Android Wi-Fi radio bridges. |
mobile-throttle | On (mobile) | Slows background poll/tick/scan loops when mobile apps are backgrounded (disabled on desktop). |
5. Local development & test loop
Assemble the five-repository sibling layout from Building from source, then iterate inside the owning repo:
# 1. Rebuild dashboard/static/style.css after editing dashboard/static/css/*.css
cd Ratspeak && ./dashboard/build-css.sh
# 2. Launch desktop app in dev mode (reloads dashboard assets on relaunch)
cd Ratspeak/src-tauri && cargo tauri dev
# 3. Fast single-crate test loops
cd Ratspeak && cargo test -p ratspeak-db
cd Ratspeak && cargo test -p ratspeak-runtime
cd Ratspeak && cargo test -p ratspeak-tauri
# 4. Full workspace test suites across affected repos
cd rsReticulum && cargo test --workspace
cd rsLXMF && cargo test --workspace
cd Ratspeak && cargo test --workspace
6. Contributing & pull request checklist
- File issues and PRs in the owning repository: App UI/runtime bugs go to
ratspeak/Ratspeak; protocol/daemon bugs toratspeak/rsReticulumorratspeak/rsLXMF; handheld firmware toratspeak/ratspeak-handheld; documentation updates toratspeak/ratspeak-docs. - Format, lint, and test before opening a PR: Run
cargo fmt --check,cargo clippy, andcargo test --workspacein every affected workspace (plus API baseline checks when touching public protocol surfaces). - Commit bottom-up for cross-repo changes: Land changes in
rsReticulum→rsLXMF→Ratspeakso each repository compiles independently at every commit. - Never commit secrets or runtime data: Keep
.ratspeak/,.reticulum/,.db,.key, recovery phrases, and personal data out of PRs and issue reports. - Include evidence in your PR: List affected repos, exact commands run, screenshots for UI/docs changes, and board/radio details for hardware work.
Next steps
- Follow exact release-reproducible builds in Building from source.
- Inspect frontend↔backend command domains, events, and error codes in Tauri IPC reference.