Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.

Project structure · Backend

Spring Boot project structure

Opens with credits

A REST API in Java with Spring Boot 4, PostgreSQL, Flyway and Testcontainers, organised by feature the way the Spring docs suggest. It grows from the Initializr scaffold to a service with JWT security, problem-detail errors, MapStruct DTOs, slice and integration tests, CI, containers and observability, and finally Modulith boundaries, contract and load tests. For students who know some Java and want to see how a real service is organised.

Curated by Tauseef FayyazIntermediate183 files and foldersSpring Boot 4.1, Spring Framework 7, Spring Security 7.1Checked October 2026
Explore the filesPick any file to see what it is, why it exists and when you add it.

How it grows

Each stage opens the explorer there

  1. 1Day 1What the scaffold and your first hour give you40 files and folders
  2. 2GrowingWhat a real app with features and tests adds+64 files and folders
  3. ProductionWhat running it for real users adds+36 files and foldersOpens with credits
  4. ExpertWhat a team needs to keep it healthy for years+43 files and foldersOpens with credits

How it is organised

  • Put the class with @SpringBootApplication in the root package (com.example.shop). Component scanning and entity scanning start there, so everything else must live below it.
  • Package by feature, not by layer: order/ holds the order controller, service, repository, entity, mapper and DTOs. The Spring Boot docs show this layout, and it keeps a change to one feature inside one folder.
  • Keep the layers inside each feature: controller (HTTP) calls service (rules and transactions) calls repository (database). Controllers never touch repositories, and features talk through public services or events, never through each other's tables.
  • Never return JPA entities from controllers. Map them to records with MapStruct so the API does not change every time a column does.
  • The database schema belongs to Flyway migrations, not to Hibernate. Set ddl-auto to validate and add a new V<n>__ file for every change; seed data lives in a separate location only the dev profile loads.
  • Configuration lives in application.yaml with profile files on top, bound to validated @ConfigurationProperties records, and secrets come from environment variables, never from committed files.
  • Test each layer with the cheapest test that proves it: Mockito for services, @WebMvcTest and @DataJpaTest slices, a few @SpringBootTest integration tests, all against real PostgreSQL with Testcontainers instead of H2.
  • Add Expert tooling (Modulith, ArchUnit, Pact, Gatling, mutation tests, release automation) when the team and the number of consumers grow, not on day one. One Maven module with enforced package boundaries goes a long way before a multi-module build pays off.

At the top of the project

Open one in the explorer for the full story

Learn more on Sefism

Roadmaps, cheat sheets and projects that go with Spring Boot.

See 11 more
Checked against 24 official sources, October 2026. If something has changed, the docs win.Show sources

Picked from the other libraries by shared topics.

Work with me

Stuck on something specific?

Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.

  • 1:1 Mentorship
  • Fresh Graduate Mentorship
  • Career Guidance

Brand deals, promos and partnerships: tauseeffayyaz@gmail.com