DevPrep

All topics › Software architecture

What are Clean Architecture and the Dependency Rule?

Senior PRO

The point

Clean Architecture (Robert Martin) is a way to organize code into concentric layers with business rules in the center and details outside:

  1. Entities — domain models and rules (Account, Money).
  2. Use Cases (Interactors) — application scenarios: "withdraw money", "place an order".
  3. Interface Adapters — Presenter/ViewModel, Repository implementations, DTO-to-Entity mappers.
  4. 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

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store