SwiftPumpkin

10 of 22 · System architecture

Facade & Modules

A facade is a small public API in front of a complex subsystem. Putting the subsystem in its own module makes the facade the only thing outsiders can reach, so the compiler enforces the boundary.

How it's wired

send(note)EncodesTransportsApp codeCalls one APIFacadePublic, smallSubsystem AinternalSubsystem Binternal
calls or tellsreports backThe module exports only the facade. The compiler stops anyone reaching the internals.
  • ThanksVault fronts storage and PumpkinPatchClient fronts RPC.
  • Envelopes, transports and file I/O are internal to their Swift packages.
PartOwnsLooks like
FacadeThe only public entry pointPumpkinPatchClient, ThanksVault
SubsystemComplex internals, free to changeinternal types in the package
ModuleEnforces the boundarySwift package target

What matters in practice

  • Without a module boundary a facade is a suggestion. Under deadline, someone imports the transport directly.
  • Facades grow into god objects. Split by capability (notes, sync, catalog) instead of one API client with 80 methods.
  • The facade is what you version. Behind it you can swap HTTP for gRPC, JSON for protobuf, or add caching without touching a single caller.

When I'd put a facade in a module

Networking, persistence, analytics, paymentsAnything with more than one moving part.
A subsystem another team ownsThe facade is the contract between teams.

Compared

Facade vs adapter

FacadeAdapter
PurposeHide a subsystemMake incompatible types fit
In this appPumpkinPatchClient, ThanksVaultUIKitScreen (representable)

Expert notes

  • Make the boundary a compiler error, not a code-review comment.

Check yourself

Answer out loud before you reveal. Recall is what makes it stick.

30-second answer

Explain Facade & Modules in 30 seconds.

System designAsked directly

Facade versus Gateway: what's the difference, and who writes each?

System designAsked indirectly

A third-party analytics SDK is imported in forty files and now must be replaced. How do you prevent that next time?

System designAsked indirectly

Sibling modules in your Swift package need shared helper APIs, but app clients shouldn't use them. How do you expose them?

Read it in the app's source