Rust/Tauri Bridge Commands
Relevant source files
The following files were used as context for generating this wiki page:
The Rust/Tauri Bridge Commands serve as the critical communication layer between the TypeScript-based frontend ("The Brain") and the Rust-based backend ("The API") in the mausVoice application. Following the architectural principle of "Rust is the API, TypeScript is the Brain," all business logic and decision-making reside in TypeScript, while Rust provides pure native capabilities such as audio capture, keyboard injection, and filesystem access.
Sources: CLAUDE.md, llms.txt, apps/desktop/README.md
Bridge Architecture and Data Flow
The bridge utilizes Tauri's IPC (Inter-Process Communication) mechanism. TypeScript components initiate actions that call into Repositories, which in turn invoke Rust commands defined in the backend. This structure ensures that the frontend remains the single source of truth for state (via Zustand), while delegating hardware-intensive or OS-level tasks to Rust.
The diagram shows the unidirectional flow of requests from the React frontend through the TypeScript bridge to the Rust backend execution layer.
Sources: CLAUDE.md, apps/desktop/README.md
Type-Safe Bindings Generation
To maintain synchronization between Rust and TypeScript, the project uses tauri-specta to auto-generate TypeScript definitions. A dedicated binary, gen_bindings.rs, walks through all annotated Rust commands to emit a bindings.ts file used by the frontend.
Sources: apps/desktop/src-tauri/examples/gen_bindings.rs:6-126, packages/desktop-native-apis/README.md
Key Command Categories
The bridge commands are categorized by their functional domain, covering system capabilities, audio processing, and data persistence.
Audio and Recording
Rust manages the native audio stack, including microphone enumeration and the transcription sidecar.
| Command | Purpose |
|---|---|
start_recording | Initiates native audio capture. |
stop_recording | Ends audio capture and finalized buffer. |
list_microphones | Returns available system input devices. |
pause_recording | Temporarily halts the audio stream. |
Sources: apps/desktop/src-tauri/examples/gen_bindings.rs:90-100
System and Keyboard Interaction
Since mausVoice types directly into other applications, it requires high-level OS permissions and keyboard simulation.
Data Persistence (SQLite)
Rust handles the SQLite database interactions for users, transcriptions, and preferences. Repositories in TypeScript call these commands to sync local state with the disk.
| Domain | Commands |
|---|---|
| Transcriptions | transcription_create, transcription_list, transcription_delete |
| User | user_get_one, user_set_one, user_preferences_set |
| Security | api_key_create, api_key_update (Encrypted via XChaCha20-Poly1305) |
Sources: apps/desktop/src-tauri/examples/gen_bindings.rs:10-120, llms.txt
Implementation Pattern
New commands must follow a specific registration pattern to be accessible through the bridge:
- Define: Add
#[tauri::command]and#[specta::specta]to the function insrc-tauri/src/commands.rs. - Register: Add the command to the
invoke_handlerinapp.rs. - Collect: Add the function to the
collect_commands!macro ingen_bindings.rs. - Generate: Run
pnpm gen:bindingsto update the TypeScriptbindings.ts.
Sources: packages/desktop-native-apis/README.md, CLAUDE.md
Security and Permissions
The bridge is subject to a restrictive Content Security Policy (CSP). External API domains (e.g., Groq, Deepgram) are allowlisted in the http:default permission set, ensuring that while the webview can perform fetches, these remote origins cannot access sensitive IPC bridge commands.
Sources: CLAUDE.md, apps/desktop/src/tauri-conf.test.ts:25-45
Conclusion
The Rust/Tauri Bridge is the foundational utility that allows mausVoice to function as a native-grade tool while maintaining the developer velocity of a React-based UI. By enforcing strict type safety via Specta and following the "Rust as API" architecture, the project ensures performance-critical tasks like GPU-accelerated transcription and global hotkey listening are handled safely outside the JavaScript environment.