Architecture
Thrust follows modern iOS architecture patterns with SwiftUI and SwiftData.Overview
Core Principles
1. SwiftUI-First
Everything is SwiftUI:- No UIKit (except for specific APIs)
- Declarative UI
- State-driven updates
- Composition over inheritance
2. SwiftData for Persistence
Why SwiftData:- Native Swift API
- Type-safe queries
- Automatic migrations
- CloudKit sync support
- Better than Core Data
3. Observable Pattern
@Observable for State:- Replaces ObservableObject
- Automatic change tracking
- Better performance
- Cleaner syntax
4. Cross-Screen Data Consistency
When multiple screens display the same computed data (e.g., budget suggestions shown both on Dashboard capsule and Budgets screen), use a shared@Observable manager injected via .environment() to guarantee a single source of truth.
Pattern: Shared Manager
manager.rebuild(). Screens that only read (e.g., InsightCapsulesView) do a fallback rebuild if isLoaded == false.
5. Separation of Concerns
Clear responsibilities: Views:- UI only
- No business logic
- Minimal state
- Composition
- Business logic
- State management
- Data transformation
- Validation
- Shared services
- System APIs
- External integrations
- Singleton pattern
- Pure functions
- Calculations
- Analytics
- No state
Data Flow
Unidirectional Data Flow
- User taps “Add Transaction”
- View shows sheet
- User fills form
- View calls ViewModel method
- ViewModel validates data
- ViewModel creates Transaction model
- SwiftData saves to database
- @Query automatically updates
- View re-renders with new data
State Management
Three types of state: 1. View State (Local)Layers
1. Presentation Layer
Views:- SwiftUI views
- Minimal logic
- Composition
- Reusable components
- @Observable classes
- Business logic
- State management
- Data transformation
2. Business Logic Layer
Managers:- Singleton services
- System integrations
- Shared functionality
- Pure calculation functions
- Analytics
- Forecasting
- No side effects
3. Data Layer
SwiftData:- Models with @Model
- Relationships
- Queries with @Query
- Migrations
- Sync across devices
- Backup
- Family sharing
- Sensitive data
- API keys
- Tokens
- App settings
- Preferences
- Non-sensitive data
Key Patterns
1. Coordinator Pattern
SheetCoordinator:- Centralized sheet management
- Type-safe navigation
- Deep linking support
2. Repository Pattern
Not used directly - SwiftData @Query replaces repositories Instead of:3. Factory Pattern
For complex object creation:4. Strategy Pattern
For different calculation strategies:Privacy Architecture
Ghost Mode (Default)
All data on-device:- No network requests
- No cloud sync
- Maximum privacy
- Fully functional
Connected Mode (Optional)
With user consent:- iCloud sync
- Bank integration (EU)
- Real-time prices
- AI categorization
Performance
Optimization Strategies
1. Lazy Loading:Testing Architecture
Unit Tests
Test engines and managers:UI Tests
Test critical flows:Security
Data Protection
Encryption:- SwiftData encrypted at rest
- Keychain for sensitive data
- CloudKit encrypted in transit
- Face ID / Touch ID
- Passcode fallback
- Auto-lock
Scalability
Handling Large Datasets
Strategies:- Pagination - Load data in chunks
- Indexing - SwiftData indexes for fast queries
- Lazy loading - Only load what’s visible
- Background processing - Heavy calculations off main thread
- Caching - Cache expensive calculations
Next Steps
Project Structure
Navigate the codebase
API Reference
Detailed API documentation
Contributing
Contribute to Thrust
Quick Start
Get started developing