Skip to content

deadislove/dotnet-CleanArchMediatR-template

Repository files navigation

CleanArchMediatR.Template

Visitors Clones

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

📚 Documentation

For more detailed information about the design and usage of this template, please refer to:

🧱 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

cd tests/CleanArchMediatR.Template.Application.Tests
dotnet test

# Show detail infromation.
dotnet test --logger "console;verbosity=detailed"

🛠️ How to Run

# 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

🧠 Architecture Overview

The solution follows Clean Architecture principles:

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:

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

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors