Skip to content

hammond01/CleanArchitecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

368 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Clean Architecture with Domain-Driven Design (DDD)

.NET Version License Clean Architecture DDD CQRS Build Status Completion

A comprehensive implementation of Clean Architecture combined with Domain-Driven Design (DDD) using .NET 8. This v1.0.0 release showcases a production-ready Modular Monolith architecture with Custom CQRS Dispatcher, Central Package Management, and DbMigrator tooling for enterprise applications.

Clean Architecture with DDD

(Open on draw.io)

๐Ÿ“‹ Table of Contents

๐Ÿš€ Overview

This project is a comprehensive implementation of Clean Architecture combined with Domain-Driven Design (DDD) using .NET 8.

v1.0.0 represents a production-ready foundation featuring:

  • Modular Monolith Architecture - 3 business modules (Identity, Catalog, Auditing) with isolated schemas
  • Custom CQRS Dispatcher - Unique implementation replacing MediatR with automatic validation and performance monitoring
  • DbMigrator Tool - Production-ready database migration orchestrator for CI/CD pipelines
  • Central Package Management - Unified dependency versioning across 18 projects
  • 19 Working API Endpoints - Fully functional REST APIs with Swagger documentation

The implementation showcases enterprise architecture principles with patterns like CQRS, Repository Pattern, Unit of Work, Specification Pattern, Domain Events, and Modular Monolith design.

๐Ÿ“… Current Status (February 2026) - v1.0.0 Released:

  • โœ… Custom CQRS Dispatcher: Complete replacement of MediatR - automatic validation, performance monitoring, structured logging with emojis (๐Ÿ”โšก๐Ÿ“ข)
  • โœ… DbMigrator Tool: Multi-DbContext orchestration, health checks, idempotent execution, Serilog logging
  • โœ… Central Package Management: Directory.Packages.props managing all 18 projects
  • โœ… 3 Business Modules: Identity (8 endpoints), Catalog (11 endpoints), Auditing (1 endpoint)
  • โœ… BuildingBlocks: 5 shared projects providing domain base classes, CQRS infrastructure, API components
  • ๐Ÿ”„ Completion: ~75% - Production foundation complete, testing infrastructure and advanced auth workflows planned for v1.1.0

โœจ Key Highlights

  • ๐Ÿ—๏ธ Clean Architecture: Clear separation of layers and dependencies with modular monolith structure
  • ๐ŸŽฏ Custom Dispatcher: Unique CQRS implementation with built-in validation, logging, and performance monitoring (replaces MediatR)
  • ๐Ÿ”„ CQRS Pattern: Complete Command Query Responsibility Segregation with automatic handler registration
  • ๐Ÿ—„๏ธ DbMigrator: Professional database migration tool orchestrating multiple DbContexts with health checks
  • ๐Ÿ“ฆ Central Package Management: Unified dependency versioning via Directory.Packages.props
  • ๐ŸŽฏ Domain-Driven Design: Focus on business logic and domain model
  • ๏ฟฝ Repository & Unit of Work: Enterprise-grade data access patterns with Specification Pattern
  • ๐Ÿ“Š 19 Working API Endpoints: Identity (8), Catalog (11), Auditing (1)
  • ๐Ÿ”’ Security Foundation: JWT authentication infrastructure, CORS configuration
  • ๐Ÿ“ Interactive Swagger UI: Comprehensive API documentation with live testing
  • ๐Ÿš€ Production Tooling: DbMigrator for CI/CD, structured logging with Serilog

๐Ÿ›๏ธ Architecture Overview

This repository demonstrates Clean Architecture principles by Uncle Bob implemented across different architectural patterns. Currently, it includes:

๐ŸŽฏ Current Implementation: Monolithic Architecture

A complete monolithic application following Clean Architecture with 4 main layers:

1. Domain Layer (Core)

  • Entities: Core business objects
  • Value Objects: Immutable objects
  • Domain Events: Business events
  • Repository Interfaces: Data access contracts
  • Domain Services: Business logic services

