15 of 22 · 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 |
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
| Several teams, build times hurting | Interface plus implementation modules. |
|---|---|
| One small team | Layer modules or folders are enough. |
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?
- Faster builds and isolation.
- With fine-grained modules you build one feature without compiling the whole app, so iteration speeds up and SwiftUI previews stay stable.
- Picking only the modules you need also keeps size-constrained targets like App Clips and extensions small.
- The costs are real: more
Package.swiftwiring and dependency hygiene, so weigh them for your team.
Onboarding only appears on first launch, so QA keeps reinstalling the app to test it. How would you restructure the code?
- Move onboarding into its own module and build a small preview app from just the modules it needs.
- Then the flow launches on its own, with no reinstalling to reset first-launch state.
- QA and developers get a one-tap loop.
- It only works if the feature module has no dependency on the app target, so it rewards modularization discipline.
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?
- Name the costs.
- A plugin architecture has more pieces than MVC or MVP and needs more upfront planning.
- A small reviewer group must approve every core change, which slows everyone.
- That process makes sense with dozens of parallel teams and weekly releases.
- For 10 engineers it's mostly overhead.
- Match the ceremony to your team count and adopt only the parts that solve real pain.