Full technical details: See
docs/foundations/Architecture.md in your project for complete technical coverage.Core Principles
1. MVVM Architecture
Clean separation between UI, business logic, and data: Benefits:- ✅ Views are dumb (no business logic)
- ✅ ViewModels are testable (no UIKit dependencies)
- ✅ Business logic isolated and reusable
- ✅ Clear data flow
2. Dependency Injection
Centralized composition withCompositionRoot:
- ✅ No global singletons
- ✅ Easy to mock for testing
- ✅ Clear dependency graph
- ✅ Compile-time safety
3. Protocol-Oriented Design
All external dependencies use protocols:- ✅ Swappable implementations
- ✅ Easy testing with mocks
- ✅ No vendor lock-in
- ✅ Clear contracts
Module Structure
11 Swift Packages
Core
Foundation utilities, errors, logging
Networking
HTTP client with interceptors
Storage
SwiftData models, repositories
Auth
Authentication clients
Payments
Subscription management
AI
LLM client protocol
FeatureChat
Chat UI, ViewModels; owns
LLMClient/LLMMessageFeatureRating
Sentiment-based rating prompts
FeatureSettings
Settings and paywall UI
DesignSystem
Tokens, components, Liquid Glass, accessibility
Localization
Type-safe strings, pluralization, i18n
A 12th package, TestSupport (
Packages/TestSupport), ships shared test
infrastructure (e.g. URLProtocolStub). It is test-only — not a reusable product
module — so the “11 Swift Packages cleanly separated for reuse” claim still stands.template.manifest.json):
- ✅ No circular dependencies
- ✅ Core has no dependencies
- ✅ Features depend on services
- ✅ Services depend on infrastructure
Data Flow
Chat Message Flow
Authentication Flow
iOS 26 Liquid Glass Layer
The DesignSystem package ships a dedicated Liquid Glass primitive. Primitive:Packages/DesignSystem/Sources/DesignSystem/Materials/SAIGlass.swift
SAIGlassStyle:.regular(default surface) and.clear(edge-to-edge hero surfaces)..saiGlass(...)modifier: one-call glass treatment for any view.SAIGlassContainer: merges nearby glass surfaces so adjacent cards, toolbars, and sheets sample the same background instead of stacking visually.
- iOS 26+: uses the native
Glassmaterial,glassEffect, andGlassEffectContainer. - iOS 17–25: falls back to SwiftUI
Materialautomatically. Same call sites, progressive enhancement at runtime.
saiScrollEdgeGlass(_:), saiSidebarAdaptable(), saiTabBarMinimize(_:), and SAITabBarMinimizeStyle for shell-level polish.
See Design System Module for the full API.
Swift 6 Concurrency Model
The entire codebase builds under strict concurrency checking on the Swift 6 toolchain.@MainActor-pinned storage repositories:MessageRepositoryImpl,ConversationRepositoryImpl, andSettingsRepositoryImplare all main-actor-isolated.@Observablethroughout: view models and observable stores use the@Observablemacro. NoObservableObject, no@Published, no.onReceive.- No
DispatchQueue.mainin app code: all main-thread work goes through@MainActororMainActor.run. - Explicit
any: every protocol-typed property and parameter uses theanykeyword, as Swift 6 requires. - Async/await throughout: no completion handlers, structured concurrency for cancellation,
Sendablewhere crossing actor boundaries.
Architecture Rule: ≤ 400 Lines Per File
A workspace-wide ceiling keeps every production and test Swift file ≤ 400 lines (enforced by.swiftlint.yml file_length: warning: 400). When a type grows past that, it moves into extension-split siblings in the same folder.
Examples in the codebase:
SessionManager.swift→SessionManager+SignIn,+Refresh,+PersistenceL10nstrings →L10n+<Namespace>.swiftper nested enum (Auth, Chat, Settings, …)SettingsView.swift→ a 125-line composition root with sections split outChatViewModel.swift→ChatViewModel+Memory.swift
Concurrency Primitives
Async/Await Throughout
- ✅ No completion handlers
- ✅ Structured concurrency (cancellable stream tasks)
- ✅ MainActor for UI updates
- ✅ Sendable for thread safety
Testing Strategy
The whole workspace runs in one pass viaBoilerplate.xctestplan: ~598 tests across 12 package test targets + the app test suites (SwiftAIBoilerplateProTests unit + SwiftAIBoilerplateProUITests). A single xcodebuild test covers everything:
CoreTests, TestSupportTests, NetworkingTests, StorageTests, AuthTests, DesignSystemTests, FeatureChatTests, FeatureRatingTests, FeatureSettingsTests, PaymentsTests, LocalizationTests, AITests. (TestSupportTests exercises the shared test-infrastructure package.)
Unit Tests
Test ViewModels and repositories in isolation, injecting fakes for external clients:Integration Tests
Test component interaction through the composition root:UI Tests
Test end-to-end flows. UI suites need theUI_TESTING=1 launch hook so the first-launch onboarding/permission alert does not block them:
Customization Entry Points
Add New Feature
- Create package (if needed):
Packages/FeatureX/ - Create models: Define SwiftData models in
Storage - Create repository: Data access layer
- Create ViewModel: Business logic
- Create View: SwiftUI interface
- Wire in CompositionRoot: Add factory method
Replace Backend
Implement the protocol:This swap snippet is illustrative — there is no
FirebaseAuthClient in the template.
The production implementation is SessionManager (a Supabase-backed actor) adapted to
AuthClient via SessionManagerWrapper.Add UI Components
- Create component in
DesignSystem/Components/ - Use design tokens (DSColors, DSSpacing, etc.)
- Add preview
- Add snapshot test
- Use in features
Best Practices Applied
Code Organization
Code Organization
- Files ≤ 400 lines (extension-split when larger)
- One type per file
- MARK comments for navigation
- Grouped by responsibility
Error Handling
Error Handling
- All errors mapped to
AppError - User-friendly messages
- Technical details logged
- Never swallow errors silently
Naming
Naming
- Clear, explicit names
- No abbreviations in public API
- Consistent conventions
- Self-documenting code
Performance
Performance
- Lazy loading (messages, images)
- Cursor-based pagination
- Image compression
- Offline-first data access
- Background sync
Security
Security
- Tokens in Keychain (never UserDefaults)
- API keys server-side only
- PII redacted in logs
- Row Level Security (Supabase)
Key Files
| Purpose | File Location |
|---|---|
| Dependency Injection | SwiftAIBoilerplatePro/Composition/CompositionRoot.swift |
| Feature Flags | SwiftAIBoilerplatePro/Composition/FeatureFlags.swift |
| App Entry | SwiftAIBoilerplatePro/SwiftAIBoilerplatePro.swift |
| Navigation | SwiftAIBoilerplatePro/AppShell/MainTabView.swift |
| Auth Router | SwiftAIBoilerplatePro/AppShell/LaunchRouter.swift |
Learn More
Core Module
Error handling, logging, utilities
Networking
HTTP client architecture
Storage
SwiftData and repositories
docs/CLAUDE.md
Guidelines for AI-assisted development
Find full technical documentation in your project: Architecture.md
