Suggest an editImprove this articleRefine the answer for “How are the layers structured in Clean Architecture?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)In **Clean Architecture**, layers are arranged in concentric circles, where each inner layer is independent of the outer ones, and dependencies always point inward, toward business logic. **Key point:** the layers are structured from abstract to concrete: Entities → Use Cases → Interface Adapters → Frameworks, and the closer a layer is to the center, the more stable its code.Shown above the full answer for quick recall.Answer (EN)ImageIn **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.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.