2. Application Layer

  • Use Cases: Application business rules
  • Commands & Queries: CQRS implementation
  • Handlers: Command/Query handlers
  • DTOs: Data transfer objects
  • Validators: Input validation
  • Mappers: Object mapping

3. Infrastructure Layer

  • Persistence: Entity Framework Core implementation
  • External Services: Third-party integrations
  • Caching: In-memory and distributed caching
  • Logging: Structured logging with Serilog
  • Authentication: Identity management
  • Configuration: Application settings

4. Presentation Layer

  • Web API: RESTful APIs with ASP.NET Core
  • Controllers: API endpoints
  • Middleware: Request/Response pipeline
  • API Documentation: Swagger/OpenAPI integration

๐Ÿš€ Future Implementations

  • Microservices Architecture - Distributed services with API Gateway (Partially Implemented)
  • Event-Driven Architecture - Message-driven communication (Planned)
  • CQRS with Event Sourcing - Advanced CQRS implementation (Planned)
  • Serverless Architecture - Cloud-native serverless approach (Planned)

๐Ÿ“ Project Structure

CleanArchitecture/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ BuildingBlocks/                    # ๐Ÿงฑ Shared Building Blocks
โ”‚   โ”‚   โ”œโ”€โ”€ BuildingBlocks.Domain/         # Base entities, domain events
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Entities/                  # Entity.cs, IHasKey, ITrackable
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Events/                    # IDomainEvent
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Repositories/              # IRepository, IUnitOfWork
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Specifications/            # Specification Pattern
โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ BuildingBlocks.Application/    # ๐ŸŽฏ Custom Dispatcher & CQRS
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ CQRS/                      # ICommand, IQuery, ICommandHandler, IQueryHandler
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Dispatcher/                # โญ Custom Dispatcher (v1.0)
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ IDispatcher.cs         # Main dispatcher interface
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Dispatcher.cs          # Implementation with validation
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ IDomainEventHandler.cs # Domain event handler
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ DTOs/                      # BaseDto
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Results/                   # Result pattern
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Validation/                # IValidator interface
โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ BuildingBlocks.Infrastructure/ # Common infrastructure
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Persistence/               # Base repositories
โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ BuildingBlocks.Api/            # API base components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Controllers/               # BaseController
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Filters/                   # ApiExceptionFilter
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Responses/                 # ApiResponse
โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ BuildingBlocks.Shared/         # Shared utilities
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ Modules/                           # ๐Ÿ“ฆ Business Modules
โ”‚   โ”‚   โ”œโ”€โ”€ Identity/                      # ๐Ÿ‘ค Authentication & User Management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Identity.Domain/           # User, Role entities
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Identity.Application/      # 8 Command/Query handlers
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Commands/              # Register, Login, ConfirmEmail, etc.
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Queries/               # GetUser, ValidateToken
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Identity.Infrastructure/   # EF Core, IdentityDbContext
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Data/                  # DbContext, Migrations
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Repositories/          # User repositories
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Identity.Api/              # 8 API endpoints
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ Controllers/           # AuthenticationController
โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ Catalog/                       # ๐Ÿ“ฆ Product & Category Management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Catalog.Domain/            # Product, Category entities
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Entities/              # Domain models
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Repositories/          # Repository interfaces
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Catalog.Application/       # CQRS handlers & Specifications
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Features/
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Products/          # Product commands & queries
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Categories/        # Category commands & queries
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Specifications/        # LowStockProducts, ProductsByPrice, etc.
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Catalog.Infrastructure/    # EF Core, CatalogDbContext
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Data/                  # DbContext, Migrations
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Repositories/          # Repository implementations
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Catalog.Api/               # 11 API endpoints
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ Controllers/           # ProductsController, CategoriesController
โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ Auditing/                      # ๐Ÿ“ Audit Logging
โ”‚   โ”‚       โ”œโ”€โ”€ Auditing.Domain/           # AuditLog entity
โ”‚   โ”‚       โ”œโ”€โ”€ Auditing.Application/      # Audit query handlers
โ”‚   โ”‚       โ”œโ”€โ”€ Auditing.Infrastructure/   # AuditingDbContext
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ Data/                  # Separate audit schema
โ”‚   โ”‚       โ””โ”€โ”€ Auditing.Api/              # 1 API endpoint
โ”‚   โ”‚           โ””โ”€โ”€ Controllers/           # AuditLogsController
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ DbMigrator/                        # ๐Ÿ—„๏ธ Database Migration Tool
โ”‚   โ”‚   โ”œโ”€โ”€ DbMigrationService.cs          # Orchestrates 3 DbContexts
โ”‚   โ”‚   โ”œโ”€โ”€ MigrationSettings.cs           # Configuration model
โ”‚   โ”‚   โ”œโ”€โ”€ Program.cs                     # Console app entry point
โ”‚   โ”‚   โ”œโ”€โ”€ appsettings.json               # Migration settings
โ”‚   โ”‚   โ”œโ”€โ”€ README.md                      # Migration guide
โ”‚   โ”‚   โ””โ”€โ”€ DbMigrator.csproj
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ CleanArchitecture.Api/             # ๐Ÿš€ Main API Gateway
โ”‚       โ”œโ”€โ”€ Extensions/                    # Module registration
โ”‚       โ”‚   โ”œโ”€โ”€ IdentityModuleExtensions.cs
โ”‚       โ”‚   โ”œโ”€โ”€ CatalogModuleExtensions.cs
โ”‚       โ”‚   โ””โ”€โ”€ AuditingModuleExtensions.cs
โ”‚       โ”œโ”€โ”€ Program.cs                     # Application entry point
โ”‚       โ”œโ”€โ”€ appsettings.json               # Configuration
โ”‚       โ””โ”€โ”€ CleanArchitecture.Api.csproj
โ”‚
โ”œโ”€โ”€ docs/                                  # ๐Ÿ“š Documentation
โ”‚   โ””โ”€โ”€ imgs/
โ”‚       โ””โ”€โ”€ CleanArchitecture-DDD.png
โ”‚
โ”œโ”€โ”€ Directory.Packages.props               # ๐Ÿ“ฆ Central package management
โ”œโ”€โ”€ CHANGELOG.md                           # Version history
โ”œโ”€โ”€ RELEASE_NOTES_v1.0.0.md               # v1.0.0 release notes
โ”œโ”€โ”€ QUICK_START_v1.0.0.md                 # Quick start guide
โ”œโ”€โ”€ ARCHITECTURE.md                        # Architecture documentation
โ””โ”€โ”€ README.md                              # This file

