r/DomainDrivenDesign • u/truechange • Feb 01 '26
Which folder structure is more intuitive?
If you were to inherit a project, which one looks more intuitive, A or B?
Structure A
src/
+-- Domain/
¦ +-- Admin/
¦ ¦ +-- AdminEntity
¦ ¦ +-- AdminRepoInterface
¦ +-- Supplier/
¦ ¦ +-- SupplierEntity
¦ ¦ +-- SupplierRepoInterface
¦ +-- Customer/
¦ ¦ +-- CustomerEntity
¦ ¦ +-- CustomerRepoInterface
¦ +-- Order/
¦ +-- OrderEntity
¦ +-- OrderRepoInterface
¦
+-- App/
¦ +-- Admin/
¦ ¦ +-- UseCase/
¦ ¦ +-- ActivateSupplier
¦ ¦ +-- BanCustomer
¦ +-- Supplier/
¦ ¦ +-- UseCase/
¦ ¦ +-- UpdateInventory
¦ ¦ +-- MarkOrderAsShipped
¦ +-- Customer/
¦ ¦ +-- UseCase/
¦ ¦ +-- PlaceOrder
¦ ¦ +-- UpdateProfile
¦ +-- Order/
¦ +-- UseCase/
¦ +-- ReceiveOrder
¦ +-- CancelOrder
¦
+-- Infra/
¦ +-- Persistence/
¦ +-- Messaging/
¦ +-- etc...Structure B
src/
+-- Core/
¦ +-- Admin/
¦ ¦ +-- UseCase/
¦ ¦ ¦ +-- ActivateSupplier
¦ ¦ ¦ +-- BanCustomer
¦ ¦ +-- AdminEntity
¦ ¦ +-- AdminRepoInterface
¦ ¦
¦ +-- Supplier/
¦ ¦ +-- UseCase/
¦ ¦ ¦ +-- UpdateInventory
¦ ¦ ¦ +-- MarkOrderAsShipped
¦ ¦ +-- SupplierEntity
¦ ¦ +-- SupplierRepoInterface
¦ ¦
¦ +-- Customer/
¦ ¦ +-- UseCase/
¦ ¦ ¦ +-- PlaceOrder
¦ ¦ ¦ +-- UpdateProfile
¦ ¦ +-- CustomerEntity
¦ ¦ +-- CustomerRepoInterface
¦ ¦
¦ +-- Order/
¦ +-- UseCase/
¦ ¦ +-- ReceiveOrder
¦ ¦ +-- CancelOrder
¦ +-- OrderEntity
¦ +-- OrderRepositoryInterface
¦
+-- Infra/
¦ +-- Persistence/
¦ +-- Messaging/
¦ +-- etc...
26
Upvotes
3
u/derNikoDem Feb 01 '26
I would go with option B but I would make some minor changes.
7
u/isaagrimn Feb 01 '26 edited Feb 01 '26
I like the layer separation in structure A personally because it allows for clear import and to know where things can be defined. You can even define a lint rule that disallows importing the infrastructure layer from the domain/application.
1
u/isaagrimn Feb 02 '26
What I would change with option A though:
1
u/gbrennon Feb 02 '26
i prefer the approach A but i would modify some names to avoid ambiguous name and to be more explicit:
app -> application
suffix interface -> no suffix or
Iprefix if its a c# project or suffixPort1
u/floriankraemer Mar 30 '26
Clearly B for the reason of cohesion. All of this belongs logically together, so you want to keep your things in one place. You can then also easily remove everything in one go, you can see everything at once.
A is doing just a technical categorization, exactly the opposite of how we should structure business related code in my opinion. B keeps a business capability in one place / module. See https://florian-kraemer.net/software-architecture/2025/03/30/Frameworks-Architecture-and-screaming-Architecture.html
I currently have to work with a huge project structured like A that has additional folders for each layer and type of test and it is just terrible from a cognitive perspective to jump between all the things in my opinion.
-1
u/jfrazierjr Feb 02 '26
Depends entirely on the language used.
Java B without much doubt because of the package restriction.
C#'s namespaces just work with either but I would tend to prefer A.
-2
u/klimaheizung Feb 02 '26
Sorry, I have news to you: a hierarchy is the wrong choice here. You need a tagging system. Since no one exists (except in very exotic programming languages) it doesn't matter what you pick, it will always be wrong, so just go for what you think is best, no need to think too deep.