I'm trying to understand how people structure a reasonably large Java/Spring modular monolith in practice.
I understand the general idea of package-by-feature / DDD / bounded contexts fairly well. For example:
orders/
submissions/
users/
catalog/
And inside a business module you can have things like:
api/
application/
domain/
infrastructure/
What I'm struggling with is everything that doesn't fit neatly into a business domain.
For example:
- security
- authentication / authorization
- CurrentUser / UserContext
- email notifications
- file storage / uploads
- PDF generation
- reporting Jackson
- configuration Web MVC
- configuration messaging
- observability
- global exception handling
Where do these things actually live in a real modular monolith?
For example, suppose I have:
submissions/
orders/
users/
notifications/
security/
config/
infrastructure/
A submission is created and I want to send a confirmation email.
Would you do something like:
submissions
|
| NotificationRequested
v
notifications
|
v
EmailSender
with notifications being an application module, and EmailSender / template rendering / SMTP being infrastructure?
Or would you put the email infrastructure outside the notifications module?
Similarly, where would you put CurrentUser? If every controller needs the authenticated user, should it be exposed by a security module? Does that mean all business modules depend on security?
And what about Spring Security annotations such as:
@PreAuthorize("hasRole('ADMIN')")
on controllers belonging to different modules?
I'm also wondering how this relates to Spring Modulith. I understand that it can enforce application module boundaries, but I'm not sure what the recommended approach is for these cross-cutting/technical concerns.
I'm specifically interested in real-world production codebases, not toy/tutorial examples.
How do you normally structure this in a large Java/Spring application?
If you have examples of mature open-source projects or architectural documentation that demonstrate this, I'd really appreciate them.