Skip to content

JKSJ15/LibraryAPI

Repository files navigation

📚 Library API - Spring Boot

REST API built with Spring Boot, following industry best practices for security, testing, and scalability.
The system simulates a library catalog, where users can browse books and administrators manage the catalog (create, update, and delete books).


🚀 Technologies

  • Java
  • Spring Boot
  • Spring Security
  • JWT (JSON Web Token)
  • Spring Data JPA
  • Hibernate
  • MySQL
  • Maven
  • Docker & Docker Compose
  • Prometheus
  • Grafana
  • Springdoc OpenAPI (Swagger)
  • JUnit

🔧 Features

  • ✅ Full CRUD operations for books (admin only)
  • ✅ Public access for users to view books
  • ✅ Pagination and sorting
  • ✅ Filtering via query parameters (one filter at a time)
  • ✅ Authentication with JWT
  • ✅ Role-based access control (USER / ADMIN)
  • ✅ Data validation with Bean Validation
  • ✅ DTO pattern for request/response
  • ✅ Global exception handling
  • ✅ Unit tests (Controller, Service, Repository, JWT Service)
  • ✅ Integration tests (including JWT and security)
  • ✅ API documentation (Swagger/OpenAPI)
  • ✅ Monitoring with Prometheus
  • ✅ Metrics visualization with Grafana
  • ✅ Dockerized environment

🧩 Architecture

The application follows a layered architecture, ensuring clear separation of concerns:

Controller → Service → Repository → Database
      ↓
     DTO
      ↓
 Security (JWT)
      ↓
Exception Handler
      ↓
 Actuator → Prometheus → Grafana

📁 Project Structure

src/
├── main/
│   ├── java/library/com/
│   │   ├── configurations/
│   │   ├── controller/
│   │   ├── dto/
│   │   ├── entity/
│   │   ├── exceptions/
│   │   ├── repository/
│   │   ├── service/
│   │   └── ComApplication.java
│   └── resources/
│       └── application.properties
│
├── test/
│   ├── java/library/com/
│   │   ├── configurations/
│   │   ├── controller/
│   │   ├── integration/
│   │   ├── repository/
│   │   ├── service/
│   │   └── util/
│   └── resources/
│       └── application-test.properties

🔐 Authentication & Authorization

  • Stateless authentication using JWT
  • User registration and login
  • Protected routes with Spring Security

Roles:

  • USER → can view books
  • ADMIN → can create, update, and delete books

Example:

Authorization: Bearer YOUR_TOKEN

📄 Pagination & Filtering

Example:

GET /books?page=0&size=10&sort=title,asc

Available filters (single use only):

  • title → partial, case-insensitive search
  • author → filter by author (case-insensitive)
  • genre → filter by genre

⚠️ Only one filter can be applied per request.


⚠️ Validation & Business Rules

  • Required fields (e.g., title, author, description, status)
  • Publication date cannot be in the future
  • ID is automatically generated by the database
  • Text search is partial and case insensitive

🧪 Testing

The project includes comprehensive test coverage:

Unit tests

  • Controller
  • Service
  • Repository
  • JWT Service

Integration tests

  • Full application flow
  • JWT authentication
  • Security validation

📊 Monitoring

Metrics endpoint:

/actuator/prometheus
  • Prometheus collects application metrics
  • Grafana provides visualization dashboards

📚 API Documentation

Documentation is automatically generated using Springdoc OpenAPI.

Access:

http://localhost:8080/swagger-ui/index.html

Features:

  • Interactive endpoint testing
  • Request/response visualization
  • Clear API contract

🐳 Docker

Run the full environment using Docker:

mvn clean package
docker compose up --build

▶️ How to Run

1. Clone the repository

git clone https://github.com/JKSJ15/libraryAPI.git

2. Navigate to the project

cd libraryAPI

3. Configure the database

Edit application.properties

4. Run the application

./mvnw spring-boot:run

💡 About the Project

This project was built to simulate a real-world library system, where users can explore a book catalog and administrators manage the collection.

It focuses on applying professional back-end concepts such as:

  • Security with JWT
  • Layered architecture
  • Testing strategies
  • Monitoring and observability

Using Java and Spring Boot.

About

An API that helps organize a bookstore catalog.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors