13 of 20 · System architecture
Feature Modules
Feature modularization splits an app into modules per feature, each with a small interface module and an implementation module. Features depend on each other's interfaces; implementations only meet at the composition root.
How it's wired
- ThanksHistoryInterface holds the protocol.
- ThanksHistory implements it with internal screens. Only AppContainer imports the implementation.
| Part | Owns | Looks like |
|---|---|---|
| Interface module | Tiny, stable contract | ThanksHistoryInterface |
| Implementation module | Screens and logic, internal | ThanksHistory |
| Composition root | The one place implementations meet | AppContainer |
Swift example: circular feature imports vs. interface modules
Splitting each feature into a tiny Interface module and an Implementation module breaks cycles and keeps incremental builds fast.
Interface + Implementation + Composition Root
FeedFeature imports ProfileInterface, never ProfileImpl—so editing ProfileImpl does not recompile FeedFeature.
// Module: ProfileInterface (tiny, rarely changes)
@MainActor
public protocol ProfileBuilding {
func makeProfile(userID: String) -> UIViewController
}
// Module: FeedImpl (imports ProfileInterface only—NOT ProfileImpl)
@MainActor
public final class FeedCoordinator {
private let profileBuilder: any ProfileBuilding
public init(profileBuilder: any ProfileBuilding) {
self.profileBuilder = profileBuilder
}
func didTapAuthor(_ id: String) {
let vc = profileBuilder.makeProfile(userID: id)
nav.pushViewController(vc, animated: true)
}
}
// Module: App (Composition Root—the ONLY target importing both Impl modules)
let feed = FeedCoordinator(profileBuilder: ProfileBuilderImpl(api: api))Keep Interface modules narrow per domain; one giant CoreInterfaces module imported by everyone rebuilds the whole app on every PR.
What you gain and what it costs
- Build times: changing one feature's implementation rebuilds that module and the app, not every feature that uses it.
- Ownership: modules map to teams, and module APIs make cross-team changes explicit and reviewable.
- Preview apps: build and run one feature with fakes in seconds, without launching the whole app.
- Costs: Package.swift plumbing, cross-module refactors, and "public" everywhere. Watch for a Core module everything imports; touching it rebuilds the world.
- Linking matters: many dynamic frameworks slow app launch; prefer static linking for feature modules.
When I'd modularize by feature
| Three or more teams, or slow incremental builds | Interface plus implementation modules so edits rebuild one feature instead of the whole app. |
|---|---|
| One small team | Layer modules or folders: Package.swift plumbing and public APIs cost more than they save. |
Compared
Monolith vs layer modules vs feature modules
| Monolith | Layer modules | Feature modules | |
|---|---|---|---|
| Incremental builds | Slow | Better | Best |
| Team ownership | Blurry | By layer | By feature |
| Setup cost | None | Moderate | Highest |
Expert notes
- Modularize along ownership lines. A module boundary no team owns is just friction.
Check yourself
Answer out loud before you reveal. Recall is what makes it stick.
Explain Feature Modules in 30 seconds.
- Feature modules split an app into an interface module and an implementation module per feature.
- Features depend only on each other's interfaces, and implementations meet at one composition root.
- That buys faster incremental builds, preview apps per feature and clear team ownership.
- The costs are Package.swift plumbing and cross-module refactors, so I start with logical boundaries and split physically when build times or ownership demand it.
Why split an app into dozens of SPM feature modules? What do you actually gain?
- What I gain is cheaper change.
- A feature builds and previews without compiling the whole app, the compiler enforces which features can see each other, and ownership maps to modules.
- App Clips and extensions can link only what they need.
- The cost is
Package.swiftwiring, cross-module refactors and access control everywhere. - I wouldn't start with dozens; I'd split when build times hurt, teams collide in the same code, or boundaries keep getting bypassed.
Onboarding only appears on first launch, so QA keeps reinstalling the app to test it. How would you restructure the code?
- Before restructuring, I'd add a debug launch argument that resets first-launch state, because that fixes QA's loop today at almost no cost.
- If onboarding changes often, I'd move it into its own module and build a small preview app from only the modules it needs, so the flow runs standalone with injected fake state.
- That only works if the module doesn't depend on the app target, which is exactly the discipline it enforces.
Feature A must navigate to Feature B, but feature modules shouldn't import each other. How do you wire it?
- Don't import B's implementation.
- Either A depends on B's interface module, a small protocol like
ProfileRouting, or A exposes a closure likeonSelect: (Item.ID) -> Voidand the composition root wires it to B. Only the root sees both implementations. - Because features stay independent, each can also ship as a standalone preview app for QA.
Leadership wants a strict modular, plugin-based architecture for a 10-person team. What does it actually cost?
- I'd weigh it by what changes and who collides, with headcount only as a multiplier.
- A plugin architecture adds interface modules, registration and upfront contract design, and a central group approving core changes becomes a queue.
- Those costs pay off when features have independent lifecycles, ship in parallel, or the domain needs hard boundaries.
- I'd start with logical boundaries, add physical modules where builds or ownership hurt, and use plugins only where runtime swapping is real.
Read it in the app's source
Done with Feature Modules? Mark it complete. Nailing its cards builds this pumpkin, row by row.