# novojitsaha/library_mgmt_system architecture

> Architecture diagram of the GitHub repository novojitsaha/library_mgmt_system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/novojitsaha/library_mgmt_system
- Repository: https://github.com/novojitsaha/library_mgmt_system

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients and Documentation
    subgraph "Clients & Documentation"
        direction TB
        Clients["HTTP Clients<br>e.g., Web, Postman, Mobile"]:::external
        Swagger["Swagger UI"]:::docs
        Javadoc["Javadoc Site<br>(docs/apidocs)"]:::docs
    end

    %% Spring Boot Application
    subgraph "Spring Boot Application"
        direction TB
        App["LibraryApplication<br>«Spring Boot App»"]:::application
        subgraph "Web Layer"
            direction TB
            Controller["LibraryController<br>«Controller (Spring MVC REST)»"]:::controller
        end
        subgraph "Service Layer"
            direction TB
            Service["LibraryService<br>«Service (Spring @Service)»"]:::service
        end
        subgraph "Repository Layer"
            direction TB
            Repo["BookRepository<br>«Repository (Spring Data JPA)»"]:::repository
        end
        Exception["GlobalExceptionHandler<br>«@ControllerAdvice»"]:::service
        App -->|starts application| Controller
        Controller -->|calls| Service
        Service -->|uses| Repo
        Service -.->|throws exception| Exception
        Exception -->|returns ErrorResponse| Controller
    end

    %% Persistence and Config
    DB["H2 Database<br>«embedded, file-based»"]:::db
    Props["application.properties<br>(spring.datasource.url)"]:::config
    Book["Book Entity<br>«Model»"]:::model
    ErrorResponse["ErrorResponse DTO"]:::model

    %% Flows
    Clients -->|HTTP GET/POST /books| Controller
    Swagger -->|API docs| Controller
    Controller -->|parses input / returns response| Clients
    Repo -->|executes SQL| DB
    Repo -->|manages| Book
    App -->|configured by| Props
    Clients -.->|views docs| Javadoc

    %% Click Events
    click App "https://github.com/novojitsaha/library_mgmt_system/blob/main/src/main/java/com/crescendo/library/LibraryApplication.java"
    click Controller "https://github.com/novojitsaha/library_mgmt_system/blob/main/src/main/java/com/crescendo/library/web/LibraryController.java"
    click Service "https://github.com/novojitsaha/library_mgmt_system/blob/main/src/main/java/com/crescendo/library/service/LibraryService.java"
    click Repo "https://github.com/novojitsaha/library_mgmt_system/blob/main/src/main/java/com/crescendo/library/repository/BookRepository.java"
    click Exception "https://github.com/novojitsaha/library_mgmt_system/blob/main/src/main/java/com/crescendo/library/exception/GlobalExceptionHandler.java"
    click ErrorResponse "https://github.com/novojitsaha/library_mgmt_system/blob/main/src/main/java/com/crescendo/library/dto/ErrorResponse.java"
    click Book "https://github.com/novojitsaha/library_mgmt_system/blob/main/src/main/java/com/crescendo/library/model/Book.java"
    click Props "https://github.com/novojitsaha/library_mgmt_system/blob/main/src/main/resources/application.properties"
    click Javadoc "https://github.com/novojitsaha/library_mgmt_system/blob/main/docs/apidocs/index.html"

    %% Styles
    classDef controller fill:#D6EAF8,stroke:#1F618D,color:#1B4F72;
    classDef service fill:#D5F5E3,stroke:#28B463,color:#1D8348;
    classDef repository fill:#FDEDEC,stroke:#C0392B,color:#922B21;
    classDef db fill:#FADBD8,stroke:#CD6155,color:#943126;
    classDef docs fill:#F4ECF7,stroke:#8E44AD,color:#5B2C6F;
    classDef external fill:#E8E8E8,stroke:#7B7D7D,color:#566573;
    classDef application fill:#FEF9E7,stroke:#B7950B,color:#7D6608;
    classDef config fill:#EBF5FB,stroke:#5499C7,color:#21618C;
    classDef model fill:#EAF2F8,stroke:#2E86C1,color:#1B4F72;
```
