Published on

.NET Starter Clean Architecture

Authors

.NET Starter Clean Architecture

This repository contains a starter template for building .NET applications using Clean Architecture, CQRS and Mediator pattern principles. The template is built on .NET Core 7 and can be used as a starting point for building REST APIs.

Getting Started

To get started with the template, you need to clone the repository GitHub and open it in Visual Studio or any other compatible IDE. Change the connection-string. Once you have done that, you can start customizing it to fit your requirements.

Architecture Overview

The architecture of this template follows the Clean Architecture principles. The architecture is divided into four layers:

Presentation/API Layer: This layer is responsible for interacting with the users/client application and sendting the data to them.

Application Layer: This layer contains the business logic of the application. It is responsible for implementing the use cases of the application and coordinating the interaction between the different layers of the architecture.

Domain Layer: This layer contains the domain model of the application. It is responsible for defining the entities, value objects, and business rules of the application.

Infrastructure Layer: This layer is responsible for providing the technical services required by the application such as email, sms, caching, logging, and messaging.

Persistence Layer: This layer is responsible for all database operation.

Technologies Used

The template uses the following technologies:

  • .NET 7: This is the framework used to build the application.

  • Entity Framework Core: This is used to implement data access in the application.

  • AutoMapper: This is used to map the entities between different layers of the application.

  • FluentValidation: This is used to validate the input data in the application.

  • MediatR: This is used to implement the mediator pattern between the different layers of the application.

Functionality

  • Login, Register, Refresh Token, Verify Email, Facebook Login
  • JWT Token Authentication
  • Role,Policy Based Authentication
  • Swagger Documentation
  • API Versioning
  • Rate Limiting
  • Data Seeding
  • Pagination Setup
  • Examples
  • SendGrid Email Service
  • Cloudinary Service
  • etc.

Contributing

Contributions to the project are welcome. If you find a bug or want to suggest an improvement, you can create an issue or submit a pull request.

License

The project is licensed under the MIT license.

What is Clean Architecture?

Clean architecture is an architectural style that aims to separate the concerns of different layers of an application. The main idea is to make the inner layers independent of the outer layers, so that they can be changed or replaced without affecting each other. The inner layers contain the core business logic and domain models, while the outer layers handle the infrastructure, presentation and communication aspects.

One of the benefits of clean architecture is that it makes the application easier to test, as you can isolate the core logic from the external dependencies. Another benefit is that it makes the application more adaptable to changing requirements, as you can swap out different implementations of the outer layers without touching the inner layers.

What is CQRS?

CQRS stands for Command Query Responsibility Segregation. It is a pattern that separates the read and write operations of an application. The idea is to have different models for querying and updating data, and different handlers for processing them.

One of the benefits of CQRS is that it simplifies the design and implementation of each model and handler, as they have a single responsibility. Another benefit is that it improves the performance and scalability of the application, as you can optimize each model and handler for their specific needs, and use different storage and caching strategies for them.

What is Mediator Pattern?

Mediator pattern is a behavioral pattern that defines an object that encapsulates how a set of objects interact. It promotes loose coupling by keeping objects from referring to each other explicitly, and lets you vary their interaction independently.

One of the benefits of mediator pattern is that it reduces the complexity and dependencies of the communication between objects, as they only need to know about the mediator. Another benefit is that it makes the code more reusable and extensible, as you can introduce new objects and interactions without changing the existing ones.