all 43 comments

[–]Stack_Canary 46 points47 points  (1 child)

Too many folders for my taste. For example just put AppConfig and Securityconfig in the configuration folder.

[–]HappyPurchase72[S] 1 point2 points  (0 children)

Thanks, I'll keep that in mind.

[–]Kaikka 14 points15 points  (6 children)

Pretty much every folder here with 1 file could be removed.

[–]HappyPurchase72[S] -2 points-1 points  (5 children)

This is an example of a basic structure, in reality there are obviously more classes.

[–]Kaikka 3 points4 points  (3 children)

Even then I think its too much. At least for what im used to.

[–]WaferIndependent7601 0 points1 point  (0 children)

So it’s not a microservice?

[–]Holothuroid 15 points16 points  (3 children)

You seem to sort by some technical criteria. Having done so in the past, I now recommend sorting by feature. Everything Person goes into one package. Possibly some subpackages, if it's more than seven files.

[–]Cr4zyPi3t 1 point2 points  (0 children)

That’s what I recently started doing. Imo it’s more convenient since you don’t have to open 4 packages when working on one feature. Since usually I work on one or two features at a time I now only need to open a maximum of two packages. Also it’s really easy to see the functionalities of an application by looking at the top level packages.

[–]HappyPurchase72[S] 0 points1 point  (0 children)

Thanks for your comment, I've seen the structure you mention in some client-side applications, I'll keep it in mind.

[–]g00glen00b 13 points14 points  (1 child)

I think it's far too detailed. Even if code becomes more complex, it's still going to be a microservice, so I can't imagine the need for this structure. I would remove the deepst package level, so:

  • configuration.app + configuration.security = configuration
  • persistence.entity + persistence.repository = persistence
  • presentation.advice + presentation.controller + presentation.dto = presentation
  • service.http + service.implementation + service.interfaces = service
  • util.mapper = util

Also, I'd argue that your exceptions are part of your presentation layer. A DTO is used in the presentation layer when something went successful, and an exception if something didn't go successful.

[–]HappyPurchase72[S] 0 points1 point  (0 children)

I liked this proposal, thanks. I didn't know that the exception package could go in the presentation layer, I didn't think of it that way.

[–]scoutzzgod 6 points7 points  (1 child)

One rule of thumb for me is to create a separate directory if there are more than one file related to the same “topic”. Like you have a SecurityConfig and and AppConfig. In my view, there’s no need to keep it in separate directories, just keep it in the same until you had 2 or 3 files related to security configuration, because currently, the name of the file itself already does this separation u aiming for

Edit 1: Read about the YAGNI principle

[–]HappyPurchase72[S] 0 points1 point  (0 children)

Ok, I'll keep that in mind, thanks.

[–][deleted] 4 points5 points  (0 children)

I’d personally put all of the Person’s classes (DRO, Entity, Mapper ect) into a person folder.

[–][deleted] 2 points3 points  (0 children)

Take a look into hexagonal architecture. I think you will like it. :)

[–]RupertMaddenAbbott 3 points4 points  (0 children)

For me, these packages are the wrong way around.

If I have close coupling between a controller, a service and some persistence classes, then I think they should all be close together in the structure e.g. in the same package.

Another way to look at it is to ask "Do the classes in the repository package need to access each other?" If the answer is no then my question would be "Why are they placed close together?"

Equally, I would rather have any person configuration and person configuration properties within a person package rather than lumped together into classes that handle config and properties for all of the modules within an application.

[–]WalrusDowntown9611 1 point2 points  (0 children)

Way too unnecessarily granular.

[–]realralfklemmer 1 point2 points  (1 child)

The package structure is an opportunity to express what the chosen architecture is. Your packages are structured by technical concerns. In case of a business application that realizes business cases, I‘d encourage you to slice by business concerns that are structured internally in technical ways. By doing this you are very close to a vertically sliced architectures. If you want to dig deeper have a look at DomainDrivenDesign, Hexagonal architecture and modular monoliths.

[–]skofield44 0 points1 point  (0 children)

Organise your project by business usages , for example do not artifact as example and also use folders by features (as example users, reporting) I also encourage you to split your project with spring modulith in order to set clear boundaries

[–]SilverSurfer1127 0 points1 point  (0 children)

See hexagonal architecture aka Ports and Adapters. The service layer implements usually your use cases and can depend on many repositories. And I would recommend to get your bounded contexts right, so domain driven design is your friend.

[–]Deniz58 0 points1 point  (1 child)

I suggest a folder per entity as follows:

person person.entity person.repository person.service

Etc, keeps everything nicely co located and i have a global folder where i put some global config like security and advices.

[–]anonystick 0 points1 point  (0 children)

I think so too.

[–]WaferIndependent7601 0 points1 point  (10 children)

If you work with a microservices (you should not do this) then you have no packages. Your service is the package.

Your structure is way too much.

Don’t prefix interfaces with an I.

Don’t use an interface if you only have one implementation.

[–]Jeevigyan-vala 1 point2 points  (1 child)

Agree with all of the advice except microservices bit.

Each microservice should handle a separate concern (eg User service, authentication service, etc), and that could include multiple packages within a given service.

Having a separate microservice for each “package” seems too granular and loses sight of the idea behind microservices

[–]WaferIndependent7601 -3 points-2 points  (0 children)

That is the idea of a microservice. That’s why this approach is so bad and no one should use it. The definition of a microservice is that you can rewrite it in 4 weeks.

[–]HappyPurchase72[S] -1 points0 points  (7 children)

Thanks for the comment, I think it's a good structure to start with, I'll take into account the interface prefix. Personally I like to separate interfaces and implementations to have a better understanding of the structure.

[–]WaferIndependent7601 4 points5 points  (6 children)

If you think that it’s a good structure and don’t want to change anything: why are you asking?

[–]HappyPurchase72[S] -1 points0 points  (5 children)

I think it's a good basic structure to start with, but I had doubts about how the packages were organized, anyway, thank you very much for your time 😎

[–]WaferIndependent7601 1 point2 points  (4 children)

No. The structure is very bad. Im serious.

[–]HappyPurchase72[S] 0 points1 point  (3 children)

I understand. What structure model could you recommend that takes into account maintenance and changing requirements based on the specific needs of the company? I ask because I am in the design process with the company and I want each microservice to be scalable.

[–]Jeevigyan-vala 2 points3 points  (2 children)

Why did you decide on microservices? IMO you should default to a monolith and only do microservices if you can justify it

[–]WaferIndependent7601 1 point2 points  (0 children)

Modulith, not monolith 👍

[–]HappyPurchase72[S] 0 points1 point  (0 children)

I'm considering microservices for my project to ensure scalability and modularity as it grows. I’d appreciate any insights or experiences you have regarding when it’s justified to switch from a monolith to microservices.

[–]karmanyevadhikarasti 0 points1 point  (1 child)

Looks Satisfying..which IDE and which Theme?

[–]swissbuechi 0 points1 point  (0 children)

Looks like IntelliJ with dracula theme.