/clean-architecture-api-template

ASP.NET Core backend template with Clean Architecture, DDD, and CQRS principles. Features modular design, JWT-based authentication, MediatR for request handling, and Specification pattern for flexible querying. Prioritizes clean code, scalability, and comprehensive testing for maintainable and efficient development.

Primary LanguageC#MIT LicenseMIT

Clean Architecture Template

.NET Version GitHub Workflow Status License

A .NET project template implementing Clean Architecture, focusing on DDD principles, unit testing, and RESTful API design. This template uses 5 layers to ensure modularity and separation of concerns, and it supports token-based authentication.


πŸ—‚ Project Structure

  • src/
    • Api - Controllers and API configuration (e.g., Swagger, API responses)
    • Application - Application layer with CQRS, MediatR handlers, DTOs, and commands/queries.
    • Domain - Domain models, entities, and core business logic.
    • Infrastructure - Database configuration, data access, and external services.
    • SharedKernel - Common types, constants, and cross-cutting concerns.
    • Host - Application setup and main entry point (Program.cs and configuration).
  • tests/
    • Separate unit tests for each layer to ensure isolation and robustness.

πŸš€ Getting Started

  1. Clone the repository:

    git clone https://github.com/YourUsername/CleanArchitecture.Template.git
  2. Navigate to the source directory:

    cd src
  3. Restore dependencies:

    dotnet restore
  4. Build the solution:

    dotnet build
  5. Run the project:

    dotnet run --project CleanArchitecture.Template.Host

πŸ”§ Configuration

  • Environment Variables: Set up necessary environment variables, like database connections and JWT keys.
  • Docker Support: Optionally, run the project using Docker.

πŸ“œ Documentation

πŸ“ docs/ Folder

Comprehensive documentation is located in the docs/ folder, structured as follows:

  • features/authentication - Detailed markdown documentation for authentication, login, and token refresh flows.
  • postman - Pre-configured Postman collection for testing endpoints.
  • setup - Guide to run migrations using Entity Framework Core, ensuring seamless database setup.

πŸ§ͺ Testing

  1. Run Unit Tests:

    dotnet test
  2. Continuous Integration: GitHub Actions are set up to automatically run tests on each push to main and develop branches, ensuring that new changes don’t break existing functionality.


πŸ›  Tooling

  • Swagger: API documentation available at /swagger when running the project.
  • Postman Collection: Available in docs/postman to test API endpoints for authentication, user management, and health checks.

πŸ’» CI/CD Pipeline

The project uses GitHub Actions for CI/CD, with the following workflow:

  • .NET Build & Test: Runs on each push to main and develop, performing restore, build, and test operations.

πŸ›  Key Features

  • Modular Architecture: Divides responsibilities across API, Application, Domain, Infrastructure, SharedKernel, and Host layers.
  • Authentication & Authorization: JWT-based token authentication with refresh token mechanism.
  • Documentation: Detailed feature documentation and Postman collection to ease testing and integration.
  • Docker Support: Optionally run the project in Docker for a standardized environment.

πŸ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.


Happy coding! πŸŽ‰