Architecture of Spring Boot

Spring Boot follows a layered architecture in which each layer communicates with its adjacent layer. The codebase of spring boot application is divided into four separate layers with distinctive responsibilities.

These four layers include :

Fig : Layered Architecture of Spring Boot

The above diagram shows that each layer of the architecture is communicating with its adjacent layer. 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.

Presentation layer :

  • This is the user interface of the application that presents the application’s features and data to the user.
  • 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 the request to the business layer for further processes.

Business Layer :

  • This layer contains the business logic that drives the application's core functionalities.
  • Like making decisions, calculations, evaluations, and processing the data passing between the other two layers.
  • It 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.

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.

Database Layer

  • This layer is responsible for interacting with databases to save and retrieve application data.
  • It may contain multiple databases. All the database related operations like CRUD (Create, Read/Retrieve, Update, and Delete) are performed in this layer.

Whenever a client makes a HTTP request or web request, it is 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.

Fig : Spring Boot Request Flow

When the client makes an HTTP request (GET or POST).

  • The request is forwarded to the controller. The controller maps the request and processes it.
  • The controller then calls the services from service layer if needed.
  • The business logic is performed in the service layer. Service layer is responsible for processing the data from the database that is mapped with the model or entity class through JPA.
  • Finally, JSP page is returned as a response to the client.