This article examines the public reference implementation Modular. The objective is not to display a large package tree, but to show how intentional boundaries can improve delivery through clearer ownership and safer change.

UI Matters is about demonstrating value, not just knowledge, so this article focuses on observed behavior and practical implications.

01

Why modularity matters in production

Most iOS codebases do not become hard to maintain because engineers cannot write Swift. They become hard to maintain because dependency boundaries remain implicit.

Common symptoms include:

  • Every feature change feels more expensive over time.
  • SwiftUI previews compile unrelated infrastructure and become slower.
  • Shared modules become high-risk dumping grounds.
  • Parallel team work produces integration friction.
  • Refactors are delayed because rebuild impact is unclear.
02

Investigation context

The project explored modular boundaries under realistic product pressure. The process used throughout was:

Investigation process
Problem -> Investigation -> Implementation -> Stress test -> Evidence -> Production implications

The key result: rules were extracted from observed behavior, not from ideology.

03

The production reference app

Modular is the production-style implementation of those findings. Its high-level dependency graph makes the app target the composition root:

Architecture
App target (composition root)
├── CatalogFeature      ─┬── DesignSystem
│                        ├── ItemDomain
│                        └── AnalyticsAPI
├── FavoritesFeature    ─┬── DesignSystem
│                        ├── ItemDomain
│                        └── AnalyticsAPI
├── SearchFeature       ─┬── DesignSystem
│                        ├── ItemDomain
│                        └── AnalyticsAPI
├── CatalogWidgets (framework target) ─┬── DesignSystem
│                                       └── ItemDomain
├── Networking
└── AnalyticsLive ── AnalyticsAPI + third-party SDK adapter

Key properties

  • No feature imports sibling features for app-level workflows.
  • Features consume lightweight inputs, not app infrastructure setup.
  • Third-party SDK imports are contained in one module.
  • The app target owns composition and orchestration.
04

What changed, and why it matters

1. Folders are not module boundaries

