How caolib/book_management_system works
Project Type & Purpose
• This is a full-stack, front/backend-separated application.
• The provided repo is the backend service, written in Java17 + Spring Boot 3.0.9, exposing RESTful APIs for book lending operations.
• It relies on MySQL for persistent storage and Redis for token management (JWT expiration).
Top-Level Architecture
• In the backend, model a layered (MVC) architecture:
a. Web Layer
b. Service Layer
c. Persistence Layer
• Two infrastructure components: MySQL Database and Redis Cache.
Main Components & Their Groupings
a. Web Layer ( Controllers + Interceptors + Exception Handler )
• Controllers: AdminController, LoginController, BookController, BorrowController, ReaderController, etc.
• Custom Annotation: @MyController (for any special controller logic).
• Interceptors: JwtTokenInterceptor (JWT auth), LoggingInterceptor (request logging).
• GlobalExceptionHandler: handles all uncaught exceptions and maps to HTTP responses.
• Configuration: WebMvcConfig (registers interceptors).
b. Service Layer
• Interfaces: AdminService, BookService, BorrowService, ReaderService.
• Implementations: AdminServiceImpl, BookServiceImpl, etc.
• Contains business logic, transaction management, calls DAOs (mappers).
c. Persistence Layer (MyBatis-Plus)
• Mappers: AdminMapper, BookMapper, BorrowMapper, ReaderMapper.
• XML mappings in src/main/resources/mapper/*.xml for custom SQL.
• Entities/DTOs/VOs: under domain/entity, domain/dto, domain/vo.
d. Infrastructure
• MySQL: persistent storage for books, readers, borrows, admins.
• Redis: token blacklist/expiry store for JWTs.
• Config classes: MybatisConfig, RedisConfig.
• Utility classes: JwtUtils, MyUtils, ThreadLocalUtil, Advice.
Data Flows & Interactions
1. Frontend → (HTTP/JSON) → Spring Boot controllers
2. Controller → (calls) → Service Layer
3. Service → (invokes) → MyBatis Mapper → MySQL (via JDBC)
4. Service or Interceptor → (reads/writes) → Redis for token operations
5. Exceptions bubble up → GlobalExceptionHandler converts to HTTP error response
Architectural Patterns & Design Principles
• Layered Architecture (Separation of Concerns)
• RESTful API style in Controllers
• Interceptor Chain for cross-cutting concerns (auth, logging)
• Configuration Classes for externalizing infra setup
• Exception Handling centralized
• DTO/VO pattern for request/response payloads
• [ ] Controllers, Interceptors, Exception Handler inside Web Layer
• [ ] Services grouped in Service Layer
• [ ] Mappers & Entities in Persistence Layer
• [ ] Config classes, Utilities as side modules