| name | tauri-contract |
| description | TS ⇄ Rust contract sync procedure for Tauri v2 apps. Use when modifying events, commands, types, or payloads that cross the frontend/backend boundary. Ensures both sides stay in sync. |
Tauri Contract Sync
Keep Rust backend and TS frontend in sync when modifying the cross-layer contract.
When to Use
- Adding/removing event names
- Modifying event payloads
- Adding/removing Tauri commands
- Changing core enums/types (states, errors)
- Modifying configuration schemas
File Mappings
| Contract Element | Rust Source | TS Mirror |
|---|
| Event names | src-tauri/src/events.rs (event_names::*) | src/types.ts (EVENT_*) |
| Event payloads | src-tauri/src/events.rs (structs) | src/types.ts (interfaces) |
| Core enums | src-tauri/src/state.rs | src/types.ts |
| Error types | src-tauri/src/state.rs | src/types.ts |
| Config schema | src-tauri/src/config.rs | src/types.ts |
| Commands | src-tauri/src/lib.rs | invoke(...) calls |
Sync Checklist
When modifying contract elements:
Adding a New Command
- Add
#[tauri::command] in src-tauri/src/lib.rs
- Export via
tauri::generate_handler![...]
- Define return/error types if new
- Add TS type for return value in
src/types.ts
- Call via
invoke(...) in UI
- Update mocks in
src/test/setup.ts
- Add tests in both layers
Adding a New Event
- Add event name constant in Rust
events.rs (event_names::*)
- Add payload struct in Rust
events.rs (with #[derive(Serialize)])
- Add TS event name constant in
types.ts (EVENT_*)
- Add TS payload interface in
types.ts
- Emit from Rust via
app_handle.emit(...)
- Listen in TS via
listen(EVENT_*, callback)
Guidelines
- Contract-first: Always design the contract before implementing
- Minimal payloads: Only include data the UI needs
- Explicit errors: Every command returns
Result<T, E> with typed errors
- Versioning: For breaking changes, consider deprecation path