link: Architectural Patterns

Clean Architecture

Overview

Clean Architecture, proposed by Robert C. Martin (Uncle Bob), is a software design philosophy aimed at creating systems that are easy to maintain, test, and adapt. The core idea is to organize the system in such a way that the business logic is independent of frameworks, user interfaces, databases, and other external concerns. This separation of concerns is achieved through a layered approach, ensuring that the core business logic remains isolated from external changes.

Key Concepts

Core Concepts

  • Independence: The architecture promotes the independence of the business logic from the user interface, database, frameworks, and other external agencies.
  • Layers: The system is divided into concentric layers, each with specific responsibilities, ensuring clear separation of concerns.
  • Dependency Rule: Dependencies point inward, meaning that inner layers are not aware of the outer layers.

Layers of Clean Architecture

Layers

  • Entities: At the core, representing the business objects and containing the core business logic and rules.
  • Use Cases: Surrounding the entities, these contain the application-specific business rules. They orchestrate the flow of data to and from the entities, driving the business processes.
  • Interface Adapters: These convert data from the format most convenient for the use cases and entities to the format most convenient for external agencies like databases and user interfaces.
  • Frameworks and Drivers: The outermost layer containing frameworks and tools such as the database, the web framework, etc. This layer is where all the external dependencies reside.

Dependency Rule

Dependency Rule

  • All dependencies must point inward.
  • Nothing in an inner circle can know anything about something in an outer circle. For example, entities do not know about use cases, use cases do not know about interface adapters, and so on.

Example

Related Topics

References

Hexagonal Architecture and Clean Architecture (with examples) - DEV Community

Clean Coder Blog

GitHub - Code Challenge: Simple Blog API built with TypeScript and MongoDB.