This is the REST API for a Library Management System built with Java Spring Boot.
It supports user authentication, book management, and loan tracking — fully secured with JWT role-based access.
The project is deployed live on AWS and includes a full CI/CD pipeline with automated testing.
- Java 17+
- Spring Boot 3
- Spring Security (JWT Resource Server)
- Spring Data JPA (Hibernate)
- H2 Database (In-memory)
- Maven
- JUnit 5 & Mockito (Testing)
- Docker & Docker Hub (Containerization)
- AWS EC2 (Cloud Deployment)
- GitHub Actions (CI/CD)
- OpenAPI / Swagger (API Documentation)
- View all books
- Search by title, author, and availability
- Create, update, delete (Admin only)
- Register new users (requires Admin approval)
- Admin can view/update/delete users
- Role-based access:
ADMINorUSER - Secure Login returning a JWT token
- Users can borrow and return books
- Smart Security: Users can only view their own loans; Admins can view all.
- History tracking of returned books
The API is fully documented using Swagger UI (OpenAPI). You can explore endpoints and test them directly in the browser.
Tip: To test secured endpoints in Swagger:
- Login using the
/auth/loginendpoint to get a Token.- Click the Authorize button at the top of the Swagger page.
- Paste the token as:
Bearer <your-token>.
This project uses a fully automated CI/CD Pipeline using GitHub Actions.
- Push to Main: Code is pushed to the GitHub repository.
- Automated Testing:
mvn testruns Unit and Integration tests. - Build & Package: Maven builds the JAR file.
- Containerization: A Docker image is built and pushed to Docker Hub.
- Deployment: GitHub Actions connects to AWS EC2 via SSH, pulls the latest image, and restarts the container.
The project maintains high code coverage using JUnit 5 and Mockito.
The test suite includes:
- Repository Tests: Integration tests using H2 to verify database queries.
- Controller Tests: Slice tests using
MockMvcfor endpoints and validation. - Security Tests: Verification of Role-based access control (RBAC).
Run tests locally:
mvn test- Authentication: Stateless JWT (JSON Web Token)
- Authorization: Method-level security (@PreAuthorize, @PostAuthorize)
- Protection: - Passwords are encrypted using BCrypt.
- Unapproved users are locked out until Admin approval.
- Users cannot access data belonging to others.
You can use Postman or cURL:
POST /auth/register
{
"name": "Test User",
"email": "test@example.com",
"password": "password123"
}POST /auth/login
{
"email": "admin@example.com",
"password": "adminPass123"
}💡 This returns a JWT. Include it in the Authorization header:
Authorization: Bearer <your-token>
# From the root of the project
mvn spring-boot:run📌 Main API base path:
http://localhost:8080/api
OR
http://13.53.36.164/api
This project is open-source and free to use under the MIT License.