https://github.com/deadislove/dotnet-cleanarchmediatr-template
A modular and scalable .NET template built with Clean Architecture and MediatR. Supports DDD, CQRS, multiple databases, Serilog logging, JWT auth, and unit testing out of the box.
https://github.com/deadislove/dotnet-cleanarchmediatr-template
automapper clean-architecture cqrs-pattern docker docker-compose dotnet fluentvalidation jwt-authentication mediatr mssql postgresql serilog sqlite xunit
Last synced: 3 months ago
JSON representation
A modular and scalable .NET template built with Clean Architecture and MediatR. Supports DDD, CQRS, multiple databases, Serilog logging, JWT auth, and unit testing out of the box.
- Host: GitHub
- URL: https://github.com/deadislove/dotnet-cleanarchmediatr-template
- Owner: deadislove
- License: mit
- Created: 2025-05-30T08:20:14.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-23T00:57:19.000Z (about 1 year ago)
- Last Synced: 2025-06-26T14:05:30.370Z (about 1 year ago)
- Topics: automapper, clean-architecture, cqrs-pattern, docker, docker-compose, dotnet, fluentvalidation, jwt-authentication, mediatr, mssql, postgresql, serilog, sqlite, xunit
- Language: C#
- Homepage:
- Size: 22.6 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# CleanArchMediatR.Template


## Description
A modular .NET template project that implements Clean Architecture and MediatR, designed for scalable, testable, and maintainable enterprise applications. This solution also supports multiple database providers via factory abstraction and integrates JWT-based authentication with clear separation of concerns.
## ๐ Features
- โ
Clean Architecture (Application, Domain, Infra, API, Shared)
- โ
CQRS with MediatR
- โ
FluentValidation for request validation
- โ
Serilog for structured logging
- โ
JWT Authentication
- โ
Modular DB support (MSSQL, PostgreSQL, SQLite via Docker Compose)
- โ
Layered service abstraction (facade, repository, service)
- โ
AutoMapper integration
- โ
Docker-compatible
- โ
xUnit Testing for Handlers
- โ
Custom Middleware for exceptions and meta-filling
## ๐งฑ Folder Highlights
| Folder / Project | Description |
| --------------------------------------------------- | ------------------------------------------------------------------------ |
| `src/CleanArchMediatR.Template.Api` | ASP.NET Core API project, entry point of the application |
| `src/CleanArchMediatR.Template.Application` | Business logic with CQRS (Commands, Queries, Handlers, DTOs, Validators) |
| `src/CleanArchMediatR.Template.Domain` | Domain layer with Entities, Interfaces, Services, and Exceptions |
| `src/CleanArchMediatR.Template.Infra` | Infrastructure logic (EF Core, Jwt, Logging, Repositories) |
| `src/CleanArchMediatR.Template.PersistenceFactory` | Database factory abstraction to support multiple DBs |
| `src/CleanArchMediatR.Template.Shared` | Shared constants and utilities |
| `tests/CleanArchMediatR.Template.Application.Tests` | xUnit tests for application layer |
| `docker-compose.*.yml` | Scripts for launching various databases via Docker |
## ๐งช Running Tests
```bash
cd tests/CleanArchMediatR.Template.Application.Tests
dotnet test
```
## ๐ ๏ธ How to Run
```bash
# Launch database with docker (choose one)
docker-compose -f docker-compose.sqlite.yml up -d
# Build and run API
cd src/CleanArchMediatR.Template.Api
dotnet run
```
## ๐ฆ Prerequisites
- [.NET 9 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)
- [Docker](https://www.docker.com/) (if using provided database images)
## ๐ง Architecture Overview
The solution follows Clean Architecture principles:
```bash
API (Controller)
โโโ Application Layer (Commands, Queries, Handlers)
โโโ Domain Layer (Entities, Interfaces)
โโโ Infrastructure (EFCore, Jwt, Logging)
```
Decoupling is achieved via abstractions and dependency injection. The PersistenceFactory adds flexibility for database provider configuration.
## โ๏ธ Customize the Template
To start your own project based on this template:
```bash
dotnet new install CleanArchMediatR.Template
dotnet new cleanarch-mediatr -n YourProjectName
```
## ๐ Other Notes
- SQLite DB (app.db) is used for lightweight development.
- Logs are saved in logs/ directory.
- HTTP samples can be tested with *.http files in API project.
## Stay in touch
- Author - [Da-Wei Lin](https://www.linkedin.com/in/da-wei-lin-689a35107/)
- Website - [David Weblog](https://davidskyspace.com/)
- [MIT LICENSE](https://github.com/deadislove/dotnet-CleanArchMediatR-template/blob/main/LICENSE.md)