clean-architecture-manga
:cyclone: Clean Architecture with .NET6, C#10 and React+Redux. Use cases as central organizing structure, completely testable, decoupled from frameworks
Top Related Projects
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
Sample ASP.NET Core 8.0 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model. Download the eBook PDF from docs folder.
Web Application ASP.NET 8 using Clean Architecture, DDD, CQRS, Event Sourcing and a lot of good practices
Northwind Traders is a sample application built using ASP.NET Core and Entity Framework Core.
Full Modular Monolith application with Domain-Driven Design approach.
Quick Overview
The clean-architecture-manga repository is a .NET Core implementation of Clean Architecture, showcasing best practices in software design. It demonstrates how to structure a project using Domain-Driven Design (DDD) principles, SOLID principles, and design patterns, providing a practical example of a well-architected application.
Pros
- Implements Clean Architecture principles, promoting separation of concerns and maintainability
- Provides a real-world example of Domain-Driven Design in practice
- Includes comprehensive unit and integration tests, demonstrating good testing practices
- Offers a detailed wiki with explanations of architectural decisions and patterns used
Cons
- May be overly complex for small projects or beginners learning Clean Architecture
- Requires a solid understanding of DDD and SOLID principles to fully appreciate and utilize
- Some developers might find the strict adherence to Clean Architecture principles restrictive
- The project structure might require a learning curve for those unfamiliar with the approach
Code Examples
- Domain Entity Example:
public sealed class Account : IAggregateRoot
{
public Account(AccountId id, CustomerId customerId, Currency currency)
{
Id = id;
CustomerId = customerId;
Currency = currency;
}
public AccountId Id { get; }
public CustomerId CustomerId { get; }
public Currency Currency { get; private set; }
public Credit Credit { get; private set; }
public Debit Debit { get; private set; }
}
This code defines an Account entity with its properties and constructor, following DDD principles.
- Use Case Example:
public sealed class CloseAccount : IUseCase<CloseAccountInput>
{
private readonly IAccountRepository _accountRepository;
private readonly IUnitOfWork _unitOfWork;
public CloseAccount(
IAccountRepository accountRepository,
IUnitOfWork unitOfWork)
{
_accountRepository = accountRepository;
_unitOfWork = unitOfWork;
}
public async Task<bool> Execute(CloseAccountInput input)
{
var account = await _accountRepository.GetAccount(input.AccountId);
if (account == null)
throw new AccountNotFoundException($"The account {input.AccountId} does not exist or is already closed.");
account.Close();
await _accountRepository.Update(account);
await _unitOfWork.Save();
return true;
}
}
This code implements a use case for closing an account, demonstrating the application of Clean Architecture principles.
- Controller Example:
[Route("api/[controller]")]
[ApiController]
public sealed class AccountsController : ControllerBase
{
private readonly ICloseAccount _closeAccountUseCase;
public AccountsController(ICloseAccount closeAccountUseCase)
{
_closeAccountUseCase = closeAccountUseCase;
}
/// <summary>
/// Close an account
/// </summary>
[HttpDelete("{accountId}")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CloseAccountResponse))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> Close([FromRoute][Required] Guid accountId)
{
var output = await _closeAccountUseCase.Execute(
new CloseAccountInput(accountId));
if (output == null)
{
return NotFound();
}
var response = new CloseAccountResponse(
output.AccountId);
return Ok(response);
}
}
This code shows a controller implementation, demonstrating how Clean Architecture separates the presentation layer from the application logic.
Getting Started
To get started with the clean-architecture-manga project:
-
Clone the repository:
git clone https://github.com/ivanpaulovich/clean-architecture-manga.git
-
Navigate to the project directory:
c
Competitor Comparisons
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
Pros of CleanArchitecture
- More comprehensive documentation and explanations of Clean Architecture principles
- Includes a sample API project, showcasing real-world application
- Provides a more structured approach with clear separation of concerns
Cons of CleanArchitecture
- Less focus on Domain-Driven Design (DDD) concepts
- Fewer examples of different architectural patterns and variations
- Less emphasis on CQRS (Command Query Responsibility Segregation) implementation
Code Comparison
CleanArchitecture:
public class DeleteToDoItemCommand : IRequest
{
public int Id { get; set; }
}
public class DeleteToDoItemCommandHandler : IRequestHandler<DeleteToDoItemCommand>
{
private readonly IRepository<ToDoItem> _repository;
public DeleteToDoItemCommandHandler(IRepository<ToDoItem> repository)
{
_repository = repository;
}
}
clean-architecture-manga:
public sealed class CloseAccount : IUseCase
{
private readonly IAccountRepository _accountRepository;
private readonly IUnitOfWork _unitOfWork;
public CloseAccount(
IAccountRepository accountRepository,
IUnitOfWork unitOfWork)
{
_accountRepository = accountRepository;
_unitOfWork = unitOfWork;
}
}
Both repositories demonstrate clean architecture principles, but clean-architecture-manga focuses more on DDD and CQRS patterns, while CleanArchitecture provides a more general implementation of clean architecture concepts.
Sample ASP.NET Core 8.0 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model. Download the eBook PDF from docs folder.
Pros of eShopOnWeb
- More comprehensive e-commerce example with a wider range of features
- Better documentation and explanations of architectural decisions
- Regularly updated and maintained by Microsoft
Cons of eShopOnWeb
- More complex and potentially overwhelming for beginners
- Less focused on demonstrating clean architecture principles
- Heavier reliance on specific technologies and frameworks
Code Comparison
clean-architecture-manga:
public sealed class RegisterCustomerUseCase : IRegisterCustomerUseCase
{
public async Task<RegisterCustomerOutput> Execute(RegisterCustomerInput input)
{
// Implementation
}
}
eShopOnWeb:
public class CatalogService : ICatalogService
{
public async Task<CatalogItem> GetCatalogItemAsync(int id)
{
// Implementation
}
}
The clean-architecture-manga example focuses on use cases and follows a more domain-centric approach, while eShopOnWeb uses services that are more closely tied to the application's specific features. This reflects the different emphasis of each project, with clean-architecture-manga prioritizing clean architecture principles and eShopOnWeb providing a more realistic e-commerce implementation.
Web Application ASP.NET 8 using Clean Architecture, DDD, CQRS, Event Sourcing and a lot of good practices
Pros of EquinoxProject
- More comprehensive project structure with additional features like identity management and API versioning
- Includes a front-end implementation using Angular, providing a full-stack solution
- Offers more extensive documentation and architectural explanations
Cons of EquinoxProject
- Less focus on pure Clean Architecture principles, with some coupling between layers
- More complex setup and configuration, which may be overwhelming for beginners
- Larger codebase with more dependencies, potentially making it harder to maintain
Code Comparison
Clean Architecture Manga:
public sealed class CloseAccount : IUseCase
{
public async Task<Output> Execute(Input input)
{
var account = await _accountRepository.Get(input.AccountId);
account.Close();
await _accountRepository.Update(account);
return new Output(account);
}
}
EquinoxProject:
public class CustomerAppService : ICustomerAppService
{
public async Task<CustomerViewModel> Register(CustomerViewModel customerViewModel)
{
var customer = _mapper.Map<Customer>(customerViewModel);
if (!await _customerRepository.GetByEmail(customer.Email) != null)
return null;
_customerRepository.Add(customer);
return _mapper.Map<CustomerViewModel>(customer);
}
}
The Clean Architecture Manga example demonstrates a more focused use case implementation, while EquinoxProject shows a broader application service with mapping and repository usage.
Northwind Traders is a sample application built using ASP.NET Core and Entity Framework Core.
Pros of NorthwindTraders
- Implements a more comprehensive set of Clean Architecture principles, including CQRS and MediatR
- Provides a more realistic and complex domain model based on the Northwind database
- Includes extensive unit and integration tests, demonstrating best practices in testing
Cons of NorthwindTraders
- May be overwhelming for beginners due to its complexity and extensive use of advanced patterns
- Less focus on DDD (Domain-Driven Design) concepts compared to Clean Architecture Manga
- Requires more setup and configuration to run and understand the project structure
Code Comparison
NorthwindTraders (using MediatR for CQRS):
public class CreateCustomerCommand : IRequest<int>
{
public string Id { get; set; }
public string CompanyName { get; set; }
}
Clean Architecture Manga (using simple command pattern):
public sealed class RegisterCommand : ICommand
{
public string SSN { get; }
public string Name { get; }
public decimal InitialAmount { get; }
}
Both projects demonstrate clean architecture principles, but NorthwindTraders uses more advanced patterns like CQRS with MediatR, while Clean Architecture Manga focuses on simpler implementations of clean architecture concepts. NorthwindTraders offers a more complex and realistic scenario, making it suitable for experienced developers, while Clean Architecture Manga provides a more straightforward approach for those new to clean architecture.
Full Modular Monolith application with Domain-Driven Design approach.
Pros of modular-monolith-with-ddd
- Focuses on Domain-Driven Design (DDD) principles, providing a clear structure for complex business domains
- Demonstrates a modular monolith approach, which can be easier to maintain and deploy than microservices
- Includes comprehensive documentation and architectural decision records (ADRs)
Cons of modular-monolith-with-ddd
- Less emphasis on Clean Architecture patterns compared to clean-architecture-manga
- May be more complex for smaller projects or teams new to DDD concepts
- Limited to .NET Core, while clean-architecture-manga offers examples in multiple languages
Code Comparison
modular-monolith-with-ddd:
public class MeetingGroup : Entity, IAggregateRoot
{
public MeetingGroupId Id { get; private set; }
public string Name { get; private set; }
public string Description { get; private set; }
public MeetingGroupLocation Location { get; private set; }
public MemberId CreatorId { get; private set; }
}
clean-architecture-manga:
public sealed class Account : AggregateRoot
{
public AccountId Id { get; private set; }
public string Name { get; private set; }
public Money Balance { get; private set; }
public DateTime UpdatedAt { get; private set; }
public DateTime CreatedAt { get; private set; }
}
Both examples demonstrate the use of domain entities and aggregate roots, but modular-monolith-with-ddd focuses more on DDD concepts, while clean-architecture-manga emphasizes Clean Architecture principles.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Clean Architecture with .NET Core & React+Redux :cyclone:
Sample implementation of the Clean Architecture Principles with .NET Core. Use cases as central organizing structure, decoupled from frameworks and technology details. Built by small components that are developed and tested in isolation.
We support two versions:
- .NET 6 - .NET 6.
- .NET 5 - .NET 5.
- .NET Core 3.1 - .NET Core 3.1.
Hit the
WATCH
button to get the latest Clean Architecture updates.
Manga is a Virtual Wallet Solution in which the customer register an account then manage the balance by Deposit
, Withdraw
and Transfer
operations.
We also support the React client:
Build & Run
To startup the whole solution, execute the following command:
Windows:
PS cd .docker && ./setup.ps1
MacOS:
$ cd .docker && ./setup.sh
Then the following containers should be running on docker ps
:
Application | URL |
---|---|
NGINX | https://wallet.local:8081 |
Wallet SPA | https://wallet.local:8081 |
Accounts API | https://wallet.local:8081/accounts-api |
Identity Server | https://wallet.local:8081/identity-server |
SQL Server | Server=localhost;User Id=sa;Password=<YourStrong!Passw0rd>;Database=Accounts; |
Browse to https://wallet.local:8081 then click on Log In. If asked trust the self-signed certificate.
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 on 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 importance in the application and domain layers. The same rule is applied for modern C# language syntax.
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.
- Refactoring.
- Build the Front End.
- Submit issues and bugs.
The Discussão em Português is pinned for the large community of brazillian developers.
Index of Clean Architecture Manga
Home
Use Cases
Flow of Control
Architecture Styles
Design Patterns
Domain-Driven Design Patterns
Separation of Concerns
Encapsulation
Test-Driven Development TDD
Fakes
SOLID
- Single Responsibility Principle
- Open-Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
.NET Core Web API
- Swagger and API Versioning
- Microsoft Extensions
- Feature Flags
- Logging
- Data Annotations
- Authentication
- Authorization
Entity Framework Core
Environment Configurations
DevOps
- Running the Application Locally
- Running the Tests Locally
- Continuous Integration & Continuous Deployment
Docker
Related Content and Projects
Contributors â¨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Hit the
FORK
button and show Clean Architecture on your profile.
Top Related Projects
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
Sample ASP.NET Core 8.0 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model. Download the eBook PDF from docs folder.
Web Application ASP.NET 8 using Clean Architecture, DDD, CQRS, Event Sourcing and a lot of good practices
Northwind Traders is a sample application built using ASP.NET Core and Entity Framework Core.
Full Modular Monolith application with Domain-Driven Design approach.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot