What folder structure do you use in your projects?
1 min read · — #systemdesign#softwarearchitecture
What folder structure do you use in your projects?
There are 2 approaches you can use:
- Group by type
- Group by feature
I'll use the Clean Architecture Domain layer to illustrate.
Here's what Group by type would look like:
📁 Domain
|** 📁 DomainEvents
|** 📁 Entities
|** 📁 Enums
|** 📁 Exceptions
|** 📁 Repositories
|** 📁 Shared
|\_\_ 📁 ValueObjects
And here's what Group by feature would look like:
📁 Domain
|** 📁 [Feature]/[Aggregate]/[BoundedContext]
⠀⠀⠀|** ❎ // The files go inside
|** 📁 Orders
⠀⠀⠀|** ❎ Order.cs
⠀⠀⠀|** ❎ LineItem.cs
⠀⠀⠀|** ❎ OrderNotFoundException.cs
⠀⠀⠀|** ❎ OrderStatus.cs
⠀⠀⠀|** ❎ OrderCreatedDomainEvent.cs
⠀⠀⠀|** ❎ IOrderRepository.cs
|** 📁 Products
⠀⠀⠀|** ❎ ...
|** 📁 ...
I used both groupings by type and by feature, and I've seen the pros and cons of each approach.
Grouping by type seems like a good idea until your project grows.
Before you know it, maintainability is compromised, and adding new classes is a pain.
Have you heard about Vertical Slice Architecture?
That's what grouping by feature is.
VSA takes it to the extreme, placing all files related to a single feature together.
Grouping by feature is more appropriate for larger projects, but you'll see a benefit on small projects.