An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# CleanArchMediatR.Template

![Visitors](https://img.shields.io/badge/visitors-null_total-brightgreen)
![Clones](https://img.shields.io/badge/clones-null_total_null_unique-blue)

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

Buy Me a Coffee at ko-fi.com

## ๐Ÿš€ 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)