🚀 Ultimate Template for Modern .NET Applications: Clean Architecture + Vertical Slice Architecture with CQRS
This powerful template brings together Clean Architecture and Vertical Slice Architecture into a seamless structure, designed to help .NET developers build robust, scalable, and maintainable applications. Whether you're starting a new project or upgrading an existing one, this template is your go-to foundation for modern software development.
-
Hybrid Architecture
- Combines the best of Clean Architecture (ensuring separation of concerns and testability) with Vertical Slice Architecture (encouraging feature-driven development for modular, independent slices).
-
Command Query Responsibility Segregation (CQRS)
- Built with the CQRS pattern to clearly separate read and write operations, making the codebase more organized and easier to scale.
-
Domain-Driven Design Principles
- Keeps business logic at the core, adhering to DDD concepts for domain modeling and validation.
-
Vertical Slices for Features
- Each feature is structured as an independent, self-contained slice, including all layers (command, query, domain, and infrastructure) within the same module.
- No unnecessary coupling between slices, resulting in modular and maintainable code.
-
Clean Separation of Concerns
- Layers are strictly segregated:
- Presentation Layer: Handles API endpoints, controllers, and input validation.
- Application Layer: Processes business logic, CQRS handlers, and mediates between other layers.
- Domain Layer: Core business logic and rules.
- Infrastructure Layer: External dependencies like database access, logging, and third-party integrations.
- Layers are strictly segregated:
-
Built-in Mediator Pattern
- Uses MediatR or similar libraries to handle communication between commands and queries, promoting loosely coupled components.
-
Validation Framework
- Integrates with FluentValidation for clean and reusable validation rules at the application layer.
-
Exception Handling & Problem Details
- Standardized error handling with ProblemDetails ensures API clients receive consistent and meaningful error responses.
-
Dependency Injection
- Fully integrated DI setup, making it easy to register and resolve services across different layers.
-
Ready-to-Use Best Practices
- Repository pattern (optional based on developer preference).
- Supports async programming and asynchronous disposable patterns.
- To come: Layered testing strategy with unit, integration, and end-to-end tests.
-
Extensibility
- The template allows for easy customization to suit your project's unique needs, including adding new slices without impacting existing functionality.
-
Modern Development Tools
- Fully compatible with .NET 8+, ensuring you're using the latest and greatest tools for your development.
- Developers who want to leverage the structured, scalable design of Clean Architecture.
- Teams looking for a modular approach to feature development with Vertical Slice Architecture.
- Those adopting CQRS for improved readability and maintainability in complex applications.
- Beginners and professionals aiming to start a new project with a rock-solid foundation.
This template eliminates the complexities of setting up a Clean Architecture-based project while incorporating the feature-first flexibility of Vertical Slice Architecture. It's optimized for productivity, scalability, and modern development best practices.
Use this template as the starting point for your next .NET project. Let it handle the architectural groundwork while you focus on building amazing features.