Expand description
§Track Module
§Responsibilities
This module acts as the central request dispatcher for the Mountain
application. It is the primary entry point for all incoming commands and RPC
calls, whether they originate from the Sky frontend or a Cocoon
sidecar.
§Core Functions:
- Request Routing: Route all incoming requests from frontend and sidecars
- Effect Creation: Transform string-based command/RPC names into strongly-typed ActionEffects
- Command Dispatching: Execute effects through the ApplicationRunTime
- Error Handling: Provide comprehensive error handling and recovery
- Type Safety: Ensure type-safe message passing through Rust’s type system
§Architectural Role
The Track module serves as the routing layer in Mountain’s architecture:
Sky (Frontend) ──► Track (Router) ──► ApplicationRunTime (Executor) ──► Services
Cocoon (Sidecar) ──► Track (Router) ──► ApplicationRunTime (Executor) ──► Providers§Design Principles:
- Declarative Effects: Commands create declarative ActionEffects that describe “what” needs to happen, not “how”
- Type-Safe Dispatch: String-based method names are mapped to strongly-typed effects
- Performance-Critical: Direct provider calls are used for hot paths
- Comprehensive Logging: All routing decisions are logged for observability
§Key Components
- FrontendCommand: Frontend command dispatch via Tauri
- SideCarRequest: Sidecar RPC request dispatch via gRPC
- UIRequest: UI request-response result handler
- Webview: Webview message forwarder
- Effect: Effect creation and routing
§TODOs
High Priority:
- Atomize DispatchLogic into submodules
- Add metrics/telemetry for dispatch latency
- Implement command caching for frequently used effects
- Add circuit breaker pattern for failing provider calls
Medium Priority:
- Split CreateEffectForRequest into individual effect modules
- Add request rate limiting per client
- Implement command batching for related operations
- Add warm-up phase for critical paths
Low Priority:
- Add request tracing across the entire pipeline
- Implement request replay for debugging
- Add command versioning for backwards compatibility
Modules§
- Effect
- Effect creation and routing.
Effect creation and routing for
Track. Two siblings:CreateEffectForRequest::Fn(the central router with one domain sub-module per file) andMappedEffectType::MappedEffect(the typed result alias). Nopub usere-exports - callers spell the full path. - Frontend
Command - Frontend command dispatch handling.
Frontend command dispatch. Callers spell
Track::FrontendCommand::DispatchFrontendCommand::DispatchFrontendCommand. - Side
CarRequest - Sidecar RPC request dispatch handling.
Sidecar request dispatch. Callers spell
Track::SideCarRequest::DispatchSideCarRequest::DispatchSideCarRequest. - UIRequest
- UI request-response result handling.
UI request resolution. Single Tauri command lives in
ResolveUIRequest.rs; callers spellTrack::UIRequest::ResolveUIRequest::ResolveUIRequest. - Webview
- Webview message forwarding.
Webview-guest message forwarding. Callers spell
Track::Webview::MountainWebviewPostMessageFromGuest::MountainWebviewPostMessageFromGuest.