Skip to main content
InterviewHubPRO
Section Overview
Q15

Question 15 of 50

Part 2: Behavioral Patterns & Communication (11 - 24)

30%
Design Patterns (GoF) (50 Qs)•Part 2: Behavioral Patterns & Communication (11 - 24)

What is Clean Architecture (The Onion / Hexagonal Architecture)?

senior LevelCode ExampleSystem DesignBehavioral

In Simple Words: Introduced by Uncle Bob to create systems independent of frameworks, databases, and UI:

  • Dependency Rule: Dependencies always point inwards toward the core domain!
    1. Entities (Core Domain): Pure business rules and models (Zero external dependencies).
    2. Use Cases (Application Business Rules): Orchestrates data flow to/from entities.
    3. Interface Adapters (Controllers, Gateways, Presenters): Translates data between use cases and external formats.
    4. Frameworks & Drivers (External): UI, Database (SQL/NoSQL), Web Server, Third-party APIs.
  • The core business domain does not care whether data is stored in PostgreSQL, MongoDB, or an in-memory JSON file.
text
Clean Architecture Layers:
┌───────────────────────────────────────────────┐
│     Frameworks & Drivers (DB, UI, Devices)   │
│   ┌───────────────────────────────────────┐   │
│   │   Interface Adapters (Controllers)    │   │
│   │   ┌───────────────────────────────┐   │   │
│   │   │      Application Use Cases    │   │   │
│   │   │   ┌───────────────────────┐   │   │   │
│   │   │   │   Entities (Domain)   │   │   │   │
│   │   │   └───────────────────────┘   │   │   │
│   │   └───────────────────────────────┘   │   │
│   └───────────────────────────────────────┘   │
└───────────────────────────────────────────────┘
Dependency Arrow: External ───────► Inward (Domain)