Hey guys in this post, we will discuss structuring Spring boot application and their best practices.
Read More:
- Check the Complete Spring Boot Tutorials [100+ Examples]
- Check the Complete Spring Boot and Thymeleaf Tutorial
- Check the Complete AWS Tutorial
- Check the Complete JavaServer Faces (JSF) Tutorial
- Check the Complete Spring Data JPA Tutorial
- Check the Complete Spring Security Tutorial
- Check the Javascript Projects for Beginners
- Check the Spring Boot JdbcTemplate Tutorials
Overview
Its always good practice to structure your Spring boot application while developing production grade applications. If we don’t structure it properly then its very difficult to maintain and search the files as our application grows. So today in this post, I will show you how I structure Spring boot application and I will tell you the best practices.
Note: This is my way of structuring the application, you can follow the same structure or you can change the structure as per your needs.

This is my typing Spring boot project structure. Let’s discuss these packages one by one in detail.
Base Package
Spring boot application always comes with base package, for example in.bushansirgur.springbootrestapi which contains the base class SpringbootrestapiApplication.java which contains the main() method. This is the starting point to spring boot application.
package in.bushansirgur.springbootrestapi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringbootrestapiApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootrestapiApplication.class, args);
}
}
Auth Package
This is the package in.bushansirgur.springbootrestapi.authmanage, where Login and Logout code is present.
AuthRequest.javais basically a POJO contains private fields such as username, email and passwordAuthController.javais basically accepts HTTP request for login and logoutAuthService.javais basically interface contains the business logic for authorizing and authenticate the user
Constants Package
This is the package in.bushansirgur.springbootrestapi.constants, where the contants and enums will be present.
ApplicationConstants.javais basically a class contains, public static final fields, which represents the constant variables used in the applicationSecurityConstant.javais basically an enum, contains the constant variables for security
Email Package
Assume that in your application, there is a email functionality then its better to keep it in a separate package in.bushansirgur.springbootrestapi.email
EmailService.javathis is basically an interface which contains methods for sending emails.
SendGridService.javathis is basically an implementation forEmailService, contains the implementation for sending emails.
Employee Package
Assume that you are building REST API for employee management then its always to good practice to keep all the employee functionality in one package in.bushansirgur.springbootrestapi.employee
EmployeeRequest.javathis is basically model class contains private fields, which accepts the form dataEmployeeResponse.javathis is also model class which contains the private fields, this is the final object that sent back to clientEmployeeEntity.javathis is basically entity class which is the used to persist the data to databaseEmployeeController.javathis is the employee controller which accepts HTTP requestsEmployeeService.javathis is an interface contains the business logic for employee resourceEmployeeDAO.javathis is an interface contains the database operations such as create, read, update and delete
FileUpload Package
Assume that in your application there is a file upload functionality then its better to keep all the file upload functionality code in one package in.bushansirgur.springbootrestapi.fileupload
FileService.javathis is an interface contains the abstract methods for uploading files to cloud or databaseAWSS3Service.javathis is an implementation forFileServicewhich contains the implementation for uploading files to AWS S3 bucket.
Security Package
This is the package in.bushansirgur.springbootrestapi.security, which contains the files for security related functionality.
SecurityConfig.javathis is the class where security configuration goes in.
Util Package
This is the package in.bushansirgur.springbootrestapi.util which contains the files for utility related functionality.
DateAndTimeUtil.javathis is the file which contains the util methods for date and timeJwtUtil.javathis is the file contains util methods for Json web tokens
Similarly, you can add more packages and classes as per your application needs. This is how I organize my spring boot application.
That’s it for this post, if you like this post, share this with your friends and colleagues or you can share this within your social media platform. Thanks, I will see you in our next post.
