# dawipayandas/library-management-system architecture

> Architecture diagram of the GitHub repository dawipayandas/library-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dawipayandas/library-management-system
- Repository: https://github.com/dawipayandas/library-management-system

## Overview

##### Main Components
- Frontend (React Application)
- Contains UI components, pages (Home, Admin, Book Detail, Login/Signup, Profile, etc.), and utility modules (e.g., authentication, context providers).
- Manages user interactions, displays borrowing, reviews, upvote interactions, and handles routing for protected and public pages.
- Backend (Spring Boot Application):
- API Controllers: A set of REST controllers (e.g., AuthController, BookController, ReviewController, EmailController, etc.) that expose endpoints.
- Services: Business logic components (BookService, EmailService, ReviewService, RoleService, etc.) which process data.
- Repositories: Data persistence layer interfacing with the database (BookRepository, UserRepository, etc.).
- Models: Domain entities such as Book, User, Review, Upvote, and others representing the data structure.
- Security: JWT authentication and security configuration (JwtUtils, WebSecurityConfig, AuthEntryPointJwt, etc.) enforcing secure access and authorization.
- PDF Generation: Specific functionality indicated by PdfGenerator.
- Database:
- Not explicitly detailed in the file tree but implied through repositories and initialization of roles.
- Containerization (Docker):
- Dockerfiles in both Frontend and Backend for container builds.
- docker-compose.yml to orchestrate services (likely linking the backend, frontend, and possibly the database).

##### Relationships and Interactions
- The Frontend communicates with the Backend’s REST API endpoints.
- The Backend is organized in layered architecture:
- Controllers act as entry points, invoking Services.
- Services perform business logic and make calls to Repositories.
- Repositories interface with the Database to perform CRUD operations.
- Security:
- JWT based authentication flows should be depicted from login endpoint through token generation, validation in secure endpoints, and middleware (AuthTokenFilter).
- Dockerization:
- Containers for the Frontend, Backend, and (if applicable) Database.

##### Architectural Patterns and Design Principles
- MVC (Model-View-Controller) Pattern for the Backend.
- Layered architecture to separate concerns: Controller → Service → Repository.
- Microservice elements are not used here; instead, the monolithic backend is well-structured.
- JWT security design and centralized error handling via AuthEntryPointJwt.
- Separation of concerns on the Frontend via component-based architecture using React.

##### Relevant Technologies and Frameworks
- Java Spring Boot for the backend.
- Maven for the build tool (pom.xml, mvnw).
- React for the frontend (JavaScript/JSX).
- Docker & docker-compose for containerization.
- Likely a relational database (e.g., MySQL or similar) for persistence, given the repository structure.
- Security frameworks using JWT for authentication.

##### Final Checklist for the Principal Software Engineer
- Clearly delineate the boundaries between the frontend and backend layers.
- Internal interactions in the Spring Boot application (Controller-Service-Repository chain).
- Explicitly denote security flows (JWT authentication tokens, configuration points).

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction
    U("User"):::frontend

    %% Frontend Layer
    subgraph "Frontend Layer"
        F_UI("React UI Pages"):::frontend
        F_Login("Login/Signup Component"):::frontend
        F_Context("Context Management"):::frontend
        F_Book("Book Service API"):::frontend
        F_AuthUtil("Auth Utility"):::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B_Ctrl("API Controllers"):::controller
        B_Service("Service Layer"):::service
        B_Repo("Repository Layer"):::repository
        B_Models("Domain Models"):::utils
        B_Security("Security Components"):::security
        B_Pdf("PDF Generator"):::utils
    end

    %% Database
    DB("Database"):::database

    %% Docker / Containerization
    subgraph "Containerization"
        D_FE("Frontend Dockerfile"):::docker
        D_BE("Backend Dockerfile"):::docker
        D_DC("docker-compose.yml"):::docker
        D_DB("Database Container"):::database
    end

    %% Connections
    U -->|"interacts"| F_UI
    U -->|"triggers"| F_Login
    U -->|"triggers"| F_Context
    U -->|"triggers"| F_Book
    U -->|"triggers"| F_AuthUtil

    %% Frontend to Backend Communication
    F_UI -->|"calls"| B_Ctrl
    F_Login -->|"calls"| B_Ctrl
    F_Context -->|"calls"| B_Ctrl
    F_Book -->|"calls"| B_Ctrl
    F_AuthUtil -->|"calls"| B_Ctrl

    %% Backend internal flow
    B_Ctrl -->|"invokes"| B_Service
    B_Service -->|"processes"| B_Repo
    B_Repo -->|"accesses"| B_Models
    B_Repo -->|"queries"| DB
    B_Ctrl -->|"securedBy"| B_Security
    B_Service -->|"generates"| B_Pdf

    %% Docker orchestration links
    D_DC -->|"orchestrates"| D_FE
    D_DC -->|"orchestrates"| D_BE
    D_DC -->|"orchestrates"| D_DB
    D_FE -->|"hosts"| F_UI
    D_BE -->|"hosts"| B_Ctrl
    D_DB -->|"hosts"| DB

    %% Click Events for Frontend
    click F_UI "https://github.com/dawipayandas/library-management-system/tree/main/Frontend/src/Components/pages"
    click F_Login "https://github.com/dawipayandas/library-management-system/tree/main/Frontend/src/Components/LoginSignup"
    click F_Context "https://github.com/dawipayandas/library-management-system/tree/main/Frontend/src/Context"
    click F_Book "https://github.com/dawipayandas/library-management-system/blob/main/Frontend/src/services/BookService.jsx"
    click F_AuthUtil "https://github.com/dawipayandas/library-management-system/blob/main/Frontend/src/Components/utils/auth.js"

    %% Click Events for Backend
    click B_Ctrl "https://github.com/dawipayandas/library-management-system/tree/main/Backend/src/main/java/com/example/demo/controllers"
    click B_Service "https://github.com/dawipayandas/library-management-system/tree/main/Backend/src/main/java/com/example/demo/services"
    click B_Repo "https://github.com/dawipayandas/library-management-system/tree/main/Backend/src/main/java/com/example/demo/repositories"
    click B_Models "https://github.com/dawipayandas/library-management-system/tree/main/Backend/src/main/java/com/example/demo/models"
    click B_Security "https://github.com/dawipayandas/library-management-system/tree/main/Backend/src/main/java/com/example/demo/security"
    click B_Pdf "https://github.com/dawipayandas/library-management-system/blob/main/Backend/src/main/java/com/example/demo/PdfGenerator.java"

    %% Click Events for Docker
    click D_DC "https://github.com/dawipayandas/library-management-system/blob/main/docker-compose.yml"
    click D_FE "https://github.com/dawipayandas/library-management-system/tree/main/Frontend/Dockerfile"
    click D_BE "https://github.com/dawipayandas/library-management-system/tree/main/Backend/Dockerfile"

    %% Class Definitions for styling with colors
    classDef frontend fill:#F9E79F,stroke:#000,stroke-width:2px;
    classDef controller fill:#AED6F1,stroke:#000,stroke-width:2px;
    classDef service fill:#A9DFBF,stroke:#000,stroke-width:2px;
    classDef repository fill:#D2B4DE,stroke:#000,stroke-width:2px;
    classDef security fill:#F5B7B1,stroke:#000,stroke-width:2px;
    classDef utils fill:#FAD7A0,stroke:#000,stroke-width:2px;
    classDef docker fill:#D5F5E3,stroke:#000,stroke-width:2px;
    classDef database fill:#FADBD8,stroke:#000,stroke-width:2px;
```
