ios-architecture-advanced/SKILL.md
Expert iOS app architecture patterns — dependency injection containers with scoped lifetimes, MVVM navigation via state enums, Redux/unidirectional data flow, Elements architecture, use case factory protocols, and Observer composition. Use when...
npx skillsauth add peterbamuhigire/skills-web-dev ios-architecture-advancedInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
ios-architecture-advanced or would be better handled by a more specific companion skill.SKILL.md first, then load only the referenced deep-dive files that are necessary for the task.Pattern selection matters less than application. Two root causes explain virtually all architectural failure:
Fix these two and almost any pattern works. Ignore them and no pattern saves you.
Scope determines when an object is created, how long it lives, and what it knows about.
| Scope | Lifetime | Canonical examples | |-------|----------|--------------------| | App | Launch → process death | Auth store, logger, analytics | | User | Sign-in → sign-out | Remote APIs, user data stores | | Feature | Feature entry → exit | Anything needing one captured value | | Interaction | Gesture start → end | In-flight request cancellation tokens |
User scope eliminates Optional unwrapping codebase-wide. When user-specific objects live in an App-scoped singleton, every consumer must guard against nil. Move them to User scope — created at sign-in, destroyed at sign-out — and UserSession is always non-optional inside the scope.
Child containers request from parents; parents never request from children.
class AppDependencyContainer {
// App-scoped singletons: logger, analytics, keychain
let logger: Logger
let analyticsService: AnalyticsService
func makeUserDependencyContainer(userSession: UserSession)
-> UserDependencyContainer {
UserDependencyContainer(appContainer: self, userSession: userSession)
}
}
class UserDependencyContainer {
private let appContainer: AppDependencyContainer
let userSession: UserSession // captured immutably at sign-in
init(appContainer: AppDependencyContainer, userSession: UserSession) {
self.appContainer = appContainer
self.userSession = userSession
// No Optional unwrapping for userSession anywhere in user scope
}
func makePickMeUpContainer(pickupLocation: Location)
-> PickMeUpDependencyContainer {
PickMeUpDependencyContainer(userContainer: self,
pickupLocation: pickupLocation)
}
}
class PickMeUpDependencyContainer {
private let userContainer: UserDependencyContainer
let pickupLocation: Location // mutable global → immutable feature value
init(userContainer: UserDependencyContainer, pickupLocation: Location) {
self.userContainer = userContainer
self.pickupLocation = pickupLocation
// pickupLocation can never change mid-feature; race conditions eliminated
}
}
Key insight: Capturing a mutable global in a scope constructor converts it to an immutable constant for the feature's entire lifetime. Eliminates optionals and race conditions in one move.
Closures passed as dependencies become unreadable at call sites. Factory protocols restore discoverability and enable autocomplete.
protocol SignInUseCaseFactory {
func makeSignInUseCase(
username: String,
password: Secret,
onStart: @escaping () -> Void,
onComplete: @escaping (SignInUseCaseResult) -> Void
) -> UseCase
}
// The container already has a method with matching signature.
// Just declare conformance — no implementation needed.
extension OnboardingDependencyContainer: SignInUseCaseFactory {}
// ViewController receives the narrowest protocol, not the full container
class SignInViewController: UIViewController {
let useCaseFactory: SignInUseCaseFactory
func handleSignInTapped() {
let useCase = useCaseFactory.makeSignInUseCase(
username: usernameField.text ?? "",
password: Secret(passwordField.text ?? ""),
onStart: { [weak self] in self?.showLoading() },
onComplete: { [weak self] result in self?.handle(result) }
)
useCase.start()
}
}
Extended guidance for ios-architecture-advanced was moved to references/skill-deep-dive.md to keep this entrypoint compact and fast to load.
Use that deep dive for:
2. Model-Driven Navigation3. Use Case Pattern4. Observer Element Pattern5. Redux / Unidirectional Data Flow6. Architecture Selection Guide7. Build Time as Architecture ConcernAnti-PatternsQuick Decision Checklistdata-ai
Use when adding AI-powered analytics to a SaaS platform — semantic search over business data, natural language queries, trend detection, anomaly alerts, and AI-generated insights for dashboards. Covers embeddings, NL2SQL, and per-tenant analytics...
data-ai
Design AI-powered analytics dashboards — what metrics to show, how to display AI predictions and confidence, drill-down patterns, KPI cards, trend visualisation, AI Insights panels, export design, and role-based dashboard variants. Invoke when...
development
Use when designing, building, reviewing, or upgrading production software systems that must be secure, performant, maintainable, scalable, and user-centered. Apply before writing specs, code, architecture, APIs, databases, mobile apps, SaaS platforms, or ERP systems.
development
Professional web app UI using commercial templates (Tabler/Bootstrap 5) with strong frontend design direction when needed. Use for CRUD interfaces, dashboards, admin panels with SweetAlert2, DataTables, Flatpickr. Clone seeder-page.php, use...