Swift Architecture
Choose the smallest architecture that makes state ownership, dependencies, side effects, and tests explicit. Default new SwiftUI features to MV; escalate only for observed complexity.
Contents
- Scope Boundary
- Decision Workflow
- Pattern Selection
- MV Default
- Escalation Signals
- Migration
- Common Mistakes
- Review Checklist
- References
Scope Boundary
This skill owns pattern selection, module boundaries, dependency direction, migration strategy, and architecture-level test seams. Route SwiftUI property-wrapper wiring and view composition to swiftui-patterns, navigation APIs and route models to swiftui-navigation, isolation diagnostics to swift-concurrency, and test syntax/fixtures to swift-testing.
Decision Workflow
- Record the feature's state owner, inputs, outputs, dependencies, side effects, navigation handoffs, and current tests.
- Identify the concrete pressure: complex state machine, shared derived state, dependency control, feature composition, team ownership, or UIKit navigation.
- Select the smallest pattern that addresses that pressure; write down what it adds and what remains unchanged.
- Implement one vertical slice with injected dependencies and observable state transitions.
- Run existing behavior tests plus state-transition and dependency-failure tests. If behavior changes, restore the fixture, fix the smallest boundary, and rerun before migrating another slice.
Pattern Selection
Use Coordinator alongside another state pattern when navigation complexity is the pressure; it is not a replacement for domain/state architecture.
MV Default
Keep views as state expressions and put business operations in observable models and injected services:
Load Architecture Pattern Recipes [blocked] for MVVM, MVI, TCA, Clean Architecture, Coordinator, and VIPER structure.
Escalation Signals
- Choose MVVM when substantial presentation transformation must be tested without rendering and the adapter has real behavior.
- Choose MVI when transitions, invalid states, and effects need one auditable reducer-like path.
- Choose TCA when feature composition, dependency overrides, cancellation, and deterministic effect tests recur across modules.
- Choose Clean Architecture when independent domain rules and dependency direction matter across multiple delivery/data layers.
- Add Coordinator for UIKit/hybrid route ownership, deep flow composition, or conditional navigation outside view controllers.
- Keep VIPER for compatible legacy modules or deliberate migrations; do not start a new SwiftUI feature with it by habit.
Do not escalate merely because a view is long. First extract subviews, services, and focused observable models.
Migration
Migrate one feature boundary at a time:
- Freeze behavior with tests and a dependency/state inventory.
- Introduce the target boundary around existing operations.
- Move one state transition or dependency at a time without rewriting UI and persistence simultaneously.
- Compare behavior, navigation, cancellation, error, and persistence results after each slice.
- Remove the old path only after no callers or tests depend on it.
For ObservableObject to Observation, preserve the same owner and mutation isolation before replacing wrappers. For MVVM to MV, delete forwarding view-model members only after views bind to the same model/service behavior. For TCA adoption, wrap one feature's state/actions/effects and migrate dependencies incrementally.
Common Mistakes
Review Checklist
- Choice is justified by concrete feature/team pressures
- State owner, mutation path, dependencies, effects, and navigation owner are explicit
- Dependencies are injected and replaceable in tests
- Pattern cost is proportional to feature complexity
- UI mechanics, navigation APIs, isolation, and test syntax route to sibling skills
- Migration preserves behavior one vertical slice at a time
- Failure, cancellation, navigation, and persistence behavior are verified after each slice
- No forwarding-only layers or god objects remain
References
- Detailed pattern structures: references/architecture-patterns.md [blocked]
- Apple: Observation · Migrating from ObservableObject to Observable
- TCA: ComposableArchitecture


