Choose, review, or migrate Apple-platform architecture and module boundaries. Use when feature complexity may justify MVVM, MVI, TCA, Clean Architecture, a Coordinator, or an incremental migration beyond straightforward SwiftUI MV.
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.
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.
Inspect the existing project conventions, deployment target, Swift mode, dependencies, and tests before proposing a pattern. Preserve the established architecture when it remains coherent; do not introduce a framework or project-wide migration unless the request and observed complexity justify it.
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
Pattern
Choose when
Main cost
MV
SwiftUI feature has straightforward state and orchestration
Logic can drift into large views without decomposition
MVVM
Presentation logic needs an independently testable adapter
Extra layer can become a forwarding shell
MVI
A feature is best modeled as explicit state + intents + reducer/effects
Boilerplate and centralized transition design
TCA
Many composable features need deterministic effects, dependencies, and testing
Framework learning and architectural commitment
Clean Architecture
Large product needs strict dependency direction across domain/data/UI
Protocol and mapping overhead
Coordinator
UIKit or hybrid navigation needs a separate flow owner
Another lifecycle and routing owner
VIPER
Maintaining an existing UIKit module with established VIPER boundaries
Very high ceremony; poor default for new SwiftUI work
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:
@MainActor
@Observable
final class TripStore {
private let client: TripClient
var trips: [Trip] = []
var error: Error?
init(client: TripClient) { self.client = client }
func load() async {
do { trips = try await client.fetchTrips() }
catch { self.error = error }
}
}
struct TripList: View {
@State private var store: TripStore
init(client: TripClient) {
_store = State(initialValue: TripStore(client: client))
}
var body: some View {
List(store.trips) { Text($0.name) }
.task { await store.load() }
}
}
Load Architecture Pattern Recipes 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
Mistake
Fix
Pattern chosen by popularity
Tie it to an observed feature pressure.
View model only forwards properties
Remove it and use MV.
One object owns navigation, networking, formatting, persistence, and UI state
Split by responsibility and dependency direction.
TCA or Clean Architecture applied to trivial screens
Start with MV and preserve an escalation seam.
Coordinator used as a state architecture
Keep it focused on route/lifecycle ownership.
Multiple patterns mixed inside one feature
Define one local state/effect model and migrate at feature boundaries.
Big-bang migration
Move one tested vertical slice and rerun the same proof matrix.
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
1---2name: swift-architecture3description: Choose, review, or migrate Apple-platform architecture and module boundaries. Use when feature complexity may justify MVVM, MVI, TCA, Clean Architecture, a Coordinator, or an incremental migration beyond straightforward SwiftUI MV.4---56# Swift Architecture78Choose the smallest architecture that makes state ownership, dependencies, side effects, and tests explicit. Default new SwiftUI features to MV; escalate only for observed complexity.910## Contents1112- [Scope Boundary](#scope-boundary)13- [Decision Workflow](#decision-workflow)14- [Pattern Selection](#pattern-selection)15- [MV Default](#mv-default)16- [Escalation Signals](#escalation-signals)17- [Migration](#migration)18- [Common Mistakes](#common-mistakes)19- [Review Checklist](#review-checklist)20- [References](#references)2122## Scope Boundary2324This 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`.2526Inspect the existing project conventions, deployment target, Swift mode, dependencies, and tests before proposing a pattern. Preserve the established architecture when it remains coherent; do not introduce a framework or project-wide migration unless the request and observed complexity justify it.2728## Decision Workflow29301. Record the feature's state owner, inputs, outputs, dependencies, side effects, navigation handoffs, and current tests.312. Identify the concrete pressure: complex state machine, shared derived state, dependency control, feature composition, team ownership, or UIKit navigation.323. Select the smallest pattern that addresses that pressure; write down what it adds and what remains unchanged.334. Implement one vertical slice with injected dependencies and observable state transitions.345. 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.3536## Pattern Selection3738| Pattern | Choose when | Main cost |39|---|---|---|40| MV | SwiftUI feature has straightforward state and orchestration | Logic can drift into large views without decomposition |41| MVVM | Presentation logic needs an independently testable adapter | Extra layer can become a forwarding shell |42| MVI | A feature is best modeled as explicit state + intents + reducer/effects | Boilerplate and centralized transition design |43| TCA | Many composable features need deterministic effects, dependencies, and testing | Framework learning and architectural commitment |44| Clean Architecture | Large product needs strict dependency direction across domain/data/UI | Protocol and mapping overhead |45| Coordinator | UIKit or hybrid navigation needs a separate flow owner | Another lifecycle and routing owner |46| VIPER | Maintaining an existing UIKit module with established VIPER boundaries | Very high ceremony; poor default for new SwiftUI work |4748Use Coordinator alongside another state pattern when navigation complexity is the pressure; it is not a replacement for domain/state architecture.4950## MV Default5152Keep views as state expressions and put business operations in observable models and injected services:5354```swift55@MainActor56@Observable57final class TripStore {58 private let client: TripClient59 var trips: [Trip] = []60 var error: Error?6162 init(client: TripClient) { self.client = client }6364 func load() async {65 do { trips = try await client.fetchTrips() }66 catch { self.error = error }67 }68}6970struct TripList: View {71 @State private var store: TripStore7273 init(client: TripClient) {74 _store = State(initialValue: TripStore(client: client))75 }7677 var body: some View {78 List(store.trips) { Text($0.name) }79 .task { await store.load() }80 }81}82```8384Load [Architecture Pattern Recipes](references/architecture-patterns.md) for MVVM, MVI, TCA, Clean Architecture, Coordinator, and VIPER structure.8586## Escalation Signals8788- Choose MVVM when substantial presentation transformation must be tested without rendering and the adapter has real behavior.89- Choose MVI when transitions, invalid states, and effects need one auditable reducer-like path.90- Choose TCA when feature composition, dependency overrides, cancellation, and deterministic effect tests recur across modules.91- Choose Clean Architecture when independent domain rules and dependency direction matter across multiple delivery/data layers.92- Add Coordinator for UIKit/hybrid route ownership, deep flow composition, or conditional navigation outside view controllers.93- Keep VIPER for compatible legacy modules or deliberate migrations; do not start a new SwiftUI feature with it by habit.9495Do not escalate merely because a view is long. First extract subviews, services, and focused observable models.9697## Migration9899Migrate one feature boundary at a time:1001011. Freeze behavior with tests and a dependency/state inventory.1022. Introduce the target boundary around existing operations.1033. Move one state transition or dependency at a time without rewriting UI and persistence simultaneously.1044. Compare behavior, navigation, cancellation, error, and persistence results after each slice.1055. Remove the old path only after no callers or tests depend on it.106107For `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.108109## Common Mistakes110111| Mistake | Fix |112|---|---|113| Pattern chosen by popularity | Tie it to an observed feature pressure. |114| View model only forwards properties | Remove it and use MV. |115| One object owns navigation, networking, formatting, persistence, and UI state | Split by responsibility and dependency direction. |116| TCA or Clean Architecture applied to trivial screens | Start with MV and preserve an escalation seam. |117| Coordinator used as a state architecture | Keep it focused on route/lifecycle ownership. |118| Multiple patterns mixed inside one feature | Define one local state/effect model and migrate at feature boundaries. |119| Big-bang migration | Move one tested vertical slice and rerun the same proof matrix. |120121## Review Checklist122123- [ ] Choice is justified by concrete feature/team pressures124- [ ] State owner, mutation path, dependencies, effects, and navigation owner are explicit125- [ ] Dependencies are injected and replaceable in tests126- [ ] Pattern cost is proportional to feature complexity127- [ ] UI mechanics, navigation APIs, isolation, and test syntax route to sibling skills128- [ ] Migration preserves behavior one vertical slice at a time129- [ ] Failure, cancellation, navigation, and persistence behavior are verified after each slice130- [ ] No forwarding-only layers or god objects remain131132## References133134- Detailed pattern structures: [references/architecture-patterns.md](references/architecture-patterns.md)135- Apple: [Observation](https://sosumi.ai/documentation/observation) · [Migrating from ObservableObject to Observable](https://sosumi.ai/documentation/swiftui/migrating-from-the-observable-object-protocol-to-the-observable-macro)136- TCA: [ComposableArchitecture](https://swiftpackageindex.com/pointfreeco/swift-composable-architecture/main/documentation/composablearchitecture)
Run npx skillmds@latest add thiennc-tesoglobal/swift-architecture in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Choose, review, or migrate Apple-platform architecture and module boundaries. Use when feature complexity may justify MVVM, MVI, TCA, Clean Architecture, a Coordinator, or an incremental migration beyond straightforward SwiftUI MV. It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
thiennc-tesoglobal (@thiennc-tesoglobal) published this skill. Their other Agent Skills are listed on their SkillMD profile.