๐ŸŽฏ Architecture Highlights

Modular Monolith with Clean Architecture (v1.0.0):

  • 18 Projects total across BuildingBlocks, Modules, DbMigrator, and API
  • 3 Business Modules (Identity, Catalog, Auditing) with separate schemas
  • Custom Dispatcher replacing MediatR for unique identity
  • Central Package Management for unified versioning
  • Production Tooling with DbMigrator for CI/CD pipelines

๐Ÿ› ๏ธ Technologies Used

Backend Technologies

  • .NET 8 - Latest .NET framework
  • ASP.NET Core - Web framework
  • Entity Framework Core 8.0.10 - ORM
  • Custom Dispatcher - CQRS implementation (replaces MediatR)
  • FluentValidation 11.9.0 - Input validation
  • Serilog 4.2.0 - Structured logging
  • Mapster - Object mapping
  • Swagger/Swashbuckle 7.0.0 - API documentation

Database & Caching

  • SQL Server - Primary database
  • In-Memory Database - Testing
  • IMemoryCache - In-memory caching
  • Redis (Optional) - Distributed caching

DevOps & Tools

  • Docker - Containerization
  • docker-compose - Multi-container deployment
  • xUnit - Testing framework
  • Moq - Mocking framework
  • GitHub Actions - CI/CD pipeline

๐ŸŽฏ Key Features

๐Ÿ›๏ธ Modular Monolith Architecture (v1.0.0 - Production Foundation)

