Swift Architecture Skill
Overview
Use this skill to pick the best Swift architecture playbook for SwiftUI/UIKit codebases and apply it to the user’s task.
For quick navigation across playbooks, use references/_index.md.
Fast Path
Before selecting an architecture, always capture:
- task type (new feature, refactor, PR review, debugging)
- UI stack (SwiftUI, UIKit, or mixed)
- scope (single screen, multi-screen, app-wide)
- state and effect complexity
- team familiarity and dependency tolerance
- existing conventions to preserve
Then:
- if the user explicitly names an architecture, treat it as the initial candidate and run a fit check first
- if no architecture is named, load
references/selection-guide.md and infer the best fit from the stated constraints
- if the best fit combines patterns, name one primary playbook for the feature boundary and one secondary playbook for the supporting concern
- choose Quick Recommendation Mode for single-feature guidance with clear constraints
- choose Deep Refactor Mode for migrations, mixed architectures, or module boundary changes
Quick Recommendation Mode
Use this mode when:
- the scope is one feature or screen
- constraints are clear enough to recommend one primary pattern
- the user mainly needs a recommendation, scaffold, or review checklist
Deliver:
- fit result (
fit or mismatch)
- 1-2 reasons grounded in the request
- the selected reference file
- concrete structure, state, dependency, async, and testing guidance scoped to the feature
Deep Refactor Mode
Use this mode when:
- the request spans multiple modules or screens
- the codebase already mixes architectures
- the user is migrating from one pattern to another
Deliver:
- current-state assessment
- target architecture recommendation with fit or mismatch result
- incremental migration path with boundary changes called out
- risks, trade-offs, and verification points for the transition
Architecture Router
If the user explicitly names an architecture, treat it as the initial candidate and run a fit check before committing:
- validate against UI stack fit (SwiftUI/UIKit/mixed), state complexity, effect orchestration needs, team familiarity, and existing codebase conventions
- if it fits, proceed with the requested architecture
- if it mismatches key constraints, explicitly explain the mismatch and recommend the closest-fit alternative from
references/selection-guide.md
- if the user still insists on a mismatched architecture, proceed with a risk-mitigated plan and state the risks up front
Architecture reference mapping:
- MVVM →
references/mvvm.md
- MVI →
references/mvi.md
- TCA →
references/tca.md
- Clean Architecture →
references/clean-architecture.md
- VIPER →
references/viper.md
- Reactive →
references/reactive.md
- MVP →
references/mvp.md
- Coordinator →
references/coordinator.md
Combination routing:
- Coordinator is usually secondary unless the user's main problem is flow ownership, deep linking, or reusable navigation.
- Reactive is usually secondary when streams live inside MVVM, MVP, VIPER, MVI, or TCA presentation boundaries.
- Clean Architecture is usually primary for app/module layering, with MVVM, MVP, or TCA as the presentation pattern.
- When combining, read both references and state which pattern owns each boundary before giving file structure or code.
Analyze Existing Codebase (When Applicable)
When code already exists:
- detect current architecture and DI style
- note concurrency model (async/await, Combine, GCD, mixed)
- align recommendations to local conventions
Guardrails
- Do not force an architecture switch for a small feature when the current local pattern is still a reasonable fit.
- Preserve existing conventions unless the mismatch is severe enough to justify change.
- Do not introduce new framework dependencies such as TCA unless the user explicitly accepts that trade-off or the codebase already uses them.
- Prefer the smallest architecture change that solves the request cleanly.
- Keep guidance architecture-specific; do not blend playbooks unless the boundary between patterns is explicit.
- For combined patterns, avoid merging responsibilities: identify the primary boundary first, then apply the secondary playbook only to its concern.
Produce Concrete Deliverables
Read the selected architecture reference and convert its guidance into deliverables tailored to the user's request:
- File and module structure: directory layout with file names specific to the feature
- State and dependency boundaries: concrete types, protocols, and injection points
- Async strategy: cancellation, actor isolation, and error paths
- Testing strategy: what to test, how to stub dependencies, and example test structure
- Migration path (for refactors): incremental steps to move from current to target architecture
- UI stack adaptation: where SwiftUI and UIKit guidance should differ for the chosen architecture
Output Requirements
- Keep recommendations scoped to the requested feature or review task.
- Prefer protocol-based dependency injection and explicit state modeling.
- Flag anti-patterns found in existing code and provide direct fixes.
- Include cancellation and error handling in all async flows.
- For explicit architecture requests, include a short fit result (
fit or mismatch) with 1-2 reasons.
- For mismatch cases, include one closest-fit alternative and why it better matches the stated constraints.
- When writing code, include only the patterns relevant to the task — do not dump entire playbooks.
- Treat reference snippets as illustrative by default; add full compile scaffolding only if the user asks for runnable code.
- Ask only minimum blocking questions; otherwise proceed with explicit assumptions stated up front.
- When reviewing PRs, use the architecture-specific checklist and call out specific violations with line-level fixes.
Verification Checklist
Before finalizing:
- confirm the selected pattern matches the user’s constraints and stack
- confirm dependency injection, state ownership, effects, and testing strategy are covered
- call out migration risk explicitly when recommending an architecture change
- end with the selected architecture’s PR review checklist adapted to the user’s feature
1---2name: swift-architecture-skill3description: Swift iOS architecture guidance and playbooks for MVVM, MVI, TCA, Clean Architecture, VIPER, MVP, Coordinator, and Reactive patterns. Use when designing, implementing, refactoring, or reviewing the architecture of a SwiftUI or UIKit feature, module, or codebase.4license: MIT5---67# Swift Architecture Skill89## Overview1011Use this skill to pick the best Swift architecture playbook for SwiftUI/UIKit codebases and apply it to the user’s task.1213For quick navigation across playbooks, use `references/_index.md`.1415## Fast Path1617Before selecting an architecture, always capture:18- task type (new feature, refactor, PR review, debugging)19- UI stack (SwiftUI, UIKit, or mixed)20- scope (single screen, multi-screen, app-wide)21- state and effect complexity22- team familiarity and dependency tolerance23- existing conventions to preserve2425Then:26- if the user explicitly names an architecture, treat it as the initial candidate and run a fit check first27- if no architecture is named, load `references/selection-guide.md` and infer the best fit from the stated constraints28- if the best fit combines patterns, name one **primary** playbook for the feature boundary and one **secondary** playbook for the supporting concern29- choose **Quick Recommendation Mode** for single-feature guidance with clear constraints30- choose **Deep Refactor Mode** for migrations, mixed architectures, or module boundary changes3132## Quick Recommendation Mode3334Use this mode when:35- the scope is one feature or screen36- constraints are clear enough to recommend one primary pattern37- the user mainly needs a recommendation, scaffold, or review checklist3839Deliver:40- fit result (`fit` or `mismatch`)41- 1-2 reasons grounded in the request42- the selected reference file43- concrete structure, state, dependency, async, and testing guidance scoped to the feature4445## Deep Refactor Mode4647Use this mode when:48- the request spans multiple modules or screens49- the codebase already mixes architectures50- the user is migrating from one pattern to another5152Deliver:53- current-state assessment54- target architecture recommendation with fit or mismatch result55- incremental migration path with boundary changes called out56- risks, trade-offs, and verification points for the transition5758## Architecture Router5960If the user explicitly names an architecture, treat it as the initial candidate and run a fit check before committing:61- validate against UI stack fit (SwiftUI/UIKit/mixed), state complexity, effect orchestration needs, team familiarity, and existing codebase conventions62- if it fits, proceed with the requested architecture63- if it mismatches key constraints, explicitly explain the mismatch and recommend the closest-fit alternative from `references/selection-guide.md`64- if the user still insists on a mismatched architecture, proceed with a risk-mitigated plan and state the risks up front6566Architecture reference mapping:67- MVVM → `references/mvvm.md`68- MVI → `references/mvi.md`69- TCA → `references/tca.md`70- Clean Architecture → `references/clean-architecture.md`71- VIPER → `references/viper.md`72- Reactive → `references/reactive.md`73- MVP → `references/mvp.md`74- Coordinator → `references/coordinator.md`7576Combination routing:77- Coordinator is usually secondary unless the user's main problem is flow ownership, deep linking, or reusable navigation.78- Reactive is usually secondary when streams live inside MVVM, MVP, VIPER, MVI, or TCA presentation boundaries.79- Clean Architecture is usually primary for app/module layering, with MVVM, MVP, or TCA as the presentation pattern.80- When combining, read both references and state which pattern owns each boundary before giving file structure or code.8182## Analyze Existing Codebase (When Applicable)8384When code already exists:85- detect current architecture and DI style86- note concurrency model (async/await, Combine, GCD, mixed)87- align recommendations to local conventions8889## Guardrails9091- Do not force an architecture switch for a small feature when the current local pattern is still a reasonable fit.92- Preserve existing conventions unless the mismatch is severe enough to justify change.93- Do not introduce new framework dependencies such as TCA unless the user explicitly accepts that trade-off or the codebase already uses them.94- Prefer the smallest architecture change that solves the request cleanly.95- Keep guidance architecture-specific; do not blend playbooks unless the boundary between patterns is explicit.96- For combined patterns, avoid merging responsibilities: identify the primary boundary first, then apply the secondary playbook only to its concern.9798## Produce Concrete Deliverables99100Read the selected architecture reference and convert its guidance into deliverables tailored to the user's request:101102- **File and module structure**: directory layout with file names specific to the feature103- **State and dependency boundaries**: concrete types, protocols, and injection points104- **Async strategy**: cancellation, actor isolation, and error paths105- **Testing strategy**: what to test, how to stub dependencies, and example test structure106- **Migration path** (for refactors): incremental steps to move from current to target architecture107- **UI stack adaptation**: where SwiftUI and UIKit guidance should differ for the chosen architecture108109## Output Requirements110111- Keep recommendations scoped to the requested feature or review task.112- Prefer protocol-based dependency injection and explicit state modeling.113- Flag anti-patterns found in existing code and provide direct fixes.114- Include cancellation and error handling in all async flows.115- For explicit architecture requests, include a short fit result (`fit` or `mismatch`) with 1-2 reasons.116- For mismatch cases, include one closest-fit alternative and why it better matches the stated constraints.117- When writing code, include only the patterns relevant to the task — do not dump entire playbooks.118- Treat reference snippets as illustrative by default; add full compile scaffolding only if the user asks for runnable code.119- Ask only minimum blocking questions; otherwise proceed with explicit assumptions stated up front.120- When reviewing PRs, use the architecture-specific checklist and call out specific violations with line-level fixes.121122## Verification Checklist123124Before finalizing:1251261. confirm the selected pattern matches the user’s constraints and stack1272. confirm dependency injection, state ownership, effects, and testing strategy are covered1283. call out migration risk explicitly when recommending an architecture change1294. end with the selected architecture’s PR review checklist adapted to the user’s feature