-
-
Notifications
You must be signed in to change notification settings - Fork 689
Home
Sample implementation of the Clean Architecture Principles with .NET Core. Use cases as central organizing structure, decoupled from frameworks and technology details. Built with small components that are developed and tested in isolation.
ProTip #1: To get the Clean Architecture updates hit the WATCH
button 👀.
Manga is a virtual Wallet application in which a customer can register an account then manage the balance with Deposits
, Withdraws
and Transfers
.
The Manga's demo is hosted on Azure
servers and the Swagger UI
client is available at https://clean-architecture-manga.azurewebsites.net/swagger/index.html. It is just beautiful!
Run the Docker container in less than 2 minutes using Play With Docker:
Learn how to design modular applications.
Explore the .NET Core features.
Learning how to design modular applications will help you become a better engineer. Designing modular applications is the holy grail of software architecture, it is hard to find engineers experienced in designing applications which allows adding new features in a steady speed.
.NET Core brings a sweet development environment, an extensible and cross-platform framework. We will explore the benefits of it in the infrastructure layer and we will reduce its relevance in the application layer. The same rule is applied for modern C# language constructions.
This is continually updated, open source project.
Contributions are welcome!
Learn from the community.
Feel free to submit pull requests to help:
- Fix errors
- Improve sections
- Add new sections
- Submit questions and bugs
- Use Cases
- Flow of Control
- Architecture Styles
- Design Patterns
- Domain-Driven Design Patterns
- Separation of Concerns
- Encapsulation
- Test-Driven Development TDD
- SOLID
- .NET Core Web API
- Entity Framework Core
- Environment Configurations
- DevOps
- Docker
- SQL Server
- Related Content and Projects
ProTip #2: Really interested in designing modular applications? Support this project with a hit on the STAR
button ⭐. Share with a friend!
Use Cases are delivery independent, they show the intent of a system.
Use Cases are algorithms which interpret the input to generate the output data.
Application architecture is about usage, a good architecture screams the business use cases to the developer and framework concerns are implementation details. On Manga sample the user can Register
an account then manage the balance by Deposits
, Withdrawals
and Transfers
.
Following the list of Use Cases:
Use Case | Description |
---|---|
Register | An customer can register an account using his personal details. |
Deposit | The customer can deposit an amount. |
Transfer | The customer can transfer money from one account to another. |
Withdraw | A customer can withdraw money but not more that the current balance. |
Get Customer Details | Get customer details including all related accounts and transactions. |
Get Account Details | Get account details including transactions. |
Close Account | Closes an account, requires balance to be zero. |
The flow of control begins in the controller, moves through the use case, and then winds up executing in the presenter.
- An request in received by the
CustomersController
and an actionPost
is invoked. - The action creates an
RegisterInput
message and theRegister
use case is executed. - The
Register
use case creates aCustomer
and anAccount
. Repositories are called, theRegisterOutput
message is built and sent to theRegisterPresenter
. - The
RegisterPresenter
builds the HTTP Response message. - The
CustomersController
asks the presenter the current response.
- An request in received by the
CustomersController
and an actionGetCustomer
is invoked. - The action creates an
GetCustomerDetailsInput
message and theGetCustomerDetails
use case is executed. - The
GetCustomerDetails
use case asks the repositories about theCustomer
and theAccount
. It could call theNotFound
or theDefault
port of theGetCustomerDetailsPresenter
depending if it exists or not. - The
GetCustomerDetailsPresenter
builds the HTTP Response message. - The
CustomersController
asks the presenter the current response.
Manga uses ideas from popular architectural styles. They Ports and Adapters are the simplest one followed by the others, they complement each other and aim a software made by use cases decoupled from technology implementation details.
The general idea behind Hexagonal architecture style is that the dependencies (Adapters) required by the software to run are used behind an interface (Port).
The software is divided into Application and Infrastructure in which the adapters are interchangeable components developed and tested in isolation. The Application is loosely coupled to the Adapters and their implementation details.
Interfaces like ICustomerRepository
, IOutputPort
and IUnitOfWork
are ports required by the application.
The interface implementations, they are specific to a technology and bring external capabilities. For instance the CustomerRepository
inside the EntityFrameworkDataAccess
folder provides capabilities to consume an SQL Server database.
Primary Actors are usually the user interface or the Test Suit.
The Secondary Actors are usually Databases, Cloud Services or other systems.
Very similar to Ports and Adapters, I would add that data objects cross boundaries as simple data structures. For instance, when the controller execute an use case it passes and immutable Input message. When the use cases calls an Presenter it gives a Output message (Data Transfer Objects if you like).
An application architecture implementation guided by tests cases.
- Value Object
- Entity
- Aggregate Root
- Repository
- Use Case
- Bounded Context
- Entity Factory
- Domain Service
- Application Service
- Single Responsibility Principle
- Open-Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
- Swagger and API Versioning
- Microsoft Extensions
- Feature Flags
- Logging
- Data Annotations
- Authentication
- Authorization