Skip to main content

How are the layers structured in Clean Architecture?

In Clean Architecture, the layers are arranged in concentric circles, where each inner layer is independent of the outer ones. Dependencies always point inward, toward business logic, never outward.


1. Entities (Domain Layer)

What it is: The core of the system: business models and rules that do not depend on technology.

Contains:

  • business objects (User, Order, Invoice),
  • invariants and business rules (calculateTotal(), validatePayment()).

Does not know about: frameworks, databases, the interface, the network.

Example:

python
class Order: def calculate_total(self): return sum(item.price for item in self.items)

2. Use Cases / Application Layer

What it is: The system's use cases: application logic describing how business rules are applied in specific processes.

Contains:

  • interactors (CreateOrder, RegisterUser),
  • business process coordinators,
  • interfaces to repositories and gateways.

Example:

python
class CreateOrder: def __init__(self, order_repo, payment_service): ... def execute(self, order_data): order = Order(order_data) order.validate() self.order_repo.save(order)

3. Interface Adapters / Adapter Layer

What it is: The layer that translates data from the outside world into a format the business logic understands.

Contains:

  • controllers (REST, gRPC),
  • presenters, serializers,
  • implementations of repository interfaces, APIs, etc.

Example:

python
class OrderController: def post(self, request): use_case = CreateOrder(OrderRepo(), PaymentService()) return use_case.execute(request.data)

4. Frameworks & Drivers / Infrastructure Layer

What it is: The outermost layer: specific technologies and tools: frameworks, databases, UI, APIs, servers.

Contains:

  • Django/Spring, PostgreSQL, Redis, Kafka, Flask, etc.
  • infrastructure dependencies and configuration.

5. The Dependency Rule

Code in an outer layer can know about an inner one, but an inner layer must never depend on an outer one.


Summary:

The layers of Clean Architecture are structured from abstract to concrete: Entities → Use Cases → Interface Adapters → Frameworks.

The closer a layer is to the center, the more stable and long-lived its code.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.