Architecture๏
MVC Pattern๏
SpringBootLibrary follows the classic Model-View-Controller (MVC) pattern, adapted for a REST API:
HTTP Client (Browser / Postman)
โ
โผ
โโโโโโโโโโโโโโโโโโโโโ
โ Controller โ โ Handles HTTP requests & responses
โ (REST endpoints) โ com.example.library.controller
โโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโ
โ Service โ โ Business logic
โ โ com.example.library.service
โโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโ
โ Repository โ โ Spring Data JPA interfaces
โ โ com.example.library.repository
โโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโ
โ Database (MySQL) โ โ Entities via Hibernate / JPA
โ H2 (tests) โ com.example.library.model
โโโโโโโโโโโโโโโโโโโโโ
Package Structure๏
Package |
Responsibility |
|---|---|
|
REST endpoints โ |
|
Business logic โ |
|
JPA repositories โ CRUD + custom queries |
|
JPA entities โ |
Key Design Decisions๏
Spring Data JPA is used for the persistence layer. Repository interfaces extend JpaRepository, providing standard CRUD operations without boilerplate code.
H2 in-memory database is activated automatically in the test Spring profile, so unit and integration tests run without requiring a real MySQL instance (except when using @SpringBootTest with the integration Maven profile, which spins up a MySQL Docker container via GitHub Actions).
Springdoc OpenAPI auto-generates an interactive Swagger UI from the controller annotations at runtime, always reflecting the current API surface.
Static Resources๏
The frontend is a plain HTML + JavaScript + CSS single-page application located at:
src/main/resources/static/
โโโ index.html
โโโ app.js
โโโ style.css
It communicates with the backend over REST, keeping the view layer decoupled from the server.