Skip to content
Ivan Paulovich edited this page Dec 3, 2019 · 13 revisions

Manga: The Clean Architecture Sample Implementation with .NET Core 🌀

All Contributors Build Status

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! Swagger Demo

Run the Docker container in less than 2 minutes using Play With Docker:

Try in PWD

Motivation

Learn how to design modular applications.

Explore the .NET Core features.

Learn how to design modular applications

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.

Explore the .NET Core features

.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.

Learn from the open source community

This is continually updated, open source project.

Contributions are welcome!

Contributing

Learn from the community.

Feel free to submit pull requests to help:

  • Fix errors
  • Improve sections
  • Add new sections
  • Submit questions and bugs

Index of Clean Architecture Manga

ProTip #2: Really interested in designing modular applications? Support this project with a hit on the STAR button ⭐. Share with a friend!

Use Cases

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.

Clean

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.

Flow of Control

The flow of control begins in the controller, moves through the use case, and then winds up executing in the presenter.

Register Flow of Control

  1. An request in received by the CustomersController and an action Post is invoked.
  2. The action creates an RegisterInput message and the Register use case is executed.
  3. The Register use case creates a Customer and an Account. Repositories are called, the RegisterOutput message is built and sent to the RegisterPresenter.
  4. The RegisterPresenter builds the HTTP Response message.
  5. The CustomersController asks the presenter the current response.

Register Flow of Control

Get Customer Details Flow of Control

  1. An request in received by the CustomersController and an action GetCustomer is invoked.
  2. The action creates an GetCustomerDetailsInput message and the GetCustomerDetails use case is executed.
  3. The GetCustomerDetails use case asks the repositories about the Customer and the Account. It could call the NotFound or the Default port of the GetCustomerDetailsPresenter depending if it exists or not.
  4. The GetCustomerDetailsPresenter builds the HTTP Response message.
  5. The CustomersController asks the presenter the current response.

Architecture Styles

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.

Hexagonal Architecture Style

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.

Ports

Interfaces like ICustomerRepository, IOutputPort and IUnitOfWork are ports required by the application.

Adapters

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.

Ports and Adapters

The Left Side

Primary Actors are usually the user interface or the Test Suit.

The Right Side

The Secondary Actors are usually Databases, Cloud Services or other systems.

Onion Architecture Style

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).

Clean Architecture Style

An application architecture implementation guided by tests cases.

Design Patterns

Domain-Driven Design Patterns

Separation of Concerns

Encapsulation

Test-Driven Development (TDD)

Fakes

SOLID

.NET Core Web API

Entity Framework Core

DevOps

Docker

Related Content and Projects

Clone this wiki locally