r/java • • Oct 24 '26

Hexagonal Architecture vs. Pragmatic Layered Architecture in Spring Boot

/r/softwarearchitecture/comments/1xe8u4d/hexagonal_architecture_vs_pragmatic_layered/
8 Upvotes

17 comments sorted by

View all comments

1

u/cogman10 Oct 26 '26

Well first, depending on project size, pretty much any approach will work. If this is a small project then just go with whatever the team wants to do.

But if a project is going to get big and complex, I suggest packaging by feature, not layer. Read up on DDD. And give this blog series a read: https://edmundkirwan.com/general/spoiklin.html

Hex is just a simplification of DDD rules. Strict adherence will lead you to a ball of mud if you don't understand the underlying principles that hex is trying to hit on.

Everything is dependencies, and if you think of it in those terms you'll do a lot better. Would you want to pull in a dependency which is the "everything library"? Or would you rather pull in a "Json" library? Even spring boot realizes this which is why you pull in the parts of spring you are using and not the whole ball of wax.

You should structure the internals of your app in a similar fashion. Do you want a "service" module that contains everything that could be a service, from authentication to inventory management? Probably not. It makes more sense to have an authentication modules and an inventory management module with well defined interaction points.