DEV Community

Cover image for Spring Boot Architecture
Maddy
Maddy

Posted on • Updated on • Originally published at techwithmaddy.com

Spring Boot Architecture

Spring Boot is a more user-friendly version of the Spring Framework. With Spring Boot, you can create autonomous and easy to run applications.

WHAT IS THE DIFFERENCE BETWEEN SPRING AND SPRING BOOT?

If you've ever tried to write a Java application time ago, you would have noticed how much work you had to do to perform database operations. It's a tiring process!

The Spring Framework simplifies these operations, thanks to the Spring JDBC module.

Spring is the combination of multiple sub-frameworks. It has many modules, for example, Spring MVC, Spring JDBC, Spring AOP, Spring ORM, and Spring Test. The core feature of the Spring Framework is Dependency Injection.

Even though Spring has made the development of Java applications easier, I think that it is vast and complicated to master. In the past, I tried to learn the Spring Framework from scratch, and I found it a long experience. This is where Spring Boot comes in handy, though. 😁

WHAT IS SPRING BOOT?

Spring Boot is built on top of the Spring Framework. It's a more automated and simplified version of Spring. Spring Boot makes it easy to create an up and running application in a few minutes. You go to Spring Initializr

springInitializr.png

And the website will generate the application for you in an instant.

If you're undecided on whether to learn Spring or Spring Boot, I'd say to at least know the basics of the Spring Framework and then jump onto Spring Boot.

Now let's talk about Spring Boot Architecture.

SPRING BOOT ARCHITECTURE

Spring Boot Architecture has four layers:

  • Presentation Layer
  • Business Layer
  • Persistence Layer
  • Database Layer

Spring Boot Architecture.png

PRESENTATION LAYER

This layer is at the top of the architecture. This tier is responsible for:

✔️ Performing authentication.

✔️ Converting JSON data into an object (and vice versa).

✔️ Handling HTTP requests.

✔️ Transfering authentication to the business layer.

The presentation layer is the equivalent of the Controller class. The Controller class handles all the incoming REST API requests (GET, POST, PUT, DELETE, PATCH) from the Client.

BUSINESS LAYER

The business layer is responsible for:

✔️ Performing validation.

✔️ Performing authorization.

✔️ Handling the business logic and rules.

This layer is the equivalent to the Service class. It's where we handle the business logic. If you're wondering what do we mean by "business logic", I found an interesting discussion on StackExchange. In short, the business logic in software engineering is where we decide what the software needs to do. An example of this is validation. If you are ever requested to validate something, this needs to happen inside the Service class.

The Business layer communicates with both the Presentation layer and the Persistence Layer.

PERSISTENCE LAYER

This layer is responsible for:

✔️ Containing storage logic.

✔️ Fetching objects and translating them into database rows (and vice versa).

This layer is the equivalent of the Repository interface. We write database queries inside this interface.

The Persistence layer is the only layer that communicates with the Business layer and the Database layer.

DATABASE LAYER

This layer is responsible for:

✔️ Performing database operations (mainly CRUD operations).

This layer is simply the actual database that you decide to use to build your application.

SPRING BOOT WORKFLOW

Spring Boot workflow.png

Spring Boot workflow acts like this:

  1. The Client makes an HTTP request.
  2. The Controller class receives the HTTP request.
  3. The Controller understands what type of request will process, and then it deals with it.
  4. If it is needed, it calls the service class.
  5. The Service Class is going to handle the business logic. It does this on the data from the database.
  6. If everything goes well, we return a JSP page.

Thanks for reading my article. Until next time! 👋🏾

P.S: did you enjoy this article? If so, I invite you to subscribe to my newsletter. I share interesting stuff around career development, software engineering and technical writing.

FURTHER READING:

Top comments (18)

Collapse
 
jvmlet profile image
Furer Alexander • Edited

I stopped reading after this paragraph :

Spring Boot Architecture has four layers:

Presentation Layer
Business Layer
Persistence Layer
Database Layer

You missed the whole idea of Spring boot !!!

Collapse
 
maddy profile image
Maddy

Thank you for your comment. What did I miss, precisely?

Collapse
 
jvmlet profile image
Furer Alexander • Edited

You missed the whole point of Spring boot.
It's not mvc + persistency.
This is about auto-configuration of almost each and every existing technology /stack. From simple rest service with embedded tomcat or netty to the complex application (messaging middleware, scheduling, retry, load balancing, caching, service registration and discovery, various communication layers, logging.. Should I continue?

Thread Thread
 
maddy profile image
Maddy

Sure, you are more than welcome to continue. 😁

I agree with your comment, and I'm fully aware that there is more than just "mvc + persistency".

For this article, I chose to focus on giving an overall understanding of the Spring Boot Architecture.

I blog frequently and I'll cover more Spring Boot topics in my next articles (this is my very first article about Spring Boot).

Also, let's not forget that in software engineering you don't need to know everything, but just enough to get you going.

We start small and we learn more as we go. 😊

Thread Thread
 
jvmlet profile image
Furer Alexander • Edited

overall understanding of the Spring Boot Architecture is about files named spring.factories. No more nor less.

Thread Thread
 
maddy profile image
Maddy

Thanks @jvmlet 😁

Collapse
 
maddy profile image
Maddy

Darling, I'm glad you find this article helpful! 😊

Collapse
 
nermin_karapandzic profile image
Nermin Karapandzic

Huh? What you described is maybe an architecture that you use when working on your apps, spring boot has nothing to do with this.
You can have the same architecture using just spring...
Spring boot is about autoconfiguration and that's all it is.

Collapse
 
skalaidjian profile image
shant Kalaidjian

Great Work, big thank.

Collapse
 
maddy profile image
Maddy

Thank you! 💗

Collapse
 
mdmozammilanwar profile image
Md Mozammil Anwar

Great way of writing its super amazing, kudos 👏🎊🎉🎈

Collapse
 
maddy profile image
Maddy

Thank you darling, I'm glad you like the article! ❤️

Collapse
 
diegovgodoy profile image
Diego Vargas

excellent article Maddy... greetings from Argentina

Collapse
 
maddy profile image
Maddy • Edited

Thank you darling. I hope you've found this helpful. Greetings from London! 😁

Collapse
 
ariefluthfi79 profile image
Arief Luthfi

Keep it up, love it

Collapse
 
maddy profile image
Maddy • Edited

Will do! Thanks @ariefluthfi79 . ❤️

Collapse
 
oscarromero profile image
Oscar Romero

Keep posting, I like your work. Would be great if you create a series of posts to have a path.

Collapse
 
maddy profile image
Maddy

That's the plan. Thanks for your comment @oscar Romero!