Clean Code Architecture
Clean Code Architecture
Onion Structure
Let's break down each layer and discuss the types of implementations and folder structures
commonly associated with them:
Domain Layer:
Purpose: Represents the core business logic and rules of the application. It contains entities,
value objects, and the business logic that operates on them.
Implementations:
Folder Structure:
/src
/domain
/entities
/value_objects
/repositories
/services
Application Layer:
Purpose: Orchestrates the data flow between the Presentation, Domain, and Infrastructure layers.
It contains use cases and application-specific business rules.
Implementations:
Folder Structure:
/src
/application
/use_cases
/dtos
Infrastructure Layer:
Purpose: Contains implementations for external concerns such as databases, APIs, and
frameworks. This layer is where the application communicates with external services.
Implementations:
Folder Structure:
/src
/Infrastructure
/database
/frameworks
/external_services
Presentation Layer:
Purpose: Handles user interface and input/output. It can be a web interface, CLI, or any other
means the user interacts with the application.
Implementations:
❖ Controllers (or Handlers): Handle user input, orchestrate calls to use cases, and manage
the flow of data.
❖ Views: Display information to the user.
❖ Presenters: Format data for display.
Folder Structure:
/src
/Presentation
/controllers
/views
/presenters
Example:
Suppose we are going to develop a full stack web development about Online doctor visiting,
where doctors will consult patients through video calls and write recommendations, which will
be downloaded by the patient. Before consulting with doctors, patients must register and book a
time slot filling out a form about diseases and corresponding doctors. Here I want to set up also
notifications services. Now Write Clean Code Architecture for this project.
Domain Layer:
This layer contains the core business logic and entities of your application.
Entities:
Value Objects:
Repositories:
Application Layer:
This layer contains the application-specific business rules and orchestrates the flow of data
between the domain and infrastructure layers.
Use Cases:
Interfaces:
This layer contains the implementation of data access, external services, and any other
infrastructure-specific concerns.
Data Access:
External Services:
Presentation Layer:
This layer handles user interaction and presentation.
Controllers/Handlers:
ViewModels/DTOs:
Notification Services:
● Implement notification services for sending reminders and updates to patients and
doctors.
Visual Presentation of Folder Structure