Skip to main content

Overview

Tauri commands are the IPC (inter-process communication) layer between the React frontend and Rust backend. All commands are:
  • Typed on both sides (Rust + TypeScript)
  • Async by default
  • Serialized via JSON (serde)

Command Flow

Defining Commands

Step 1: Implement Rust Command

src-tauri/src/space_fs/read_write/text.rs

Step 2: Register in lib.rs

src-tauri/src/lib.rs

Step 3: Add TypeScript Types

src/lib/tauri.ts

Step 4: Invoke from Frontend

Command Categories

Space Lifecycle

{ path: string } → SpaceInfo
Creates a new space at the given path
{ path: string } → SpaceInfo
Opens an existing space
void → string | null
Returns current space path or null
void → void
Closes the current space

File System Operations

{ dir?: string | null } → FsEntry[]
Lists files and directories
{ path: string } → TextFileDoc
Reads a text file with metadata
{ path: string, text: string, base_mtime_ms?: number } → TextFileWriteResult
Writes a text file atomically
{ path: string } → void
Creates a directory
{ from_path: string, to_path: string } → void
Renames/moves a file or directory
{ path: string, recursive?: boolean } → void
Deletes a file or directory

Search & Index

void → IndexRebuildResult
Rebuilds the SQLite full-text search index
Full-text search across all notes
{ request: SearchAdvancedRequest } → SearchResult[]
Advanced search with filters
{ limit?: number } → TagCount[]
Lists all tags with usage counts
Finds notes linking to a given note

AI Commands

{ request: AiChatStartRequest } → AiChatStartResult
Starts an AI chat conversation
void → AiProfile[]
Lists configured AI provider profiles
{ profile_id: string } → AiModel[]
Lists available models for a provider

Tasks

{ bucket: TaskBucket, today: string, limit?: number, folders?: string[] } → TaskItem[]
Queries tasks by bucket (inbox, today, upcoming)
{ task_id: string, checked: boolean } → void
Toggles task completion

Error Handling

Rust Side

Always return Result<T, String>:

Frontend Side

Use try/catch with TauriInvokeError:

State Management

Tauri State

Global state accessible to all commands:
src-tauri/src/lib.rs
Access in commands:

Type Safety

Enforcing Type Consistency

The TauriCommands interface ensures TypeScript types match Rust:
src/lib/tauri.ts
The invoke() helper enforces these types:
TypeScript will error if you:
  • Pass wrong argument types
  • Forget required arguments
  • Expect wrong return type

Performance Tips

Batch Operations

Instead of N individual calls:
Bad
Use batch command:
Good

Streaming Large Data

For large results, use events instead of return values:

Next Steps

Indexing

Learn about SQLite indexing

Storage

Content-addressed file storage