If you are working on projects, it is very important to have proper folder structure and files. This is very important and we should do this in very initial phase of project. In this blog, will explain you the best standard practice and files for spring boot project. Learn how to integrate standard ways and practices for making your project efficient and developer friendly. Proper managing spring boot project will help all developers to follow standard practice. In this blog, i will share my personal experience for spring boot project. So let’s get started.

Best Folder Structure in Spring Boot Project

Best Folder Structure in Spring Boot Project

Structure for Java Code

In spring boot, there are different ways to structured the project. Mainly there are different ways for optimizing the project to work in efficient way. We can create folder layout in two different ways:

πŸ”΄ Best practice for Django Proje...
πŸ”΄ Best practice for Django Project Working Directory Structure 2020

1. Structure Layout by Features

com
 +- packagename
     +- projectname
         +- Application.java
         |
         +- User
         |   +- User.java
         |   +- UserController.java
         |   +- UserService.java
         |   +- UserRepository.java
         |
         +- order
             +- Order.java
             +- OrderController.java
             +- OrderService.java
             +- OrderRepository.java

2. Structure Layout by Layer

com
 +- packagename
     +- projectname
         +- Application.java
         |
         +- models
         |   +- User.java
         |   +- Order.java
         |
         +- controllers
         |   +- OrderController.java
         |   +- UserController.java
         |
         +- services
         |    +- UserService.java
         |    +- OrderService.java
         |
         +- repositories
         |    +- UserRepository.java
         |    +- OrderRepository.java   
         |
         +- configs
         |
         +- utils

In personally follow, Structure by Layout, which is best structure in my opinion. Some description regarding the folders

  1. models – as name, we can keep models/domain
  2. controllers – for keeping all controllers
  3. services – for all services
  4. repositories – keep all repositories
  5. configs – configurations like WebAppSercurity.java
  6. utils – feature specifics

Structure for Resource / Template / Static files in Spring Boot

Now we have created a structured folders for java code, it time for resource folders, where we keep our templates and static files. By default, you get templates and static folder in resources. In static you can create different assets folders and in template different sections like frontend and admin or backend. In templates, if you are using thymeleaf dependency, then you can keep fragments folder, where you keep parts of htmls.

β”œβ”€β”€ java (....)
└── resources
    β”œβ”€β”€ application.properties
    β”œβ”€β”€ static
    β”‚Β Β  └── assets
    β”‚Β Β      β”œβ”€β”€ admin
    β”‚Β Β      └── frontend
    └── templates
        β”œβ”€β”€ admin
        β”‚Β Β  β”œβ”€β”€ dashboard.html
        β”‚Β Β  └── fragments
        └── frontend
            β”œβ”€β”€ 403.html
            β”œβ”€β”€ about-us.html
            β”œβ”€β”€ fragments
            └── homepage.html