A clean, modular .NET 9 template using Vertical Slice Architecture — ideal for building scalable, maintainable APIs with CQRS, Mediator Design Pattern, FluentValidation, and EF Core/Dapper.
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
If you have found this project helpful, either as a library that you use or as a learning tool, please consider buying me a coffee:
Vertical Slice Architecture organizes code by features rather than technical layers. Each “slice” encapsulates all aspects of a specific feature, including the UI, business logic, and data access. This contrasts with traditional architectures that segregate applications into horizontal layers like Controllers, Services, and Repositories.
Figure: Representation of Vertical Slice Architecture emphasizing feature-centric organization. The image above illustrates the concept of Vertical Slice Architecture, where each feature, represented as a vertical slice, integrates all necessary components across the UI, Application, Domain, and Infrastructure layers. This ensures each feature is self-contained and simplifies scaling, testing, and maintaining code
- Vertical slice structure organized per use case (CQRS style)
- Minimal API with Carter for clean endpoint definitions
- Mediator Design Pattern for command/query dispatching (withou MediatR library)
- FluentValidation for request validation
- EF Core-based persistence layer (with optional Dapper support)
- Docker and Docker Compose support
- Testable, modular, and decoupled architecture
git clone https://github.com/Amitpnk/Vertical-Slice-Architecture.git
cd Vertical-Slice-Architecture
To build and start the containers:
docker-compose up --build
To run the containers in detached mode:
docker-compose up -d
Note: Building the Docker image manually is not usually required, but if needed, use:
docker build -f src/VA.API/Dockerfile -t va-api .
If you need to rebuild and restart the containers (for example, after making changes):
docker-compose down -v
docker-compose up --build
Once the containers are running, open your browser and navigate to:
http://localhost:5000
You should see the API running. Adjust the port if you have changed it in the Docker configuration.
Vertical-Slice-Architecture/
.github/
└── workflows/
└── dotnet.yml
docs/
├── gchr.md
└── README.md
src/
├── docker/
├── .dockerignore
├── docker-compose.dcproj
├── docker-compose.override.yml
├── docker-compose.yml
└── launchSettings.json
├── VA.API/
├── Customers/
├── CreateCustomer/
├── CreateCustomer.cs
├── CreateCustomerCommandHandler.cs
├── CreateCustomerCommandValidator.cs
└── CreateCustomerEndpoint.cs
├── DeleteCustomer/
├── DeleteCustomer.cs
├── DeleteCustomerCommandValidator.cs
├── DeleteCustomerEndpoint.cs
└── DeleteCustomerHandler.cs
├── GetCustomerById/
├── GetCustomer.cs
├── GetCustomerByIdEndpoint.cs
└── GetCustomerByIdQueryHandler.cs
├── GetCustomers/
├── GetCustomer.cs
├── GetCustomersEndpoint.cs
└── GetCustomersQueryHandler.cs
└── UpdateCustomer/
├── UpdateCustomer.cs
├── UpdateCustomerCommandHandler.cs
├── UpdateCustomerCommandValidator.cs
└── UpdateCustomerEndpoint.cs
├── Data/
├── CustomerContext.cs
└── Extentions.cs
├── Migrations/
└── CustomerDb/
├── 20250519180837_Init.cs
├── 20250519180837_Init.Designer.cs
└── CustomerContextModelSnapshot.cs
├── Models/
├── Customer.cs
├── CustomerDto.cs
└── CustomerExtensions.cs
├── Properties/
└── launchSettings.json
├── appsettings.Development.json
├── appsettings.json
├── docker-compose.md
├── Dockerfile
├── Dockerfile.original
├── dotnet-cli.md
├── GlobalUsing.cs
├── my-sql.md
├── Program.cs
├── VA.API.csproj
└── VA.API.http
└── VA.CrossCutting/
├── Behaviors/
├── LoggingBehavior.cs
└── ValidationBehavior.cs
├── CQRS/
├── Dispatcher.cs
├── ICommand.cs
├── ICommandHandler.cs
├── IDispatcher.cs
├── IQuery.cs
└── IQueryHandler.cs
├── Exceptions/
├── Handler/
└── CustomExceptionHandler.cs
├── BadRequestException.cs
├── InternalServerException.cs
└── NotFoundException.cs
├── Pagination/
├── PaginatedResult.cs
└── PaginationRequest.cs
└── VA.CrossCutting.csproj
test/
└── VA.API.Tests/
├── Customers/
└── GetCustomers/
├── GetCustomersQueryHandlerTests.cs
└── GetCustomersQueryTests.cs
├── Data/
└── CustomerContextTests.cs
├── Models/
├── CustomerDtoTests.cs
├── CustomerExtensionsTests.cs
└── CustomerTests.cs
└── VA.API.Tests.csproj
.dockerignore
.gitignore
docker-compose.dcproj
docker-compose.override.yml
docker-compose.yml
launchSettings.json
LICENSE
VA.sln
This project is licensed under the MIT License — see the LICENSE file for details.
Having issues or need help getting started? Email amit.naik8103@gmail.com or raise a bug or feature request. Always happy to help.