Tauri Development
Guidelines and reference for developing Tauri v2+ cross-platform applications. All Tauri v2+ modifications must follow secure-by-default capabilities configurations and correct multi-platform project separation patterns to ensure successful deployment and high-performance desktop and mobile execution.
Reference Documentation
When deep context, precise API definitions, or config schemas are required, consult the bundled Tauri reference excerpts:
- Consult the bundled reference files vendored under resources/auto/llms.txt from the official v2 docs.
Constraints
To ensure compatibility, security, and stability:
- Frontend APIs: Use
@tauri-apps/api/coreor official v2 plugins exclusively. - Async Commands: Use owned types (such as
String) for parameters and return values in async Tauri commands. - Thread Safety: Run heavy or I/O operations asynchronously to ensure the main thread remains unblocked.
- Paths: Reference dynamic path configurations using Tauri's path APIs (e.g.,
app.path()) or paths relative to the working directory. - Capability Declarations: Declare explicit permissions in
src-tauri/capabilities/default.json(or other capability files) for all IPC and plugin operations.
Project Architecture & Setup
Clean passthrough entrypoint: Keep
src-tauri/src/main.rsas a thin passthrough:#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { app_lib::run(); }Core application setup: Place all setup, state management, and command registration in
src-tauri/src/lib.rs.Mobile compatibility: Configure a single
runentry point marked with mobile compatibility attributes inlib.rs:#[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() .invoke_handler(tauri::generate_handler![/* commands */]) .run(tauri::generate_context!()) .expect("error while running tauri application"); }
IPC & Command Rules
- Register every command intended for frontend access inside
tauri::generate_handler![...]. - For commands returning potential errors, return a
Result<T, E>where the error typeEimplementsserde::Serializeto ensure error details are safely communicated across the IPC boundary. - Manage state shared between multiple commands via Tauri state APIs and wrap in thread-safe containers (e.g.,
Mutex<T>orRwLock<T>). - To establish stable communication vectors, use high-frequency typed streams or Channels for high-volume backend data transfers.
Security & Capabilities
- Define explicit permissions inside
src-tauri/capabilities/default.jsonor another schema-compliant JSON file. - For every plugin used in the frontend (e.g.
fs,dialog,shell,http,store), declare its core permissions within capability files (e.g."fs:default","dialog:default"). - If an API silently fails or times out, immediately inspect the active capabilities configurations to confirm permissions have been correctly granted.
Completion Criteria
The Tauri task is successfully complete when:
src-tauri/src/main.rscontains only a thin passthrough toapp_lib::run().- All custom backend commands are implemented with owned parameters and registered in
tauri::generate_handler![]. - Every active plugin has corresponding permissions listed in the active capabilities configuration files under
src-tauri/capabilities/. - All frontend components reference exclusively Tauri v2 APIs (e.g.,
@tauri-apps/api/coreor official v2 plugins). - Compilation and build checks pass successfully (e.g. via
cargo checkornpm run build).