Swift architecture and data flow
Read docs/ARCHITECTURE.md, then references/state-and-dependencies.md. Use this skill before introducing a model, service, store, persistence mechanism, cache, or app-wide state.
Workflow
- Write the behaviour and invariants without UI terminology.
- Decide whether it is a value, pure operation, external capability, or mutable application state.
- Put values/pure operations in
Domain. - Define external needs as narrow
Sendableprotocols inInfrastructure. - Implement dependencies separately and construct them at the app boundary.
- Keep view-facing shared state in a main-actor-isolated
@Observabletype; rely on the package default rather than repeating@MainActor. - Own that model once with
@State; pass via@Environmentor explicit parameters; expose editable projections through@Bindable/@Binding. - Model asynchronous UI state explicitly and test each transition.
- Document persistence, migration, sync, conflict, deletion, privacy, and backup semantics before selecting storage.
Guardrails
- No global service locator, mutable singleton, or hidden dependency lookup.
- No networking, persistence, keychain, or business rules in a view.
- No
@AppStorageinside an@Observablemodel and no secrets in@AppStorageanywhere. - No cached derived collection without clear invalidation.
- No third-party architecture framework merely to avoid writing small explicit types.
- Do not create a view model per view by reflex; add state coordination only when behaviour needs an owner or test seam.
Review output
Draw the ownership and dependency flow, identify competing sources of truth and stale snapshots, then propose the smallest boundary correction. Include migration implications when storage changes.