Clean Architecture Folder Structure
An approach to organizing code by features rather than technical types, similar to Vertical Slice Architecture.
Core Principle
Focus on features, not types.
Instead of grouping files by type (Commands/Queries), group everything related to a single command (feature) in one folder.
Traditional vs Feature-Based Organization
Traditional (by type):
π Application
βββ π Commands
β βββ CreateBookingCommand.cs
β βββ CancelBookingCommand.cs
β βββ ...
βββ π Queries
β βββ GetBookingQuery.cs
β βββ ...
βββ π Validators
βββ ...
Feature-Based (recommended):
π Application
βββ π FeatureFolder1
β βββ π Feature1A
β βββ π Feature1B
βββ π FeatureFolder2
β βββ π Feature2A
β βββ π Feature2B
βββ ...
Practical Example: Bookings Feature
π Application
βββ π Bookings
β βββ π Cancel
β β βββ CancelBookingCommand.cs
β β βββ CancelBookingHandler.cs
β β βββ CancelBookingValidator.cs
β βββ π Confirm
β β βββ ConfirmBookingCommand.cs
β β βββ ConfirmBookingHandler.cs
β β βββ ConfirmBookingValidator.cs
β βββ π Reject
β β βββ ...
β βββ π Reserve
β β βββ ...
β βββ ...
Whatβs the Idea?
Iβm grouping the files based on the feature they belong to.
A use case will be a command/query and a respective handler. And often, thereβs a command validator there.
Key Benefits
- Better cohesion - Related code stays together
- High coupling for a single feature - Everything you need for one feature is in one place
- Easier navigation - Find all related code instantly
- Scalability - Add new features without touching existing code
Relation to Vertical Slice Architecture
If youβre familiar with Vertical Slice Architecture, this idea is similar. Each vertical slice represents a complete feature from API to database, organized in its own folder.
Sources
Arhitectura/Clean arch folder structure.png