A comprehensive implementation of Clean Architecture combined with Domain-Driven Design (DDD) using .NET 8. This project demonstrates architectural patterns for building enterprise applications, featuring a Monolithic Architecture foundation with Microservices Architecture partially implemented, and plans for Event-Driven and Serverless architectures.
- Overview
- Architecture
- Project Structure
- Technologies
- Features
- Getting Started
- Development Guide
- Testing
- Contributing
This project is a comprehensive implementation of Clean Architecture combined with Domain-Driven Design (DDD) using .NET 8. It demonstrates different architectural approaches for building enterprise applications, currently featuring:
- Monolithic Architecture - Complete foundation with 2 main business modules (Product & Category)
- Microservices Architecture - Partial implementation with API Gateway and 2 microservices
- Event-Driven Architecture - Planning phase (documentation only)
- Serverless Architecture - Planning phase (documentation only)
The current implementations showcase enterprise architecture principles with patterns like CQRS, Repository Pattern, Unit of Work, Mediator, API Versioning, Enhanced Security, and Advanced Middleware Pipeline.
๐ Current Status (October 2025):
- Monolithic Architecture: Has complete architectural structure with Product and Category management modules, enterprise security features, and comprehensive middleware pipeline. Requires solution file path fixes.
- Microservices Architecture: Partially implemented with API Gateway, CustomerManagement service, and ProductCatalog service with full Clean Architecture layers.
- Event-Driven & Serverless: Planning documentation ready for future implementation.
- ๐๏ธ Clean Architecture: Clear separation of layers and dependencies
- ๐ฏ Domain-Driven Design: Focus on business logic and domain model
- ๐๏ธ Monolithic Foundation: 2 core modules (Product & Category) with full CQRS implementation
- ๐ CQRS Pattern: Complete Command Query Responsibility Segregation with MediatR
- ๐ช Repository & Unit of Work: Enterprise-grade data access patterns implemented
- ๐งช Testing Infrastructure: 17 test files (12 unit tests, 5 integration tests) with xUnit and Moq
- ๐ Advanced APIs: RESTful APIs with API versioning (v1.0, v2.0) and OData support
- ๐ Enterprise Security: JWT authentication, CORS, rate limiting, IP whitelisting, request signing
- ๐ Performance Features: Response caching, compression (Gzip/Brotli), entity locking
- ๐ Rich API Documentation: Interactive Swagger UI with comprehensive documentation
- ๐ Microservices Foundation: API Gateway + 2 services with event bus infrastructure
- ๐ง Advanced Middleware: 8 middleware components for logging, rate limiting, exception handling
This repository demonstrates Clean Architecture principles by Uncle Bob implemented across different architectural patterns. Currently, it includes:
A complete monolithic application following Clean Architecture with 4 main layers:
- Entities: Core business objects
- Value Objects: Immutable objects
- Domain Events: Business events
- Repository Interfaces: Data access contracts
- Domain Services: Business logic services
- Use Cases: Application business rules
- Commands & Queries: CQRS implementation
- Handlers: Command/Query handlers
- DTOs: Data transfer objects
- Validators: Input validation
- Mappers: Object mapping
- 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
- Web API: RESTful APIs with ASP.NET Core
- Controllers: API endpoints
- Middleware: Request/Response pipeline
- API Documentation: Swagger/OpenAPI integration
- 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)
src/
โโโ MonolithArchitecture/ # ๐๏ธ Monolithic Architecture Implementation
โ โโโ src/
โ โ โโโ Application/ # Application layer
โ โ โ โโโ ProductManager.Application/ # Use cases, CQRS handlers
โ โ โ โโโ ProductManager.Domain/ # Domain entities, business rules
โ โ โโโ Infrastructure/ # Infrastructure layer
โ โ โ โโโ ProductManager.Infrastructure/ # External services, caching
โ โ โ โโโ ProductManager.Persistence/ # Data access, Entity Framework
โ โ โโโ Presentation/ # Presentation layer
โ โ โ โโโ APIs/ # RESTful Web API projects
โ โ โโโ CrossCuttingConcerns/ # Shared components
โ โ โโโ ProductManager.Shared/ # Common utilities, DTOs
โ โ โโโ ProductManager.Constants/ # Application constants
โ โโโ tests/ # Test projects
โ โ โโโ UnitTests/ # Unit tests
โ โ โโโ IntegrationTests/ # Integration tests
โ โโโ docs/ # Documentation
โ โ โโโ OData_Integration_Guide.md
โ โ โโโ OData_Integration_Summary.md
โ โ โโโ RESTful_API_Analysis.md
โ โโโ docker-compose.yml # Docker compose configuration
โ โโโ Dockerfile # Docker configuration
โ โโโ MonolithArchitecture.sln # Solution file
โ โโโ README.md # Detailed setup and implementation guide
โโโ MicroservicesArchitecture/ # ๏ฟฝ Microservices Architecture (Partial Implementation)
โ โโโ src/
โ โ โโโ Gateway/
โ โ โ โโโ ApiGateway/ # API Gateway service
โ โ โโโ Services/
โ โ โ โโโ CustomerManagement/# Customer management service
โ โ โ โ โโโ CustomerManagement.API/
โ โ โ โ โโโ CustomerManagement.Application/
โ โ โ โ โโโ CustomerManagement.Domain/
โ โ โ โ โโโ CustomerManagement.Infrastructure/
โ โ โ โโโ ProductCatalog/ # Product catalog service
โ โ โ โโโ ProductCatalog.API/
โ โ โ โโโ ProductCatalog.Application/
โ โ โ โโโ ProductCatalog.Domain/
โ โ โ โโโ ProductCatalog.Infrastructure/
โ โ โโโ Shared/ # Shared libraries and contracts
โ โ โโโ Shared.Common/ # Common utilities
โ โ โโโ Shared.Contracts/ # Service contracts
โ โ โโโ Shared.Events/ # Domain events
โ โโโ tests/
โ โ โโโ UnitTests/ # Unit tests for services
โ โโโ MicroservicesArchitecture.sln
โ โโโ README.md # Microservices setup guide
โโโ EventDrivenArchitecture/ # ๐ฎ Event-Driven Architecture (Planned)
โ โโโ README.md # Architecture planning document
โโโ ServerlessArchitecture/ # ๐ฎ Serverless Architecture (Planned)
โโโ README.md # Architecture planning document
- .NET 8 - Latest .NET framework
- ASP.NET Core - Web framework
- Entity Framework Core - ORM
- MediatR - Mediator pattern implementation
- AutoMapper - Object mapping
- FluentValidation - Input validation
- Serilog - Structured logging
- Swagger/OpenAPI - API documentation
- SQL Server - Primary database
- In-Memory Database - Testing
- IMemoryCache - In-memory caching
- Redis (Optional) - Distributed caching
- Docker - Containerization
- docker-compose - Multi-container deployment
- xUnit - Testing framework
- Moq - Mocking framework
- GitHub Actions - CI/CD pipeline
- โ
Product Management - Complete CRUD with Commands (AddOrUpdate, Delete) and Queries (GetById, Gets)
- Product entity with category relationship, pricing, stock management
- Full CQRS implementation with MediatR handlers
- Entity locking support for concurrent modification prevention
- Comprehensive validation and error handling
- โ
Category Management - Complete CRUD with hierarchical support
- Category entity with product relationships
- Full CQRS implementation with event handlers
- Support for category images and descriptions
- Comprehensive audit logging
-
๐ 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
-
๐ API Gateway - Fully implemented gateway service:
- JWT authentication integration
- Service proxy with HTTP client
- Swagger documentation
- Health monitoring
- Controllers: Auth, Categories, Products, Orders, Gateway, Health
- Request routing and load balancing foundation
-
๏ฟฝ CustomerManagement Service - Complete Clean Architecture layers:
- API Layer: RESTful endpoints with Swagger
- Application Layer: CQRS with MediatR, validators, mappers
- Domain Layer: Customer entities, repositories, domain services
- Infrastructure Layer: EF Core, DbContext, data access
- Full dependency injection configuration
-
๐ฆ ProductCatalog Service - Complete Clean Architecture layers:
- API Layer: Product endpoints with full CRUD
- Application Layer: CQRS implementation
- Domain Layer: Product domain models
- Infrastructure Layer: Database access layer
- Shared.Common: String extensions, domain events, EventBus interfaces, exception handling
- Shared.Contracts: BaseContract, Customer/Order/Product contracts for service communication
- Shared.Events: Integration event definitions for order and product events
- Unit test structure for ProductCatalog service
- Test infrastructure ready for expansion
- ๐ก Event Sourcing - Event-based state management
- ๐ Event Store - Durable event storage with replay capability
- ๐ Saga Pattern - Distributed transaction management
- ๐ CQRS Enhancement - Advanced read/write model separation
- ๐ฏ Event Handlers - Asynchronous event processing
- ๐ Event Analytics - Real-time stream processing
- โก Azure Functions - HTTP, Event, Timer, Queue functions
- ๐ฉ๏ธ Event Triggers - Event-driven function execution
- ๐ฐ Cost Optimization - Pay-per-execution model
- ๐ Managed Services - Cosmos DB, Service Bus, Storage integration
- ๐ Auto-scaling - Serverless compute scaling
- ๐ Function Monitoring - Application Insights integration
Choose the architectural pattern you want to explore. Each implementation has its own detailed README with specific setup instructions:
Status: ๐ก Implementation Foundation (October 2025)
- 2 Core Business Modules: Product Management and Category Management with full CQRS
- 5 API Controllers: Product, Category, Identity, Health, Logs
- 8 Middleware Components: Exception handling, logging, rate limiting, entity locking, CORS, compression
- Enterprise Security: JWT authentication, refresh tokens, Identity framework
- 17 Test Files: 12 unit tests (Product & Category), 5 integration tests
- Advanced Features: API versioning (v1.0, v2.0), OData, Swagger UI, health checks
- Note: Requires solution file path fixes (currently references old paths)
- ๐ View Implementation Guide โ
Status: ๐ก Partial Implementation (October 2025)
- API Gateway: Complete with 6 controllers (Auth, Categories, Products, Orders, Gateway, Health)
- 2 Microservices Implemented:
- CustomerManagement: Full Clean Architecture (API, Application, Domain, Infrastructure layers)
- ProductCatalog: Full Clean Architecture with CQRS implementation
- Shared Libraries: 3 shared projects (Common, Contracts, Events)
- Event Infrastructure: EventBus interfaces and integration event support
- Testing: Unit test structure for ProductCatalog
- Next Steps: Add OrderManagement, Inventory, Identity services
- ๐ View Implementation Guide โ
Status: ๐ก Planned for 2026
- Event Sourcing implementation with event store
- Message-driven communication with publish-subscribe patterns
- Saga pattern for distributed transactions
- CQRS with event replay capabilities
- ๐ View Architecture Planning โ
Status: ๐ก Planned for 2026
- Azure Functions implementation
- Event-driven triggers with auto-scaling
- Cloud-native approach with managed services
- Cost-effective serverless computing model
- ๐ View Architecture Planning โ
For immediate exploration, start with the Production-Ready Monolithic Architecture:
# Clone the repository
git clone https://github.com/hammond01/CleanArchitecture.git
cd CleanArchitecture
# Navigate to Monolithic implementation
cd src/MonolithArchitecture
# Restore dependencies
dotnet restore
# Run the application
dotnet run --project src/Presentation/APIs/ProductManager.Api
# Or use Docker Compose
docker-compose up -d
# Follow the complete setup guide for detailed instructions
# See: src/MonolithArchitecture/README.mdAll 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)
Recommended order for studying the implementations:
-
๐๏ธ Monolithic Architecture (Available Now - 70% Complete)
- Master Clean Architecture fundamentals with 4-layer separation
- Understand DDD principles through Product and Category modules
- Learn CQRS pattern with MediatR implementation
- Experience enterprise API development with versioning and OData
- Study comprehensive security implementation (JWT, middleware, rate limiting)
- Practice testing strategies with 17 test examples
-
๏ฟฝ Microservices Architecture (In Progress - 40% Complete)
- Learn service decomposition strategies
- Understand API Gateway patterns and routing
- Master inter-service communication with shared contracts
- Explore database-per-service pattern
- Study event-driven communication infrastructure
- Practice distributed system testing
-
๐ฎ Event-Driven Architecture (Planned 2026)
- Understand event-based patterns and event sourcing
- Learn CQRS advanced concepts with event store
- Master asynchronous communication patterns
- Explore saga patterns for distributed transactions
- Study eventual consistency strategies
-
๐ฎ Serverless Architecture (Planned 2026)
- Explore cloud-native serverless approaches
- Learn function-based architecture patterns
- Understand event-driven triggers and scaling
- Master Azure managed services integration
- Study cost-effective scaling strategies
Each architectural pattern builds upon concepts from the previous ones, creating a comprehensive learning experience from monolithic to distributed systems.
- Create Domain Entity in
ProductManager.Domain/Entities/ - Create Repository Interface in
ProductManager.Domain/Repositories/ - Implement Repository in
ProductManager.Persistence/Repositories/ - Create DTOs in
ProductManager.Shared/DTOs/ - Create Commands/Queries in
ProductManager.Application/Feature/ - Create Handlers for Commands/Queries
- Create Controller in
ProductManager.Api/Controllers/ - Write Tests in test projects
- Use C# naming conventions
- Follow Clean Code principles
- Implement proper error handling
- Add comprehensive logging
- Write unit tests for all business logic
- Document public APIs with XML comments
The project has comprehensive test infrastructure with enterprise-grade testing strategies:
Unit Tests (12 files in tests/UnitTests/Application/):
-
Product Module Tests (6 files):
AddOrUpdateProductHandlerTests.cs- Create/update product testsDeleteProductHandlerTests.cs- Product deletion testsGetProductByIdHandlerTests.cs- Single product retrieval testsGetProductsHandlerTests.cs- Product list query testsProductCommandQueryTests.cs- Command/query validation testsProductFeatureSummaryTests.cs- Feature integration tests
-
Category Module Tests (6 files):
AddOrUpdateCategoryHandlerTests.cs- Create/update category testsDeleteCategoryHandlerTests.cs- Category deletion testsGetCategoryByIdHandlerTests.cs- Single category retrieval testsGetCategoriesHandlerTests.cs- Category list query testsCategoryCommandQueryTests.cs- Command/query validation testsCategoryFeatureSummaryTests.cs- Feature integration tests
Integration Tests (5 files in tests/IntegrationTests/Controllers/):
ProductControllerTests.cs- Product API endpoint testsCategoryControllerTests.cs- Category API endpoint testsHealthControllerTests.cs- Health check endpoint testsIdentityControllerTests.cs- Authentication/authorization testsLogsControllerTests.cs- Logging endpoint tests
- Unit test structure available for ProductCatalog service
- Test infrastructure ready for expansion
- Test Isolation - Each test runs independently with proper setup/cleanup
- Realistic Data - AutoFixture for generating test data
- Dependency Mocking - Moq framework for unit tests
- Test Patterns - AAA (Arrange-Act-Assert) pattern
- Custom Factory -
CustomWebApplicationFactory.csfor integration tests
# Navigate to the monolithic architecture
cd src/MonolithArchitecture
# Restore dependencies (required due to solution file path issues)
dotnet restore
# Run all tests (after fixing solution file paths)
dotnet test
# Run with detailed output
dotnet test --verbosity normal
# Run with coverage report
dotnet test --collect:"XPlat Code Coverage"
# Run integration tests only
dotnet test tests/IntegrationTests/
# Run unit tests only
dotnet test tests/UnitTests/
# Run specific test category
dotnet test --filter Category=ProductMonolithArchitecture.sln file contains references to old paths (d:\NetCore\CleanArchitecture\...). Tests can be run individually from project directories, but the solution file needs path corrections.
- Clean Architecture Guide
- Domain-Driven Design
- API Documentation
- Database Schema
- Development Guide
- Deployment Guide
We welcome all contributions! Please read our Contributing Guidelines for details.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
- Clean Architecture by Uncle Bob
- Domain-Driven Design by Eric Evans
- .NET Community
- Author: hammond01
- GitHub: https://github.com/hammond01
- Project Link: https://github.com/hammond01/CleanArchitecture
- LinkedIn: Connect with me on LinkedIn
- Q4 2025:
- Fix Monolithic solution file path issues
- Complete testing and validation of existing features
- Add more business modules to Monolithic architecture
- Q1 2026:
- Complete Microservices Architecture with OrderManagement and Inventory services
- Implement inter-service communication patterns
- Add distributed tracing and monitoring
- Q2 2026:
- Event-Driven Architecture implementation
- Event Sourcing with event store
- Saga pattern for distributed transactions
- Q3 2026:
- Serverless Architecture with Azure Functions
- Cloud-native managed services integration
- Q4 2026:
- Performance benchmarking across all architectures
- Complete documentation and deployment guides
This project demonstrates the evolution from a well-designed monolith to distributed architectures:
- Monolithic Foundation (Current) - 2 core modules with full CQRS, JWT security, and enterprise middleware
- Microservices Decomposition (In Progress) - API Gateway + 2 services with shared libraries and event infrastructure
- Event-Driven Transformation (Planned) - Async communication with event sourcing
- Serverless Optimization (Planned) - Cloud-native scaling with Azure Functions
| Architecture | Status | Progress | Core Features |
|---|---|---|---|
| Monolithic | ๐ก Foundation Ready | 70% | 2 modules, 5 controllers, 8 middleware, 17 tests |
| Microservices | ๐ก Partial | 40% | API Gateway, 2 services, shared libraries |
| Event-Driven | ๐ต Planned | 0% | Documentation ready |
| Serverless | ๐ต Planned | 0% | Documentation 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! ๐
