Spring Boot Architecture

Spring Boot Architecture: Spring Boot is an advanced version or project of the Spring framework. Along with the Spring framework, it also consists of third-party libraries and Embedded HTTP servers. It easily creates a production-grade, less time-consuming, and stand-alone applications based on the Spring framework.

The aim of Spring Boot is to completely remove the use of XML-based and annotation-based configuration in the applications. Using Spring Boot, we can also create an application with minimal fuss (less time and effort). By default, it offers most of the things, such as functions, procedures, etc.

In this tutorial, we are going to learn about the architecture of the Spring Boot framework. It follows the layered architecture and consists of four layers, as shown below.

  • Presentation Layer
  • Business Layer
  • Persistence Layer
  • Database Layer
Spring Boot Architecture

The above diagram shows that each layer of the architecture is directly communicating with the layer just above or below it, is because of the workflow. It means each layer only depends on its adjacent layer, so if we change the API of one layer, we just need to update the layers adjacent to it.

The brief description of the layers is given below.

1. Presentation layer

It is the front layer or top layer of the architecture, as it consists of views. It is used to translate the JSON fields to objects and vice-versa, and also handles authentication and HTTP requests. After completing the authentication, it passes it to the business layer for further processes.  

2. Business Layer

It handles all the business logic and also performs validation and authorization as it is a part of business logic. For example, only admins are allowed to modify the user’s account.

3. Persistence Layer

It contains all the storage logic, such as database queries of the application. It also translates the business objects from and to database rows.

4. Database Layer

The database layer consists of the database such as MySQL, Postgre, MongoDB, etc. It may contain multiple databases. All the database related operations like CRUD (Create, Read/Retrieve, Update, and Delete) are performed in this layer.

The implementation of the above layered architecture is performed in such a way:

The HTTP request or web requests are handled by the Controllers in the presentation layer, the services control the business logic, and the repositories handle persistence (storage logic). A controller can handle multiple services, a service can handle multiple repositories, and a repository can handle multiple databases.

Spring Boot Work Flow

The Spring Boot architecture is based on the Spring framework. So, it mostly uses all the features and modules of Spring-like Spring MVC, Spring Core, etc., except that there is no need for the DAO and DAOImpl classes.

The following diagram shows the workflow of Spring Boot.

Spring Boot Architecture
  • The client makes an HTTP request (GET or POST).
  • The request is forwarded to the controller, and it maps the request and processes it. It also calls the service logic if needed.
  • The business logic is performed in the service layer, and the logic is performed on the data from the database that is mapped with the model or entity class through JPA.
  • A JSP page is returned as a response to the client if no error has occurred.