Modular SPM Architecture and Dependency Decoupling Framework
Design a modular multi-package Swift Package Manager architecture to accelerate build times and decouple feature boundaries.
Use this template when decomposing a monolithic iOS codebase into micro-packages using Swift Package Manager (SPM). It provides a concrete architecture for interface abstraction, dependency injection, and clean build graphs.
Role: Principal iOS Software Architect with deep expertise in Swift Package Manager, compilation graph optimization, and clean architecture.
Context
- Core Repository: {{target_project}}
- Target Package Count: {{module_count_target}}
- Dependency Injection Approach: {{di_approach}}
- Target Clean Build Time: {{build_time_goal_seconds}}
- Shared Domain Logic Scope: {{shared_domain_logic}}
- UI Framework Composition: {{ui_framework_stack}}
Task
Formulate a scalable modularization framework for {{target_project}} that decomposes application logic into isolated Swift Packages, enforcing inverted dependencies via {{di_approach}} to achieve {{build_time_goal_seconds}} build times.
Method
- Audit the dependency graph of {{target_project}} to identify high-fan-in utility hubs and cross-feature circular references.
- Design a multi-tiered package taxonomy (e.g., Core/Foundations, Domain/Entities, Feature Interfaces, Feature Implementations).
- Define interface-only packages containing public protocols and model DTOs to decouple concrete dependencies.
- Establish a centralized registration and container strategy using {{di_approach}} for compile-time or runtime resolution.
- Structure dynamic versus static library linkage rules in
Package.swiftto prevent duplicate symbol emission and binary bloat. - Align {{shared_domain_logic}} boundaries to isolate business rules from {{ui_framework_stack}} UI rendering code.
- Map out an incremental migration strategy to reach {{module_count_target}} discrete packages while preserving developer velocity.
- Formulate CI build matrix settings and local derived data caching to hit {{build_time_goal_seconds}}.
Constraints
- MUST enforce strict Interface/Implementation package separation to eliminate direct feature-to-feature couplings.
- MUST NOT introduce circular module dependencies across the Swift Package graph.
- MUST define explicit accessibility levels (
publicvspackagevsinternal) across module boundaries. - Code samples must follow modern Swift 5.10+ / 6.0 Package Description syntax.
Output format
- Section 1: SPM Package Graph Topology (ASCII diagram or table mapping tiers and access boundaries)
- Section 2: Interface & Registration Blueprint (Swift code illustrating {{di_approach}} with sample interfaces)
- Section 3:
Package.swiftArchitecture Templates (sample target declarations with explicit target dependencies) - Section 4: Incremental Decoupling Roadmap (4-stage migration plan targeting {{module_count_target}} modules)
- Total length: 450-800 words.
Self-review
- Ensure all 6 context variables are deeply woven into the structural rules.
- Verify that package dependency directions flow strictly inward toward core domains.
- Confirm that build performance tactics directly support the {{build_time_goal_seconds}} threshold.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.