System designInterview preparation
Intermediate·Concept·2 min read

What are layered, clean and hexagonal architecture?

Practice this question

Definition:

Layered architecture separates responsibilities such as HTTP handling, business rules and persistence. Clean and hexagonal architecture emphasize keeping core business decisions independent of frameworks and external systems. Ports describe what the core needs, and adapters implement those contracts for a particular database or service.

Key points:

  • Layered: separate HTTP, business logic and data access.

  • Clean: core business rules do not depend on framework details.

  • Hexagonal: adapters connect the core to databases, APIs and other external systems.

  • Dependency direction matters more than the number of folders: business logic should not require an HTTP request object just to calculate a result.

Interview point:

  • Show how you could replace a provider or test a business rule without booting the entire framework.
Adapted from 07_SYSTEM_DESIGN_ARCHITECTURE.md · “What are layered, clean and hexagonal architecture?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.