How novojitsaha/library_mgmt_system works
Project Type and Purpose
• This is a backend RESTful Library Management System built with Java and Spring Boot.
• It exposes HTTP endpoints for adding/removing books, searching (by id, title, author), and borrowing/returning books.
• Data is persisted in an embedded H2 database stored in a local file (library_db).
High-Level Architecture Components
a. Clients / Consumers
• HTTP clients (e.g., web front-ends, Postman, mobile apps) and Swagger UI for API exploration.
b. Spring Boot Application
• LibraryController (REST endpoints)
• LibraryService (business logic)
• BookRepository (data access via Spring Data JPA)
• GlobalExceptionHandler (cross-cutting exception handling)
c. Persistence
• Embedded H2 database, file-based.
d. Documentation
• Swagger UI for live API docs.
• Javadoc site under docs/apidocs.
Component Relationships and Data Flow
1. Client issues an HTTP request to a REST endpoint (e.g., POST /books, GET /books/search?id=...).
2. Request lands in LibraryController. Controllers parse inputs into DTOs or primitives.
3. Controller calls LibraryService, passing parameters or DTOs.
4. LibraryService implements business rules (e.g., check if book exists, apply borrow/return logic).
5. LibraryService uses BookRepository to perform CRUD operations against the H2 database.
6. BookRepository (Spring Data JPA) translates repository calls into SQL queries executed on the H2 database.
7. Results flow back up: Repository → Service → Controller → Client.
8. Any exception (e.g., BookNotFoundException, InvalidBorrowRequestException) is caught by GlobalExceptionHandler and transformed into an ErrorResponse DTO.
Architectural Patterns and Principles
• Layered (Controller → Service → Repository) separation of concerns.
• RESTful API design.
• Exception handling via @ControllerAdvice (GlobalExceptionHandler).
• Embedded database for zero-configuration persistence.
• Maven for build, dependency management, and Javadoc generation.