Business Modules (3 Modules Implemented)

  • โœ… Identity Module - Authentication & User Management (8 API endpoints)

    • User registration and login
    • JWT token generation & refresh token support
    • Email confirmation workflow
    • Password reset functionality
    • Full CQRS implementation with Custom Dispatcher
  • โœ… Catalog Module - Product & Category Management (11 API endpoints)

    • Product CRUD with category relationships
    • Category management with hierarchical support
    • CSV export functionality
    • Specification Pattern for complex queries
    • Full CQRS implementation with Custom Dispatcher
  • โœ… Auditing Module - Audit Logging (1 API endpoint)

    • Centralized audit log storage
    • Query with pagination support
    • Separate database schema for isolation

Enterprise Technical Features Implemented

  • ๐Ÿ” Authentication & Authorization - Complete JWT-based security

    • User login and registration with Identity framework
    • Refresh token support
    • Role-based authorization ready
    • Password validation and security
  • ๐Ÿ›ก๏ธ Security Middleware - 8 middleware components:

    • GlobalExceptionHandlerMiddleware - Centralized exception handling
    • ApiRequestLoggingMiddleware - Request/response logging
    • RateLimitingMiddleware - Request throttling (100 req/min default)
    • AutoEntityLockMiddleware - Automatic entity locking
    • ActionLoggingFilter - Action-level logging
    • LoggingStatusCodeMiddleware - Status code logging
    • CORS Configuration - Environment-specific policies
    • Response Compression - Gzip and Brotli support
  • ๏ฟฝ API Features:

    • API Versioning (v1.0, v2.0) with Asp.Versioning
    • OData support for advanced querying
    • Swagger/OpenAPI with enhanced UI
    • Health checks (Database & Application)
    • XML documentation support
  • ๐Ÿ—„๏ธ Data Access:

    • Entity Framework Core with SQL Server
    • Repository pattern implementation
    • Unit of Work pattern
    • Generic repository with CRUD operations
    • Audit logging and entity tracking
  • ๏ฟฝ Logging & Monitoring:

    • Serilog for structured logging
    • File and console logging
    • Request/response logging
    • Performance monitoring
    • Audit log entries tracking
  • ๐Ÿงช Testing Infrastructure (17 test files):

    • Product Tests (6 files): AddOrUpdate, Delete, GetById, Gets, CommandQuery, FeatureSummary
    • Category Tests (6 files): AddOrUpdate, Delete, GetById, Gets, CommandQuery, FeatureSummary
    • Integration Tests (5 files): Category, Product, Health, Identity, Logs Controllers

๐ŸŽฏ Custom Dispatcher System (v1.0.0 - Unique Identity)

Core Features

  • ๐ŸŽฏ IDispatcher Interface - Main dispatcher with Query, Command, and DomainEvent methods

    • Generic Query for read operations
    • Generic Command for write operations
    • PublishDomainEvent for domain events
  • โšก Automatic Validation - FluentValidation integration in pipeline:

    • Validates all commands and queries before execution
    • Returns detailed validation errors
    • No need for manual validation in handlers
  • ๐Ÿ“Š Performance Monitoring - Built-in Stopwatch:

    • Measures execution time for all operations
    • Structured logging with performance metrics
    • Helps identify slow queries/commands
  • ๐Ÿ“ข Structured Logging - Emoji-based log indicators:

    • ๐Ÿ” Query execution logs
    • โšก Command execution logs
    • ๐Ÿ“ข Domain event publication logs
    • Detailed error logging with stack traces
  • ๐Ÿ”ง Automatic Handler Registration - Reflection-based discovery:

    • AddHandlersFromAssembly() extension method
    • Registers all ICommandHandler<,> and IQueryHandler<,>
    • Registers all IDomainEventHandler<> implementations
    • No manual registration needed

๐Ÿ—„๏ธ DbMigrator Tool (Production-Ready)

Features

  • ๐Ÿ“ฆ Multi-DbContext Support - Orchestrates 3 separate contexts:

    • IdentityDbContext (identity schema)
    • CatalogDbContext (catalog schema)
    • AuditingDbContext (auditing schema)
  • ๐Ÿฅ Health Checks - Pre-migration validation:

    • Database connectivity tests
    • Schema existence verification
    • Detailed error reporting
  • ๐Ÿ“ Structured Logging - Serilog integration:

    • Console output with color-coded levels
    • File logging (logs/dbmigrator-.txt)
    • Detailed migration progress tracking
  • ๐Ÿ”„ Idempotent Execution - Safe to run multiple times:

    • Applies only pending migrations
    • Skips already-applied migrations
    • Transaction support
  • ๐Ÿš€ CI/CD Ready - Production deployment support:

    • Exit codes for automation (0=success, 1=failure)
    • Configuration via appsettings.json
    • Seed data infrastructure ready

๐Ÿ“ฆ Central Package Management

  • Directory.Packages.props - Single source of truth for all package versions
  • ManagePackageVersionsCentrally - Enabled across all 18 projects
  • Organized Groups - Core, EF Core, ASP.NET, Serilog, Testing, Tools
  • Version Consistency - No version conflicts between projects

๐Ÿš€ Getting Started

๐Ÿ“‹ Prerequisites

  • .NET 8 SDK - Download
  • SQL Server or SQL Server Express - Download
  • Visual Studio 2022 or VS Code with C# extension
  • Git for version control

๐ŸŽฏ Quick Start (v1.0.0)

# Clone the repository
git clone https://github.com/hammond01/CleanArchitecture.git
cd CleanArchitecture

# Update connection string in appsettings.json
# Edit: src/CleanArchitecture.Api/appsettings.json
# ConnectionStrings:DefaultConnection = "Server=YOUR_SERVER;..."

# Run database migrations
dotnet run --project src/DbMigrator

# Or migrate manually for each module:
dotnet ef database update --project src/Modules/Identity/Identity.Infrastructure --startup-project src/CleanArchitecture.Api --context IdentityDbContext
dotnet ef database update --project src/Modules/Catalog/Catalog.Infrastructure --startup-project src/CleanArchitecture.Api --context CatalogDbContext
dotnet ef database update --project src/Modules/Auditing/Auditing.Infrastructure --startup-project src/CleanArchitecture.Api --context AuditingDbContext

# Run the API
dotnet run --project src/CleanArchitecture.Api

# Access Swagger UI
# Open: http://localhost:5000/swagger

๐Ÿ“š Documentation Links

๐Ÿ“‹ System Requirements

All implementations share these common requirements:

  • .NET 8 SDK or later
  • Visual Studio 2022 or VS Code with C# extension
  • SQL Server or SQL Server Express (for database)
  • Git for version control
  • Docker (optional, for containerized deployments)
  • Postman or similar (for API testing)

๏ฟฝ API Endpoints (19 Total)

Identity Module (8 endpoints):

  • POST /api/authentication/register - User registration
  • POST /api/authentication/login - User login
  • POST /api/authentication/refresh-token - Refresh JWT token
  • POST /api/authentication/confirm-email - Email confirmation
  • POST /api/authentication/forgot-password - Initiate password reset
  • POST /api/authentication/reset-password - Complete password reset
  • GET /api/authentication/user - Get user profile
  • POST /api/authentication/logout - User logout

Catalog Module (11 endpoints):

  • GET /api/products - List all products
  • GET /api/products/{id} - Get product by ID
  • POST /api/products - Create product
  • PUT /api/products/{id} - Update product
  • DELETE /api/products/{id} - Delete product
  • GET /api/products/export - Export products to CSV
  • GET /api/categories - List all categories
  • GET /api/categories/{id} - Get category by ID
  • POST /api/categories - Create category
  • PUT /api/categories/{id} - Update category
  • DELETE /api/categories/{id} - Delete category

Auditing Module (1 endpoint):

  • GET /api/auditlogs - Query audit logs with pagination

๐Ÿ‘จโ€๐Ÿ’ป Development Guide

Adding New Module

  1. Create Module Structure in src/Modules/YourModule/

    YourModule/
    โ”œโ”€โ”€ YourModule.Domain/
    โ”œโ”€โ”€ YourModule.Application/
    โ”œโ”€โ”€ YourModule.Infrastructure/
    โ””โ”€โ”€ YourModule.Api/
    
  2. Create Domain Entities in YourModule.Domain/Entities/

    • Inherit from Entity base class from BuildingBlocks.Domain
    • Implement business rules and domain events
  3. Create Repository Interfaces in YourModule.Domain/Repositories/

    • Inherit from IRepository<T> from BuildingBlocks.Domain
  4. Create Commands/Queries in YourModule.Application/Features/

    • Commands implement ICommand<TResponse>
    • Queries implement IQuery<TResponse>
    • Add FluentValidation validators
  5. Create Handlers in YourModule.Application/Features/

    • Command handlers implement ICommandHandler<TCommand, TResponse>
    • Query handlers implement IQueryHandler<TQuery, TResponse>
    • Use Custom Dispatcher (no MediatR!)
  6. Implement Infrastructure in YourModule.Infrastructure/

    • Create DbContext inheriting from DbContext
    • Implement repositories
    • Add migrations: dotnet ef migrations add InitialCreate
  7. Create API Controllers in YourModule.Api/Controllers/

    • Inject IDispatcher from BuildingBlocks.Application
    • Use dispatcher.Query() or dispatcher.Command()
  8. Register Module in src/CleanArchitecture.Api/Extensions/

    • Create YourModuleExtensions.cs
    • Register DbContext, repositories, and handlers
    • Call services.AddHandlersFromAssembly(typeof(YourHandler).Assembly)

Adding New Entity to Existing Module

  1. Create Domain Entity in ModuleName.Domain/Entities/
  2. Create Repository Interface in ModuleName.Domain/Repositories/
  3. Implement Repository in ModuleName.Infrastructure/Repositories/
  4. Create Commands/Queries in ModuleName.Application/Features/EntityName/
  5. Create Handlers for Commands/Queries (use IDispatcher)
  6. Update DbContext to include new DbSet<Entity>
  7. Create Migration: dotnet ef migrations add AddEntityName
  8. Create Controller in ModuleName.Api/Controllers/
  9. Write Tests (if test infrastructure exists)

Code Standards

  • Use C# naming conventions
  • Follow Clean Code principles
  • Implement proper error handling
  • Add comprehensive logging (use Serilog)
  • Use Custom Dispatcher (not MediatR)
  • Write FluentValidation validators for all commands/queries
  • Document public APIs with XML comments
  • Follow Modular Monolith principles - keep modules isolated

๐Ÿงช Testing

โš ๏ธ Note: Testing infrastructure is currently in planning phase for v1.0.0. The focus has been on building solid foundation with Custom Dispatcher, DbMigrator, and core business modules.

๐Ÿ”ฎ Planned Testing Strategy (v1.1.0+)

Unit Testing (Planned):

  • Test Custom Dispatcher with mock handlers
  • Test CQRS handlers in isolation
  • Test domain entities and business rules
  • Test FluentValidation validators
  • Test Specification Pattern implementations

Integration Testing (Planned):

  • Test API endpoints end-to-end
  • Test database operations with TestContainers
  • Test Custom Dispatcher with real handlers
  • Test module integration

Test Infrastructure (To Be Implemented):

  • xUnit - Testing framework
  • Moq or NSubstitute - Mocking framework
  • FluentAssertions - Assertion library
  • Testcontainers - Docker-based integration tests
  • WebApplicationFactory - API integration tests

๐Ÿ”ง Running Tests (Future)

# Run all tests
dotnet test

# Run with detailed output
dotnet test --verbosity normal

# Run with coverage report
dotnet test --collect:"XPlat Code Coverage"

# Run specific module tests
dotnet test --filter "FullyQualifiedName~Catalog"

๐Ÿ“‹ Test Coverage Goals (v1.1.0)

  • Unit Tests: 80%+ code coverage
  • Integration Tests: All API endpoints
  • E2E Tests: Critical user flows
  • Performance Tests: DbMigrator and Dispatcher benchmarks

๐Ÿ“š Documentation

๐Ÿค Contributing

We welcome all contributions! Please read our Contributing Guidelines for details.

How to contribute:

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

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

๐Ÿ™ Acknowledgments

๐Ÿ“ž Contact

๐ŸŽฏ Project Roadmap

v1.0.0 (February 2026) - โœ… RELEASED:

  • โœ… Custom CQRS Dispatcher replacing MediatR
  • โœ… DbMigrator production tool
  • โœ… Central Package Management
  • โœ… 3 business modules (Identity, Catalog, Auditing)
  • โœ… 19 working API endpoints
  • โœ… Complete documentation (CHANGELOG, RELEASE_NOTES, QUICK_START)

v1.1.0 (Q2 2026) - ๐Ÿšง Planned:

  • ๐Ÿ”„ Complete authentication workflows (email verification, password reset)
  • ๐Ÿ”„ Comprehensive testing infrastructure (Unit + Integration tests)
  • ๐Ÿ”„ API health checks and monitoring endpoints
  • ๐Ÿ”„ Docker Compose for complete environment
  • ๐Ÿ”„ CI/CD pipeline with GitHub Actions

v1.2.0 (Q3 2026) - ๐Ÿ“‹ Planned:

  • ๐Ÿ“‹ Additional business modules (Orders, Inventory, Customers)
  • ๐Ÿ“‹ Advanced querying with Specification Pattern expansion
  • ๐Ÿ“‹ Caching layer (Redis integration)
  • ๐Ÿ“‹ Background job processing
  • ๐Ÿ“‹ API rate limiting and throttling

v2.0.0 (Q4 2026) - ๐Ÿ’ก Future:

  • ๐Ÿ’ก Event Sourcing implementation
  • ๐Ÿ’ก CQRS with separate read/write databases
  • ๐Ÿ’ก Real-time features with SignalR
  • ๐Ÿ’ก Advanced security (OAuth2, OpenID Connect)
  • ๐Ÿ’ก Multi-tenancy support

๐Ÿ”„ Architecture Journey

This project demonstrates Modular Monolith architecture with a clear path to distributed systems:

  1. โœ… Modular Monolith Foundation (v1.0.0 - Current)

    • 3 business modules with separate schemas
    • Custom Dispatcher for CQRS
    • Production tooling (DbMigrator)
    • Clean Architecture with DDD principles
  2. ๐Ÿ”„ Enhanced Modular Monolith (v1.x Future)

    • Additional business modules
    • Complete testing coverage
    • Advanced observability
    • Performance optimizations
  3. ๐Ÿ’ก Future Evolution Options (v2.0+)

    • Option A: Event-Driven Modular Monolith (event sourcing within modules)
    • Option B: Microservices decomposition (when scaling demands require it)
    • Option C: Hybrid approach (some modules as microservices)

๐Ÿ“Š Current Implementation Status (v1.0.0)

Component Status Progress Details
Custom Dispatcher โœ… Complete 100% CQRS, Validation, Logging, Perf Monitoring
DbMigrator โœ… Complete 100% Multi-DbContext, Health Checks, CI/CD
Central Packages โœ… Complete 100% 18 projects, unified versioning
Identity Module ๐ŸŸก Partial 70% 8 endpoints, workflows need completion
Catalog Module โœ… Complete 100% 11 endpoints, full CRUD + Specifications
Auditing Module โœ… Complete 100% 1 endpoint, separate schema
Testing ๐Ÿ”ด Planned 0% Infrastructure planned for v1.1.0
Documentation โœ… Complete 100% README, CHANGELOG, RELEASE_NOTES, QUICK_START
Overall Project ๐ŸŸก v1.0.0 75% Production foundation ready

โญ If this project helped you learn Clean Architecture and modern .NET development, please give it a star! โญ

๐Ÿš€ Follow the project for updates on new architecture implementations! ๐Ÿš€

About

๐Ÿ—๏ธ Production-ready .NET 8 Clean Architecture monolith with DDD, CQRS, and enterprise APIs. Comprehensive product management system with advanced security, testing, and scalability features, ...

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages