swiftui-architecture
Skill2 starsChanged 51 days agoMITView on GitHub
Scaffold and extend SwiftUI apps using Factory, Manager, UseCase, ViewModel, and View layers with protocol-first dependency injection. Use when starting a new SwiftUI project, adding a feature module, reviewing layer boundaries, folder structure, or clean architecture on iOS or macOS.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- piemonte/skillstheir own version, first seen Apr 5, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- piemonte/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 13 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈13
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Use this skill for new SwiftUI apps, new features, and architecture reviews.
- Distinctive: line 21
Use the smallest structure that keeps responsibilities clear.
- Distinctive: line 34
One main feature View → exactly one owning ViewModel: When the feature has business operations, that ViewModel may depend on one or more …
- Distinctive: line 45
Protocol-first at boundaries: Use protocols for replaceable infrastructure and business dependencies.
- Distinctive: line 56
Use this mode when the user asks to review, audit, inspect, or give feedback on an existing project.
- Distinctive: line 62
Do not create files, restructure the project, add abstractions, run tests, or run builds during a review unless the user separately …
- Distinctive: line 75
Before choosing observation or navigation APIs, inspect the project's minimum OS versions and Swift toolchain.
- Distinctive: line 99
Create protocols before implementations.
- Distinctive: line 130
UseCase tests: when a UseCase exists, mock its Manager protocols and verify business rules and orchestration.
- Distinctive: line 132
View tests: use previews or snapshot-style checks when they provide value.
- Distinctive: line 136
If adopting this architecture in an existing codebase:
- Very specific: line 140
Factory migration: keep individual creation methods in appropriately scoped factories.
- Distinctive: line 142
ViewModel or UseCase chains: remove ViewModel → ViewModel and UseCase → UseCase dependencies.
- Distinctive: line 168
Read only what you need:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SwiftUI Architecture
Use this skill for new SwiftUI apps, new features, and architecture reviews.
When not to use
- Single-screen prototypes → prefer simple MVVM.
- Projects committed to TCA, VIPER, or other architectures unless explicitly migrating.
Architecture decision table
Use the smallest structure that keeps responsibilities clear.
The preferred default for a feature with business rules is View → ViewModel → focused UseCase(s). When a UseCase crosses an infrastructure boundary—such as persistence, networking, files, StoreKit, analytics, or device APIs—it depends on a narrow Manager protocol. Features without infrastructure do not need a Manager layer. Add a Factory when construction or implementation selection is genuinely complex. Use simple View → ViewModel for screens whose behavior is only local presentation state; do not add empty layers to match the default.
| Situation | Recommended |
| Small screen (simple UI state, no real business rules) | Simple MVVM: View + ViewModel |
| Medium feature (business logic growing, rules, orchestration) | View + ViewModel + UseCase |
| Feature with infra (API/storage/filesystem/device) | Manager protocol(s) + UseCase + ViewModel |
| Multiple implementations / platform differences (availability/config selection, complex wiring) | Select implementations in focused factories; compose dependencies in App |
Core feature boundary
One main feature View → exactly one owning ViewModel. When the feature has business operations, that ViewModel may depend on one or more focused UseCase protocols.
The one-ViewModel rule does not mean one UseCase. When the same feature needs profile, purchase, or preference operations, inject the relevant focused UseCase protocols into its existing ViewModel. Do not add another ViewModel or merge unrelated UseCases just to serve that feature. A simple screen may have no UseCase at all.
Closures support component actions, presentation events, and content composition. Keep callback APIs small and purposeful; do not use closures to conceal forbidden dependencies, move business workflows into Views, or forward actions through layers of otherwise unnecessary containers. See closure boundaries.
Non-negotiable rules
- Unidirectional dependencies:
- Runtime flow is
View → ViewModel → UseCase → Managerwhen those layers are present; simple presentation-only features may stop at ViewModel. Appwires dependencies and owns shared lifetimes; factories create individual instances from supplied dependencies.
- Runtime flow is
- Protocol-first at boundaries: Use protocols for replaceable infrastructure and business dependencies. A trivial private implementation does not need a protocol solely to satisfy this guide.
- ViewModels own UI state on
@MainActor. Prefer@Observablewhen the app targets iOS 17/macOS 14 or later and its toolchain supports Observation; for earlier targets, use the app's compatibleObservableObjectapproach. Preserve existing observation conventions unless migration is requested. Use a nestedViewStateenum when mutually exclusive screen modes make it clearer. Independent state such as drafts, selection, sheets, and alerts may remain separate properties. See observation and deployment targets. - ViewModels depend on focused UseCase protocols when business operations require them — never managers or other ViewModels. Each UseCase depends directly on the narrow manager protocols it needs, never another UseCase.
- Views have explicit roles — each feature View receives exactly one owning feature ViewModel. Composition views may receive multiple child ViewModels to assemble independent features using instances supplied by
App. Reusable visual components receive values, bindings, and action closures. Views do not call UseCases, perform business operations, or create business services. Scoped navigation state is a presentation exception: feature/composition Views may access it; ViewModels and UseCases may not. ViewModels expose operation results and UI state, not routes or navigation commands; Views decide how to navigate. See navigation and lifetimes. - Factories create individual instances — each method creates one Manager, UseCase, or ViewModel and accepts its dependencies as arguments. Start with one factory; split by domain or platform when current complexity warrants it. Names such as
Factory,AppFactory, and[Domain]Factoryare conventions, not architectural requirements. Platform implementation selection is allowed; business logic and hidden feature/application graphs are forbidden. - Recommend-first: Propose folder tree + types before creating files.
- Comments explain intent, not syntax: Do not add comments that restate an obvious declaration, method name, property name, or control flow. Add comments when they document a non-obvious invariant, ownership decision, platform workaround, concurrency constraint, public API contract, or follow-up requirement. Prefer clear names and structure over explanatory narration.
Architecture review workflow
Use this mode when the user asks to review, audit, inspect, or give feedback on an existing project.
- Inspect the existing folder structure, target boundaries, representative Views, ViewModels, UseCases, Managers, factories, and navigation wiring before recommending changes.
- Trace actual dependencies from the composition root through a feature. Do not infer a violation from a filename or folder name alone.
- Report findings with file paths and symbols when possible. Separate required corrections, recommendations, and contextual options.
- Explain the smallest change that would resolve each required correction and identify any affected lifetime or isolation boundary.
- Do not create files, restructure the project, add abstractions, run tests, or run builds during a review unless the user separately requests implementation or verification.
- End with a prioritized list of reviewable changes. If the user approves a specific item, implement only that item and preserve earlier approved decisions.
Review mode is evidence-first: existing code and the user's stated project contract take precedence over generic examples in this skill.
During review, flag comments that merely narrate obvious code and remove them only when implementation is requested. Preserve comments that explain why the code must remain unusual.
Model ownership
Treat domain, presentation, and persistence models as suggested responsibility categories, not a mandatory three-type structure. Reuse plain domain values across Managers, UseCases, ViewModels, and Views when their meaning matches. Separate persistence/transport/UI representations only when their requirements differ. Keep framework-managed records and contexts inside their owning integration; business-facing APIs expose domain values or identifiers. See model ownership for placement and conversion rules.
Scaffold workflow
Before choosing observation or navigation APIs, inspect the project's minimum OS versions and Swift toolchain. Preserve its supported targets; adapt examples rather than raising deployment targets to fit them.
Phase 1 — Propose (no file creation)
- Confirm feature name and domain (e.g.
Catalog/ItemList). List files to add under:
Pages/Factory/(only if creation/selection complexity warrants it)Manager/(only if infrastructure is needed)UseCase/(only if business operations need a separate boundary)Component/(only when UI is shared)Constants/Utility/
Adapt roots to the project's existing layout.
- Output:
- Folder tree
- Protocol names per layer
- Dependency graph for the layers that actually exist
ViewStatecases only if an enum improves the feature's state model
- Stop and ask for approval unless the user has already approved this implementation scope in the current conversation.
Phase 2 — Implement (after approval)
- Create protocols before implementations.
- Wire the composition root in
App, calling factories for individual instances. - ViewModel + View last.
- Extract shared UI to
Component/only when used by 2+ features.
New feature checklist (short)
- Factory — only if creation/selection complexity warrants it; reuse existing factories
- Manager — only if the feature needs infrastructure; use a protocol when replaceability/test seams matter
- UseCases — only for focused business operations that need a separate boundary
- ViewModel —
[Feature]ViewModel; addViewStatewhen mutually exclusive modes benefit from it - ViewModel observation matches deployment target and existing conventions; injected ViewModel lifetime is explicit
- View —
[Feature]Viewreceives one owning ViewModel; compose independent features without an aggregate ViewModel - DI wired in
App; shared manager instances created once and reused
Layer quick reference
| Layer | Responsibility |
| Factory | Create individual Managers, UseCases, and ViewModels from supplied dependencies. App composes and shares the graph |
| Manager Common | Logging, networking, storage |
| Navigation | Presentation state scoped to a stack/window; Views may access it, ViewModels/UseCases may not |
| Manager Feature | App-specific system/integration APIs |
| UseCase | One focused business responsibility; orchestrate manager protocols directly, never other UseCases |
| ViewModel | UI state, user actions → focused UseCase protocols when needed; no other ViewModels |
| Feature View | Present one feature; forward actions to its one owning ViewModel |
| Composition View | Assemble independent feature views; own layout and cross-feature presentation, not feature business state |
| Component | Visual UI driven by values, bindings, and action closures |
Testing guidance
- UseCase tests: when a UseCase exists, mock its Manager protocols and verify business rules and orchestration.
- ViewModel tests: mock injected UseCase protocols when present; verify state transitions and user-intent handlers.
- View tests: use previews or snapshot-style checks when they provide value; keep Views thin and deterministic.
Migration guidance
If adopting this architecture in an existing codebase:
- Existing MVVM: introduce a UseCase when business logic grows beyond UI state shaping.
- ViewModel calling managers directly: wrap manager calls behind a UseCase protocol; ViewModel depends on the relevant UseCase protocols only.
- Factory migration: keep individual creation methods in appropriately scoped factories. Move graph assembly and shared-instance ownership into
App; replace hidden feature builders one feature at a time. Do not consolidate focused factories merely to enforce a single factory. - ViewModel or UseCase chains: remove ViewModel → ViewModel and UseCase → UseCase dependencies. Inject focused UseCases into the owning ViewModel; keep business workflows inside a focused UseCase operating directly on manager protocols.
Anti-patterns (reject if suggested)
// BAD — ViewModel → Manager
final class ItemListViewModel {
private let fileManager = FileSystemManager()
}
// GOOD
final class ItemListViewModel {
private let useCase: ItemListUseCaseProtocol
}// BAD — View → UseCase
Button("Load") { Task { await useCase.load() } }
// GOOD
Button("Load") { Task { await viewModel.load() } }Additional resources
Read only what you need:
- Layer overview
- Folder structure
- Model ownership and persistence boundaries
- Dependency flow
- Naming conventions
- New feature checklist
- Anti-patterns
- Navigation and dependency lifetimes
- Concurrency
- Observation and deployment targets
- For deep Swift 6 concurrency diagnostics and migration, use the companion Swift Concurrency Agent Skill.
- End-to-end example
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

