Full technical details in your project at
/docs/modules/Storage.mdWhat You Get
- ✅ Repository pattern - Never expose @Model types to Views
- ✅ DTO pattern - Lightweight, Sendable data transfer objects
- ✅ Keychain wrapper - Secure, tested token storage
- ✅ Cursor pagination - Efficient infinite scroll
- ✅ Batch operations - Optimized bulk updates/deletes
- ✅ Migration framework - Safe schema evolution
- ✅ Optional cloud sync - Supabase integration (feature-flagged)
Production Setup (From Real Code)
Here’s how the boilerplate actually sets up storage inCompositionRoot.swift:
Key Architecture Decisions
- ✅ @Model types are internal - never exposed to Views
- ✅ DTOs are public - lightweight, Sendable structs
- ✅ Repositories on @MainActor - SwiftData requirement
- ✅ Protocol-based - easy to test with mocks
- ✅ Single ModelContext - thread-safe, no conflicts
Repository Pattern (Production Implementation)
The boilerplate uses protocol-based repositories that return lightweight DTOs:- Views never see @Model types (maintains MVVM boundaries)
- DTOs are Sendable (thread-safe)
- Easy to mock for testing
- Can swap implementations (local, cloud, hybrid)
Optional Cloud Sync
- Enable Chat Sync
- Enable Photo Sync
Sync conversations and messages across devices:Setup Guide: Chat Sync Setup
- Run SQL migration
- Enable feature flag
- Wire up hybrid repositories
- Test cross-device sync
Keychain Storage (Real Implementation)
The boilerplate includes a production-ready Keychain wrapper used for all secure storage:- ✅ iOS Security framework (kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly)
- ✅ Automatic PII redaction in logs
- ✅ Thread-safe operations
- ✅ Comprehensive error handling
- ✅ Works with AuthInterceptor seamlessly via
KeychainTokenProvider
Customization Examples
Add New SwiftData Model
Key Files
| Component | Location |
|---|---|
| Models | Packages/Storage/Sources/Storage/Models/ |
| Repositories | Packages/Storage/Sources/Storage/Repositories/ |
| Keychain | Packages/Storage/Sources/Storage/Keychain/ |
| Cloud Sync | Packages/Storage/Sources/Storage/Supabase* |
Dependencies
- Core - Error handling, logging
- Networking - For cloud sync (optional)
Used By
- FeatureChat - Conversation and message storage
- FeatureSettings - Settings persistence
- Auth - Keychain for tokens
- Profile - Photo storage (optional)
Best Practices
SwiftData
SwiftData
- Use DTOs for passing data
- @MainActor for ModelContext
- Sendable for repositories
- Unique IDs with @Attribute(.unique)
Repositories
Repositories
- Protocol-based design
- Return DTOs (not @Model objects)
- Async/await throughout
- Comprehensive error handling
Cloud Sync
Cloud Sync
- Offline-first (local writes fast)
- Background sync (non-blocking)
- Graceful degradation
- Optional (feature flag)
Learn More
Full Documentation
Complete Storage guide
Chat Sync
Enable cross-device sync
Photo Storage
Enable cloud photos
Building Guide
Add custom models
Test Coverage
88%+ - Comprehensive repository testing Tests include:- CRUD operations
- Pagination
- Error scenarios
- Concurrent access
- Keychain operations
