Architecture ‐ Vertical Slicing Architecture - FullstackCodingGuy/Developer-Fundamentals GitHub Wiki
Vertical slice architecture is an approach for organising your code into features/vertical slices rather than organising by technical conerns (e.g. Controllers, Models, Services etc). Each slice will contain all the code which fullfills a feature or use case inside the application. One of the main benefits of VSA is the ability to structure each feature/slice independently, so each feature/slice can be as simple or complicated as it needs to be.

Both Onion/Clean Architecture and Vertical Slicing Architecture aim to structure applications for better maintainability, scalability, and testability, but they take different approaches in organizing the codebase. Here's a breakdown of their differences:
✅ Layered Architecture
✅ Focuses on Separation of Concerns
✅ Domain-Centric (Business Logic First)
✅ Code is Organized by Layer (API, Application, Domain, Infrastructure)
/TaskManager
│── /API --> Presentation Layer (Controllers, Endpoints)
│── /Application --> Business Logic (Use Cases, DTOs, Services)
│── /Domain --> Core Business Rules (Entities, Aggregates)
│── /Infrastructure --> Persistence, External APIs, Logging
- The Domain is at the center (contains entities and business rules).
- The Application Layer contains use cases, DTOs, and services.
- The Infrastructure Layer includes database, logging, and external integrations.
- The API Layer is just an interface for external consumers (Controllers/Minimal APIs).
- Dependencies flow inwards (API → Application → Domain).
✔️ Strong separation of concerns and modular structure.
✔️ Testability (business logic is independent of frameworks).
✔️ Scalability (supports different UIs like Web, Mobile, or gRPC).
❌ Can be over-engineered for simple projects.
❌ Slower to develop due to multiple layers.
✅ Feature-Based Organization
✅ Each Feature is Independent
✅ Reduces Unnecessary Abstraction
✅ Follows CQRS and Mediator Patterns
/TaskManager
│── /Features
│ ├── /Tasks
│ │ ├── /Create
│ │ │ ├── CreateTaskHandler.cs
│ │ │ ├── CreateTaskRequest.cs
│ │ │ ├── CreateTaskResponse.cs
│ │ ├── /GetAll
│ │ │ ├── GetAllTasksHandler.cs
│ │ │ ├── GetAllTasksRequest.cs
│ │ │ ├── GetAllTasksResponse.cs
│── /Infrastructure --> Shared Infrastructure (DB, Logging)
│── /API --> Entry Point (Minimal API, Controllers)
- Each feature (e.g.,
Tasks
) is self-contained with its own:- Handler (Processing logic)
- Request DTO
- Response DTO
- Uses CQRS (Command Query Responsibility Segregation) and MediatR for clean request handling.
- No unnecessary abstraction (like repositories or service layers).
✔️ Faster Development (each feature is independent).
✔️ Avoids unneeded complexity (no forced service/repository layers).
✔️ Easier to scale individual features.
✔️ Better for Microservices (as features are isolated).
❌ Can lead to duplicate logic (each feature implements its own handling).
❌ Harder to maintain cross-cutting concerns (logging, caching, etc.).
Criteria | Onion/Clean Architecture | Vertical Slicing Architecture |
---|---|---|
Best for | Large, Enterprise Applications | Small to Medium Projects, Microservices |
Focuses on | Business Logic and Separation of Concerns | Features and Quick Development |
Complexity | Higher (More Layers) | Lower (Flat Structure) |
Maintainability | Easier for Long-Term | Easier for Short-Term |
Cross-Cutting Concerns | Centralized | Handled per Feature |
Scaling Approach | Modular and Layered | Independent Features |
✔ Onion/Clean Architecture → Better for long-term projects, domain-driven design, and testability.
✔ Vertical Slicing → Better for microservices, fast iteration, and reducing boilerplate.