# slyrackgo/uni_library architecture

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

- Interactive diagram: https://gitdiagram.com/slyrackgo/uni_library
- Repository: https://github.com/slyrackgo/uni_library

## Overview

##### Project type and purpose
- This is a full-stack university online library system.
- Backend: Spring Boot (Java) REST API with JWT security, file upload/download, caching, and MySQL persistence.
- Frontend: React.js single-page application.
- Static file server: Node.js/Express serves the React build.
- Database scripts under src/main/Database/product.sql for schema initialization.

##### File structure
- Top level
- Dockerfile, pom.xml, mvnw scripts → Maven-based Spring Boot service, containerizable.
- src/main/Database → SQL script for MySQL.
- src/main/frontend → React app (package.json, public/, src/).
- src/main/server → Node.js/Express static file server (server.js, package.json).
- src/main/java/com/example/uni_library → Spring Boot code organized by layers: Controllers, Services, Repositories, Exceptions, Security, Product subpackage, Mappings, CacheConfiguration.
- Test code under src/test/java confirms REST endpoints and application bootstrapping.

##### Key insights from README
- Two user roles: Admin and User, both interacting via REST API.
- Endpoints:
- /product/{id}/upload (POST multipart)
- /product/{id}/download (GET)
- JWT token-based authentication.
- Technologies: Spring Boot, Java, React.js, MySQL.

##### Main components & interactions
a. React Frontend
- Hosted on Node.js/Express static server.
- Requests data and files via HTTP(S) to the API.
b. Node.js Static Server
- Serves optimized React build (index.html, JS bundles, static assets).
- Optionally proxies API calls to Spring Boot service for CORS.
c. Spring Boot Backend
- Presentation layer: Controllers (ProductController, AttachmentController, Security controllers).
- Business layer: Services and ServiceImpl classes implementing commands/queries (CreateProductService, GetProductService, etc.).
- Data layer: Repositories (Spring Data JPA) interacting with MySQL.
- Security layer: JWT filters, CustomUserDetailsService, SecurityConfiguration.
- CacheConfiguration for in-memory caching of frequent queries.
- Exception handling via GlobalExceptionHandler.
d. MySQL Database
- Tables for products, attachments, users, students, customers.
- Initialized by product.sql.
e. File Storage
- Local filesystem or configured storage location holds uploaded book files.
f. External/Infra services (optional)
- Docker container runtime, Maven build environment.

##### Architectural patterns & design principles
- Layered architecture (Controller → Service → Repository).
- Command and Query separation: Commands (upload, delete), Queries (get, search).
- DTO mapping via ModelMapperConfig.
- Centralized exception handling.
- Token-based stateless authentication with JWT filter chain.
- Static resource hosting decoupled from API.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    Browser["Web Browser"]:::client
    React["React SPA"]:::client
    Browser --> React

    %% Static Hosting
    Node["Node.js Express Server"]:::compute
    React -->|Static GET| Node
    Node --> React

    %% API Server
    API["Spring Boot API"]:::compute
    React -->|API calls| API

    subgraph "API Server Internal"
        JwtFilter["JwtAuthenticationFilter"]:::security
        API --> JwtFilter

        %% Controllers
        ProdCtrl["ProductController"]:::controller
        AttCtrl["AttachmentController"]:::controller
        HeadCtrl["HeaderController"]:::controller
        LoginCtrl["LoginController"]:::controller
        CreateUserCtrl["CreateNewUserController"]:::controller
        SecCtrl["SecurityController"]:::controller

        JwtFilter --> ProdCtrl
        JwtFilter --> AttCtrl
        JwtFilter --> HeadCtrl
        JwtFilter --> LoginCtrl
        JwtFilter --> CreateUserCtrl
        JwtFilter --> SecCtrl

        %% Service Layer
        subgraph "Services"
            CreateProd["CreateProductService"]:::service
            GetProd["GetProductService"]:::service
            UpdateProd["UpdateProductService"]:::service
            DeleteProd["DeleteProductService"]:::service
            SearchProd["SearchProductService"]:::service
            AttachmentService["AttachmentService"]:::service
        end

        ProdCtrl --> CreateProd
        ProdCtrl --> GetProd
        ProdCtrl --> UpdateProd
        ProdCtrl --> DeleteProd
        ProdCtrl --> SearchProd
        AttCtrl --> AttachmentService
        LoginCtrl --> AttachmentService
        CreateUserCtrl --> AttachmentService
        SecCtrl --> AttachmentService

        %% Repositories
        subgraph "Repositories"
            ProdRepo["ProductRepository"]:::repo
            AttRepo["AttachmentRepository"]:::repo
            StuRepo["StudentRepository"]:::repo
            UserRepo["CustomUserRepository"]:::repo
        end

        CreateProd --> ProdRepo
        GetProd --> ProdRepo
        UpdateProd --> ProdRepo
        DeleteProd --> ProdRepo
        SearchProd --> ProdRepo
        AttachmentService --> AttRepo

        %% Persistence & Storage
        MySQL["MySQL Database"]:::persistence
        FileStore["File Storage Volume"]:::persistence

        ProdRepo -->|JDBC| MySQL
        AttRepo -->|JDBC| MySQL
        StuRepo -->|JDBC| MySQL
        UserRepo -->|JDBC| MySQL
        AttachmentService --> FileStore
    end

    %% Click Events
    click React "https://github.com/slyrackgo/uni_library/tree/master/src/main/frontend"
    click Node "https://github.com/slyrackgo/uni_library/tree/master/src/main/server"
    click API "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/UniLibraryApplication.java"
    click ProdCtrl "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Product/ProductController.java"
    click AttCtrl "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/AttachmentController.java"
    click HeadCtrl "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Product/headers/HeaderController.java"
    click LoginCtrl "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Security/JWT/LoginController.java"
    click CreateUserCtrl "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Security/CreateNewUserController.java"
    click SecCtrl "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Security/SecurityController.java"
    click AttachmentService "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/AttachmentService.java"
    click CreateProd "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Product/Services/CreateProductService.java"
    click GetProd "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Product/Services/GetProductService.java"
    click UpdateProd "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Product/Services/UpdateProductService.java"
    click DeleteProd "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Product/Services/DeleteProductService.java"
    click SearchProd "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Product/Services/SearchProductService.java"
    click ProdRepo "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/ProductRepository.java"
    click AttRepo "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/AttachmentRepository.java"
    click StuRepo "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Mappings/StudentRepository.java"
    click UserRepo "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Security/CustomUserRepository.java"
    click JwtFilter "https://github.com/slyrackgo/uni_library/blob/master/src/main/java/com/example/uni_library/Security/JWT/JwtAuthenticationFilter.java"
    click MySQL "https://github.com/slyrackgo/uni_library/blob/master/src/main/Database/product.sql"

    %% Styles
    classDef client fill:#E0F7FA,stroke:#006064;
    classDef compute fill:#E8EAF6,stroke:#283593;
    classDef controller fill:#FFF3E0,stroke:#E65100;
    classDef service fill:#E8F5E9,stroke:#2E7D32;
    classDef repo fill:#F3E5F5,stroke:#6A1B9A;
    classDef persistence fill:#FFEBEE,stroke:#B71C1C;
    classDef security fill:#ECEFF1,stroke:#455A64;
```
