How to muti-module a large spring application

42 Views Asked by At

I am developing a spring boot project consisting of multiple independent modules used by the main project. As I am new to this, I need guidance on how to segregate large project into maven modules. I have few ideas which I would like to get your opinion on,

  1. Modules by feature (and only by feature): Each feature is segregated into its own modules. Thus, the modules would have their own Entities, Repositories, Services. Only services which would be consumed by other modules.
Parent Project
   |- Feature 1 (owns dtos, repo, entities)
   |- Feature 2 (owns dtos, repo, entities)
   |- ...
   |- Main project (depends on Feature 1,2, ...)
  1. Modules by common concerns and subsequently by feature
Parent Project
   |- Entities
   |- Repositories (depends on Entities)
   |- Dtos (depends on Entities)
   |- Feature 1 (depends on dtos, repo)
   |- Feature 2 (depends on dtos, repo)
   |- Main project (depends on Feature Entities, Repositories, Dtos,1,2, ...)

I would like to know the pros and cons of either of the approaches. Any new approach is also welcome.

1

There are 1 best solutions below

0
On

I'd definitely go for the package-by-feature approach. By that you ensure that services can't use other services' classes and thus keep them independent.