Spring Boot Project Architecture
Java Spring Boot REST API Project generally is a 3 layer architecture. Each Layer is designed for a dedicated purpose. Using this architecture in the project, developers can get a well organised code.
Details of each layer is explained below –
- Controller Layer – Primary responsibility of this layer is to interact with the consumer applications such as REST Client, Browser or any third party applications. Controller layer receives REST Requests, and after the processing REST Response is sent back to client via controller layer.
Controller Layer is capable to accept all the HTTP Verbs such as GET, POST, PUT, DELETE, PATCH, HEAD.
- Service Layer – Main purpose of this layer is to receive processing requests from controller layer, perform the required business logic and then send to Repository layer for further processing. Once response is received from Repository layer, it send back the response to controller layer. Service layer is also called as Business layer.
Service Layer doesn’t interact with HTTP Verbs such as GET, POST, PUT, DELETE, PATCH, HEAD.
- Repository Layer – It is also called Database layer, because this layer interacts with database. On receiving processing requests from service layer, repository layer interacts with database gets the response from database and returns to Service layer.
Repository Layer doesn’t interact with HTTP Verbs such as GET, POST, PUT, DELETE, PATCH, HEAD.
Best practice is to structure REST API code in such a way that all three layers are separated properly in the code and a clean code is developed.
Code Structure
Refer below code structure for designing Java Spring Boot REST API project –
Please refer GITHUB repository below –
https://github.com/thinkconstructive/rest-api-spring-boot-demo/tree/master
Video explanation of the 3 layer architecture is available here
Nice website.
Thanks