Overview
Zeus Finance is built on a local-first architecture that prioritizes user data ownership and offline capability. This document explains the key architectural decisions and how components interact.Core Principles
1. Local-First
Data is created, stored, and modified locally first. The server acts as a synchronization point, not the source of truth.2. Optimistic Updates
UI updates immediately after local operations. If sync fails, the user is notified but can continue working.3. Eventual Consistency
All devices will eventually sync to the same state. Conflicts are resolved by timestamp (last-write-wins) or manual intervention.System Components
Mobile Application (Flutter)
- Store all data in SQLite
- Provide instant read/write operations
- Queue changes for sync
- Handle conflict resolution
Backend Server (Rust)
- Store canonical data in PostgreSQL
- Provide REST API for sync
- Handle authentication
- Manage concurrent updates
Data Flow
Creating a Transaction
Offline Scenario
Sync Strategy
Sync Status States
Every entity has async_status field:
| Status | Meaning |
|---|---|
synced | In sync with server |
pending_create | New entity, needs server creation |
pending_update | Modified locally, needs server update |
pending_delete | Marked for deletion |
Sync Process
- Query all entities where
sync_status != 'synced' - Batch operations by type (create/update/delete)
- Send to server in dependency order (categories → wallets → transactions)
- Update local records with server IDs and
syncedstatus - Hard delete entities marked
pending_deleteand synced
Conflict Resolution
When the same entity is modified on multiple devices:- Server receives update with current
updated_at - Compare with server’s last known update
- Last-write-wins based on timestamp
- Return current server state to outdated clients
Database Schema
Local (SQLite)
Server (PostgreSQL)
Security Considerations
Authentication
- JWT tokens for API authentication
- Tokens refreshed on app foreground
- Secure storage for credentials
Data Validation
- Client-side validation for immediate feedback
- Server-side validation as authoritative
- Type safety via Rust/Flutter type systems
Scaling Considerations
Mobile
- SQLite handles thousands of records efficiently
- Lazy loading for transaction history
- Image compression for attachments
Server
- Stateless design enables horizontal scaling
- Connection pooling for database
- Rate limiting per user
Monitoring
Track these metrics in production:- Sync success/failure rates
- Average sync latency
- Conflict frequency
- Cache hit rates
- Storage utilization

