2.1 KiB
2.1 KiB
Sprimo Frontend Architecture
Workspace Layout
crates/sprimo-app: process entrypoint and runtime wiring.crates/sprimo-tauri: Tauri 2.0 alternative frontend entrypoint.crates/sprimo-api: axum-based localhost control server.crates/sprimo-config: config schema, path resolution, persistence.crates/sprimo-platform: platform abstraction for overlay operations.crates/sprimo-protocol: shared API/state/command protocol types.crates/sprimo-runtime-core: shared runtime core for command/state/API orchestration.crates/sprimo-sprite: sprite pack manifest loading and fallback logic.
Runtime Data Flow
- Frontend (
sprimo-apporsprimo-tauri) initializessprimo-runtime-core. - Runtime core loads/creates
config.tomland builds initialFrontendStateSnapshot. - Runtime core starts
sprimo-apion a Tokio runtime. - API authenticates commands and deduplicates IDs.
- Commands are bridged from API channel into frontend-specific command handlers.
- Frontend adapter applies rendering/window effects and runtime core applies snapshot/config state.
- Shared snapshot is exposed by API via
/v1/stateand/v1/health.
Sprite Reload Semantics
SetSpritePackuses a two-phase flow:
- Validate and build candidate pack runtime (manifest + clips + atlas layout + texture handle).
- Commit atomically only on success.
- On reload failure, current pack remains active and snapshot
last_erroris updated.
Threading Model
- Main task: startup + shutdown signal.
- API task: axum server.
- Bridge task: forwards API commands into Bevy ingest channel.
- Bevy main thread: rendering, animation, command application, and window behavior.
- Tauri thread/runtime: webview UI, event loop, and runtime command consumer.
- Optional hotkey thread (Windows): registers global hotkey and pushes recovery events.
- Snapshot is shared via
Arc<RwLock<_>>.
Design Constraints
- Bind API to localhost only.
- Token auth by default for mutating and state endpoints.
- Keep protocol crate renderer-agnostic for future backend/frontend reuse.
- Keep platform crate isolated for per-OS implementations.