Features/* folders inside one app target are organization only. Compile-time boundaries come from targets/modules.

Production implication: repository structure and dependency structure are separate decisions.

2. Access control is architecture, not style

A failed compile caused by a public default argument referencing an internal symbol exposed a real truth: public API shape has long-term cost.

Production implication: every public declaration is architectural surface area.

3. Preview speed reflects dependency design

DesignSystem previews are fast because dependencies are narrow. App-level previews compile a wider graph by design.

Production implication: slow previews often signal coupling problems, not just tooling noise.

4. Feature inputs should model UI needs

Infrastructure-heavy view constructors were replaced with lightweight inputs, for example CatalogInput plus fixtures.

Production implication: previews and tests stay deterministic without forcing networking, session, or analytics construction.

5. Dependency direction must stay intentional

A temporary Feature -> Networking shape was corrected. Live implementations moved to app composition, such as LiveCatalogRepository in the app target.

Production implication: features remain reusable and infrastructure-agnostic.

6. Shared domain extraction should be pressure-driven

ItemDomain was extracted when multiple features truly needed shared ownership of Item.

Production implication: shared modules should emerge from reuse pressure, not from symmetry.

7. Cross-feature workflows belong to app composition

Feature outputs such as addToFavorites replaced feature-to-feature imports.

Production implication: orchestration stays explicit in the app layer, while features remain independent.

8. Third-party dependencies need containment boundaries

AnalyticsAPI defines the contract; AnalyticsLive owns SDK integration.

Production implication: SDK replacement cost and dependency leakage stay controlled.

9. Why CatalogWidgets exists as a framework target

CatalogWidgets was intentionally included as an Xcode framework target to compare target-based boundaries with local SwiftPM boundaries in the same project.

This surfaced a useful constraint: framework public APIs must own their exported shape. Exposing shared internal types directly caused access-control pressure, which was resolved with a module-owned DTO (CatalogWidgetItem) mapped at composition.

Production implication: this extra friction is useful when evaluating hybrid modularization, binary-facing boundaries, and stricter API ownership.

05

Evidence from the investigation

Preview compilation scope

  • DesignSystem preview: minimal module graph.
  • CatalogFeature preview: bounded graph (CatalogFeature + dependencies).
  • App composition preview: full graph by design.

This separation improves day-to-day UI iteration while preserving integration checks at app level.

Fan-in and fan-out: the practical model

  • Fan-in is how many modules depend on a module.
  • Fan-out is how many modules a module depends on.

In this graph:

  • ItemDomain has high fan-in from CatalogFeature, FavoritesFeature, and SearchFeature.
  • DesignSystem also has significant fan-in, but remains stable by staying presentation-only.
  • Feature modules have moderate fan-out toward stable foundations and low fan-in from peer features.

Why this matters:

  • High fan-in plus unstable API means expensive rebuild cascades.
  • High fan-in plus a narrow, stable API supports predictable scaling.
  • High fan-out in a feature often indicates too many responsibilities.

Testability at module scope

Package-level tests validated feature and infrastructure behavior without full app startup. This reduces feedback-loop time and keeps failures close to ownership boundaries.

06

The 13 rules that survived

  1. A module must justify its boundary.
  2. Features should not import sibling features for app workflows.
  3. Feature inputs should describe UI needs, not infrastructure.
  4. Public API is architectural surface area.
  5. Keep shared modules narrow and stable.
  6. Keep DesignSystem presentation-only.
  7. The app is the composition root.
  8. Contain third-party SDKs behind a narrow adapter.
  9. Previews should be owned by the module they exercise.
  10. Package count and target count are separate decisions.
  11. Do not abstract concrete dependencies until abstraction is justified.
  12. Consider dependency fan-in and API volatility when setting boundaries.
  13. Keep architecture intentionally incomplete until pressure justifies more.

Meta-rule: these are decision tools, not dogma.

The one-sentence boundary test

Before creating a new module, ask whether it can explain what it owns in one sentence. If not, it probably should not exist yet. This keeps module count tied to ownership clarity.

When to reconsider a rule

Every rule has an escape hatch. For example:

  • If a third-party dependency is trivial and truly single-use, a dedicated adapter module may be overhead.
  • If a feature input object grows into a large service bag, the feature boundary is probably wrong.
  • If a shared domain model churns constantly, duplication or anti-corruption mapping may be cheaper.

The point is judgment, not purity.

07

Anti-patterns to catch early

Feature cycle

Dependency direction
❌ CatalogFeature -> FavoritesFeature
❌ FavoritesFeature -> CatalogFeature

✓ Both features emit actions
✓ App composition coordinates workflow

Infrastructure leakage into features

Dependency direction
❌ CatalogFeature imports Networking and AnalyticsLive directly

✓ CatalogFeature depends on CatalogInput + AnalyticsAPI
✓ App target assembles live dependencies

Giant shared module

Module ownership
❌ Shared/Core contains UI, domain, networking, analytics, formatting

✓ DesignSystem: presentation only
✓ ItemDomain: narrow domain ownership
✓ Networking: transport only

SDK spread

Dependency direction
❌ SDK imports across multiple feature packages

✓ Feature -> AnalyticsAPI
✓ App -> AnalyticsLive -> SDK

Preview tied to the full app graph

Preview scope
❌ Feature preview requires app startup and infrastructure boot

✓ Module-local fixtures + lightweight inputs
✓ Feature preview compiles bounded graph
08

Trade-offs and when modularity is worth it

What improves

  • Feature autonomy and clearer ownership boundaries.
  • Faster local UI iteration through module-local previews.
  • Better module-level test isolation.
  • Reduced third-party dependency leakage.
  • More predictable rebuild consequences.

What costs more

  • More manifests and dependency declarations.
  • More deliberate API/access-control design.
  • More visible app composition code.
  • More coordination for shared-domain API changes.
  • One more target and adapter code when dependency containment is needed.

This approach is not free. It is a deliberate exchange: upfront structure for long-term delivery stability.

Usually worth it when

  • Multiple independent features evolve in parallel.
  • More than one engineer or team contributes continuously.
  • Product lifespan is measured in years.
  • Preview/build/test loop speed affects daily output.
  • SDK sprawl and shared-domain churn are emerging risks.

Usually not worth it when

  • One short-lived feature dominates scope.
  • One engineer owns the entire app and current velocity is healthy.
  • Boundary overhead would exceed product complexity.
09

Objections from senior engineers

“This is over-engineering.”

Sometimes true. Boundaries should be extracted from pressure, not aesthetics.

“Why not keep one app target longer?”

That can work early. The risk is migration cost once coupling hardens. Incremental boundary extraction reduces that risk.

“Protocols everywhere create noise.”

Agreed. Abstraction should exist only when it buys isolation, replacement, containment, or testability. Concrete dependencies are often better when coupling is cheap and intentional. In this project, not every dependency was abstracted.

“More modules do not always improve build time.”

Correct. Additional modules add manifests, API design, and coordination costs. Evaluate them against real ownership or dependency problems, not module count alone.

“Framework/SPM boundaries add friction.”

Also true. CatalogWidgets demonstrates that this friction can be beneficial when it forces cleaner API ownership.

10

A practical adoption path

If you want to adopt this in an existing app, do not start by creating many packages. Start with one boundary that removes a real pain point:

  1. Pick a feature with unstable dependencies.
  2. Introduce a lightweight input boundary.
  3. Move live infrastructure assembly to app composition.
  4. Add module-local previews and tests.
  5. Check that the boundary improves ownership, testability, or dependency direction.
  6. Extract additional boundaries only when pressure persists.

Quick checkpoint before each extraction

  • Can this boundary be explained in one sentence?
  • Is ownership clearer after extraction?
  • Does dependency direction improve?
  • Does preview/test scope get smaller or clearer?
  • Is measured blast radius better aligned with volatility?

Architecture quality grows through feedback loops, not one-off reorganizations.

11

Production checklist

Use this as a lightweight self-audit:

  • Each module can explain its ownership in one sentence.
  • Dependency graph is acyclic.
  • No feature imports sibling features for app-level workflows.
  • Feature inputs describe UI needs, not infrastructure details.
  • DesignSystem remains presentation-only.
  • Shared modules with high fan-in are narrow and stable.
  • Third-party SDKs are contained behind API and adapter boundaries.
  • Feature previews compile bounded graphs.
  • Module-level tests run without full app startup.
  • App target remains composition/orchestration, not business-logic heavy.
12

What Modular is—and is not

Modular is

  • A production-style reference implementation.
  • A proof asset connecting code, decisions, and evidence.
  • A practical base for architecture reviews and team discussions.

Modular is not

  • A universal template to copy unchanged.
  • A claim that maximum module count equals maturity.
  • A substitute for product-specific engineering judgment.
13

Closing principle

Good modular architecture is not about demonstrating technical sophistication. It is about improving delivery under real constraints: clearer ownership, safer change, faster iteration, and predictable scaling.

For a concrete example of isolated responsibilities in a subsystem, explore the Swift 6 async image pipeline.

Explore the complete source in the Modular GitHub repository.