r/SpringBoot • u/dpk_s2003 • Jan 11 '26
How-To/Tutorial Started my Spring Boot project today focusing on clean layered architecture
I’ve started building a Spring Boot project and today I focused only on the foundation.
Steps I followed: 1. Created the project using Spring Initializr 2. Opened it in Eclipse IDE 3. Set up a clean layered folder structure (config, entity, repository, service)
I’m trying to understand proper backend architecture instead of rushing features. Next step will be controller layer and API flow.
If you have any suggestions or best practices for structuring Spring Boot projects, I’d really appreciate them.
14
Upvotes
8
u/WaferIndependent7601 Jan 11 '26
You’re not doing a clean architecture and I really hate that so many howtos say you should put all controllers in a controller package. This will make things harder in the future.
6
u/Long-Agent-8987 Jan 11 '26 edited Jan 11 '26
Don’t just create those folders at the base. Break the application into domain folders that contain said folders but not config. Then have config and shared/common at the base adjacent to the domain folders. In this way you get clear separation of domains. The service layer of a domain will provide communications and call repo layer based on domain entities.
You can put a controllers folder in the domain folders too, which use the service, the controller should communicate externally using Dtos, and internally using use cases or commands, these will involve domain entity types.
3
u/Abhistar14 Jan 11 '26
My best project, deployed on AWS. If it helps!
2
u/devmoosun Jan 11 '26
I use package-based structuring for my projects.
Each package contains its Entity, Controllers, Service, Service Impl, Repo, DTO Requests and Responses, Enums, and their Mappers.
A security package that contains the Web and Security config, JWT implementations. A common package for the Base Repo, exceptions, storages, etc. A util package for utility jobs (PasswordEncoder, etc).
1
u/MaDpYrO Jan 11 '26
Clean architecture isn't about folders, you need to actually create a project structure so you can't cross reference between layers that aren't supposed to know about each other
1
u/PmMeCuteDogsThanks Jan 11 '26
AI slop