📚 Library Management API
A production‑grade REST API built with Spring Boot 3 that enables comprehensive library management with secure authentication and role-based permissions.
✨ Features
JWT Authentication – Users can register, log in, and receive a secure token
Role‑Based Access – ADMIN can manage books and categories; USER can view and review books
Book Management – Full CRUD for books (title, author, ISBN, publication year, category)
Reviews – Users can post, update, and delete their own reviews; admins can delete any review
Categories – Books are organised into categories (Fiction, Non‑Fiction, Science, History, Fantasy)
Pagination & Sorting – List endpoints support page, size, and sort parameters
Global Exception Handling – Consistent JSON error responses with validation details
🛠️ Tech Stack
Java 21, Spring Boot 3.5.16, Spring Security 6, JJWT, PostgreSQL, Spring Data JPA, Hibernate, Maven, Lombok, Jakarta Bean Validation
📡 API Endpoints
Authentication: POST /api/auth/register, POST /api/auth/login
Books: GET /api/books, GET /api/books/{id}, POST /api/books, PUT /api/books/{id}, DELETE /api/books/{id}
Reviews: POST /api/reviews, GET /api/reviews/book/{bookId}, GET /api/reviews/my-reviews, PUT /api/reviews/{reviewId}, DELETE /api/reviews/{reviewId}
📁 Project Structure
Clean layered architecture with separation of concerns: controller, service, repository, entity, DTO, security, config, and exception packages.
📚 What I Learned
Securing REST APIs with Spring Security and JWT
Working with JPA relationships (@ManyToMany, @OneToMany, @ManyToOne)
Implementing role‑based access control with @PreAuthorize
PostgreSQL integration in Spring Boot
Adding pagination and sorting with Spring Data Pageable
Creating a global exception handler for standardised error responses
