Why RPC?
Yasumu could have used REST APIs, GraphQL, or direct Tauri commands for frontend-backend communication. Instead, it implements a custom RPC layer for several reasons:- Type safety: Full TypeScript support from frontend to backend
- Developer experience: Auto-completion and compile-time errors
- Flexibility: Easy to add new commands without boilerplate
- Decoupling: Clear separation between UI and business logic
- Testability: Business logic can be tested independently
Architecture overview
RPC package structure
The@yasumu/rpc package defines the RPC interface:
Platform bridge
The platform bridge is an interface that abstracts the communication mechanism:Implementation (Frontend)
In the Tauri app, the platform bridge makes HTTP requests:RPC proxy
The RPC proxy provides a fluent API for making calls:Usage
The proxy enables intuitive call syntax:Command definitions
Commands are defined with full TypeScript types:- Auto-completion in IDEs
- Type checking at compile time
- Inline documentation via JSDoc
Queries vs mutations
The RPC layer distinguishes between queries and mutations:Queries ($query)
- Read-only operations
- Can be cached
- Idempotent (safe to retry)
Mutations ($mutate)
- Write operations
- Not cached
- Can have side effects
Server-side handling
In Tanxium, the RPC server routes commands to handlers:Command handlers
Context passing
The RPC layer supports passing context (like the active workspace):Server-side context access
Subscription events
For real-time updates, the RPC layer supports subscriptions:Frontend subscription
Backend emission
Error handling
The RPC layer provides structured error handling:Error types
Testing
The RPC layer is easy to test by mocking the platform bridge:Performance considerations
Batching
Multiple RPC calls can be batched:Caching
TanStack Query caches RPC responses:Next steps
- Frontend architecture - Learn how the UI consumes the RPC layer
- Tanxium runtime - See how RPC commands are handled
- Architecture overview - Understand the complete system