What are Clean Architecture and the Dependency Rule?
The point
Clean Architecture (Robert Martin) is a way to organize code into concentric layers with business rules in the center and details outside:
- Entities — domain models and rules (
Account,Money). - Use Cases (Interactors) — application scenarios: "withdraw money", "place an order".
- Interface Adapters — Presenter/ViewModel, Repository implementations, DTO-to-Entity mappers.
- Frameworks & Drivers — UIKit/SwiftUI, URLSession, SwiftData/Core Data, SDKs.
Dependency Rule: source code may depend only inward. A Use Case does not know that data comes from URLSession, nor that the UI is SwiftUI. For an inner layer to call an outer one (save to a DB) it declares a port — a protocol — and the outer layer implements it. This is DIP at the scale of the whole app.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep