A production-ready ASP.NET Core 10 Web API showcasing enterprise architecture patterns with MediatR CQRS implementation, demonstrating advanced architectural practices for scalable task management systems.
Swagger UI: https://todotasks-cqrs-mediatr-production.up.railway.app/swagger/index.html
API Base URL: https://todotasks-cqrs-mediatr-production.up.railway.app/api
Clean Architecture with CQRS Pattern via MediatR:
src/
├── TodoTasks.API/ # Web API Layer (Controllers, Program.cs)
├── TodoTasks.Application/ # Business Logic Layer (MediatR Handlers, Queries, Commands)
│ ├── Features/ # CQRS Feature Folders
│ │ ├── TodoTask/
│ │ │ ├── Commands/ # Write Operations (CreateTodoTask, UpdateTodoTask, etc.)
│ │ │ └── Queries/ # Read Operations (GetTodoTasks, GetTodoTaskById, etc.)
│ │ └── Category/
│ │ ├── Commands/
│ │ └── Queries/
│ └── Common/ # Cross-cutting Concerns
│ ├── Behaviors/ # MediatR Pipeline Behaviors (Validation, Logging)
│ ├── Mappings/ # AutoMapper Profiles
│ └── DTOs/ # Data Transfer Objects
├── TodoTasks.Domain/ # Domain Layer (Entities, Value Objects, Repositories)
└── TodoTasks.Infrastructure/ # Data Access Layer (EF Core, Repositories)
- CQRS Pattern with MediatR for command/query separation
- Clean Architecture with strict dependency inversion
- Domain-Driven Design principles with rich domain models
- MediatR Pipeline Behaviors for cross-cutting concerns (validation, logging)
- FluentValidation integrated with MediatR validation behavior
- AutoMapper for DTO mapping
- Serilog for structured logging with file and console sinks
- JWT Authentication for secure API access
- Entity Framework Core 10 with SQL Server or PostgreSQL
- Repository Pattern for data access abstraction
- Swagger/OpenAPI documentation with Bearer token support
- Unit Tests for Application and Domain layers
- Dependency Injection throughout all layers
- .NET 10 - Latest framework version
- ASP.NET Core Web API - RESTful API framework
- MediatR 12.x - CQRS pattern implementation
- FluentValidation - Declarative validation rules
- AutoMapper - Object-to-object mapping
- Serilog 8.x - Structured logging framework
- Entity Framework Core 10 - ORM for data access
- SQL Server / PostgreSQL - Database providers (switchable)
- JWT Bearer Authentication - Secure token-based authentication
- Swashbuckle.AspNetCore 6.9 - API documentation
- xUnit - Unit testing framework
- C# 13 - Latest language features
Commands represent state-changing operations. Each command has:
- Command Class - Implements
IRequest<TResponse> - Command Handler - Implements
IRequestHandler<TCommand, TResponse> - Command Validator - FluentValidation rules
Example structure:
Features/TodoTask/Commands/
├── CreateTodoTask/
│ ├── CreateTodoTaskCommand.cs
│ ├── CreateTodoTaskCommandHandler.cs
│ └── CreateTodoTaskCommandValidator.cs
├── UpdateTodoTask/
│ ├── UpdateTodoTaskCommand.cs
│ ├── UpdateTodoTaskCommandHandler.cs
│ └── UpdateTodoTaskCommandValidator.cs
└── DeleteTodoTask/
├── DeleteTodoTaskCommand.cs
├── DeleteTodoTaskCommandHandler.cs
└── DeleteTodoTaskCommandValidator.cs
Queries represent data retrieval operations. Each query has:
- Query Class - Implements
IRequest<TResponse> - Query Handler - Implements
IRequestHandler<TQuery, TResponse>
Example structure:
Features/TodoTask/Queries/
├── GetPagedTodoTasks/
│ ├── GetPagedTodoTasksQuery.cs
│ └── GetPagedTodoTasksQueryHandler.cs
├── GetTodoTaskById/
│ ├── GetTodoTaskByIdQuery.cs
│ └── GetTodoTaskByIdQueryHandler.cs
└── GetAllTodoTasks/
├── GetAllTodoTasksQuery.cs
└── GetAllTodoTasksQueryHandler.cs
LoggingBehavior - Automatically logs all command/query executions:
- Logs request name and execution time
- Captures exceptions with timing information
- Provides performance monitoring
ValidationBehavior - Automatically validates all commands/queries before execution:
- Runs FluentValidation rules
- Throws validation exceptions on failure
- Eliminates repetitive validation code in handlers
builder.Services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(typeof(GetPagedTodoTasksQuery).Assembly);
cfg.AddOpenBehavior(typeof(LoggingBehavior<,>));
cfg.AddOpenBehavior(typeof(ValidationBehavior<,>));
});
builder.Services.AddValidatorsFromAssembly(typeof(CreateTodoTaskCommandValidator).Assembly);
builder.Services.AddAutoMapper(typeof(MappingProfile).Assembly);Structured logging with multiple sinks:
- Console Sink - Real-time log output during development
- File Sink - Rolling daily log files in
logs/directory - Request Logging - HTTP request/response logging middleware
- Performance Tracking - Automatic timing for all MediatR requests
What gets logged:
- Request name (e.g.,
GetPagedTodoTasksQuery,CreateTodoTaskCommand) - Execution time in milliseconds
- Success/failure status
- Exception details with stack traces
- Structured data for easy querying
- Controllers - Only handle HTTP concerns (routing, status codes)
- MediatR Handlers - Contain business logic
- Domain Layer - Pure business rules, no framework dependencies
- Infrastructure - Database and external service concerns
- Rich domain model with encapsulated business logic
- State changes through domain methods
- Domain-level validation
- Support for categories, due dates, and assignments
- Color-coded task categorization
- Validation for name length and format
- Update tracking with timestamps
- .NET 10 SDK
- SQL Server (LocalDB or full instance) OR PostgreSQL
- Visual Studio 2024 or VS Code
- Clone the repository
- Choose your database provider in
appsettings.json:"DatabaseProvider": "SqlServer", // or "PostgreSQL"
- Run database migrations:
dotnet ef database update --project src/TodoTasks.API
- Start the application:
dotnet run --project src/TodoTasks.API
Navigate to /swagger in development mode to explore endpoints and test with JWT authentication.
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login and get JWT token |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/todotasks |
Get all tasks (paginated) |
| GET | /api/todotasks/{id} |
Get task by ID |
| POST | /api/todotasks |
Create new task |
| PUT | /api/todotasks/{id} |
Update existing task |
| DELETE | /api/todotasks/{id} |
Delete task |
| POST | /api/todotasks/{id}/complete |
Mark task as complete |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/categories |
Get all categories |
| GET | /api/categories/{id} |
Get category by ID |
| POST | /api/categories |
Create new category |
| PUT | /api/categories/{id} |
Update existing category |
| DELETE | /api/categories/{id} |
Delete category |
- ✅ CQRS Pattern - Command Query Responsibility Segregation
- ✅ MediatR Integration - Request/response pipeline with behaviors
- ✅ Pipeline Behaviors - Cross-cutting concerns (validation, logging)
- ✅ JWT Authentication - Token-based security
- ✅ Dependency Injection - Advanced DI container usage
- ✅ Middleware Pipeline - HTTP request processing
- ✅ Swagger Integration - API documentation with Bearer auth
- ✅ Clean Architecture - Layered application design
- ✅ CQRS Pattern - Command/Query separation
- ✅ Repository Pattern - Data access abstraction
- ✅ Dependency Inversion - Interface-based programming
- ✅ Domain-Driven Design - Rich domain models
- ✅ SOLID Principles - Clean, maintainable code
- ✅ Feature Folder Structure - Organized by business features
- ✅ Code-First Migrations - Database schema management
- ✅ DbContext Configuration - Database context setup
- ✅ Relationship Mapping - Entity relationships
- ✅ Seed Data - Initial data population
- ✅ Async Operations - Non-blocking database operations
- ✅ FluentValidation - Declarative validation rules
- ✅ MediatR Behaviors - Automatic validation pipeline
- ✅ AutoMapper - Object mapping with profiles
- ✅ DTO Pattern - Request/response data transfer
- ✅ Unit Tests - Application layer handler tests
- ✅ Domain Tests - Entity and value object tests
- ✅ xUnit Framework - Modern testing practices
- ✅ Test Isolation - Independent test execution
- ✅ GitHub Actions - Automated CI/CD pipeline
- ✅ Self-Contained Deployment - .NET 10 to Railway deployment
- ✅ Automated Build & Deploy - Push to production on commit
- ✅ Docker Integration - Containerized deployment
- ✅ Nullable Reference Types - Null safety
- ✅ Record Types - Immutable data structures
- ✅ Pattern Matching - Modern C# syntax
- ✅ Primary Constructors - Concise constructor syntax
- ✅ Global Using Statements - Reduced boilerplate
- ✅ CQRS with MediatR - Command/Query separation
- ✅ MediatR Pipeline Behaviors - Validation and logging cross-cutting concerns
- ✅ FluentValidation - Declarative validation rules
- ✅ AutoMapper - Object mapping
- ✅ Serilog - Structured logging with file and console sinks
- ✅ Authentication & Authorization (JWT) - Secure token-based auth
- ✅ Unit Tests - Application and Domain layer coverage
- ✅ CI/CD Pipeline - GitHub Actions automated deployment to Railway
- Integration Tests
- Docker containerization
- Caching with Redis
- Health checks
- Rate limiting
- API versioning
MediatR provides several benefits for enterprise applications:
- Decoupling - Controllers don't directly reference business logic
- Testability - Handlers can be tested independently
- Reusability - Commands/Queries can be invoked from multiple sources
- Extensibility - Pipeline behaviors enable cross-cutting concerns
- Maintainability - Clear separation between read and write operations
- Scalability - Easy to implement async operations and caching
This project demonstrates production-ready ASP.NET Core development with advanced architectural patterns suitable for enterprise applications and scalable systems.