# mthang1201/webook architecture

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

- Interactive diagram: https://gitdiagram.com/mthang1201/webook
- Repository: https://github.com/mthang1201/webook

## Overview

##### Project Overview & Main Components
- Project Type & Purpose:
– WeBook is a desktop library management application built using Java and JavaFX.
– It supports functionalities such as CRUD operations, authentication, suggestions, notifications, and comments.
– It connects to a MySQL database for persistent storage.

- Main Components to Represent:
– User Interface (UI) Layer:
▪ JavaFX views defined by FXML files (in src/main/resources/org/uet/library_management/ui and subdirectories)
▪ Controllers managing UI logic (located in src/main/java/org/uet/library_management/ui and its subpackages such as auth, admin, search, settings)
– Core Business Logic Layer:
▪ Core entities (e.g., Book, Thesis, User, Loan, etc.) found in src/main/java/org/uet/library_management/core/entities
▪ Services that perform business operations generally found in src/main/java/org/uet/library_management/core/services
▪ Repositories handling data access, including MySQLRepository and specific document repositories (in src/main/java/org/uet/library_management/core/repositories)
– API and Utility Components:
▪ API packages for search, sort, and image handling that abstract functionalities like searching and thumbnail generation (under src/main/java/org/uet/library_management/api)
▪ Utility and tool classes (e.g., SessionManager, Mediator, ImageCacheManager) used to facilitate miscellaneous support tasks.
– Database & Connectivity:
▪ ConnectJDBC.java handles MySQL connection setup
▪ The README instructs setting up MySQL with provided SQL dump files located in the resources/data directory.
– Testing Layer:
▪ The tests directory (src/test) contains unit tests verifying components like the JDBC connection, API methods, and core services.

##### Relationships & Interactions
– The UI Layer interacts with the Controllers, which in turn call services from the Core Business Logic.
– The Services interact with the Repositories for CRUD operations against the MySQL database.
– The API modules (search, image, sort) integrate with both the UI (to provide dynamic content and search suggestions) and the core layer (providing specialized functionalities).
– Utility classes support various layers, for example, session management and layout utilities that are accessed by controllers.

##### Architectural Patterns & Design Principles
- Layered Architecture:
– Present the system as several layers (UI, Business Logic, Data Access, and Utilities) to emphasize separation of concerns.
- Modularization:
– Highlight the modular approach by drawing separate blocks for API services (search, sort, image) and showing their roles in extending core functionalities.
- MVC-ish Approach:
– Even though it is desktop and not web-based, note the division between controllers (handling user interactions), FXML UIs (views), and underlying model entities.
- Dependency Injection / Loose Coupling:
– Indicate how services depend on repositories and APIs, showcasing potential use of dependency injection in managing these relationships.

##### Technologies and Frameworks
- JavaFX for UI components
- MySQL as the persistent storage (connectivity via ConnectJDBC)
- Maven as the build and dependency management tool
- Integration of third-party tools such as Lombok (for boilerplate reduction)
- Testing frameworks (likely JUnit or equivalent, as seen in the testing directories)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        UI_FXML["FXML Views"] 
        UI_Ctrl["UI Controllers"]
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        BL_Entities["Core Entities"]
        BL_Services["Core Services"]
    end

    %% Data Access & Connectivity Layer
    subgraph "Data Access & Connectivity"
        DA_Repos["Data Repositories"]
        DA_Connect["ConnectJDBC"]
        DA_SQL["SQL Dump Files"]
        DA_DB["MySQL Database"]
    end

    %% API & Utilities Layer
    subgraph "API & Utilities Layer"
        API_Mod["API Modules"]
        Util_Tools["Utility Tools"]
    end

    %% Testing Layer
    subgraph "Testing Layer"
        Test_Unit["Unit Tests"]
    end

    %% Relationships - UI and Business Logic
    UI_FXML -->|"loads"| UI_Ctrl
    UI_Ctrl -->|"invokes"| BL_Services

    %% Relationships - Business Logic and Data Access
    BL_Services -->|"queries"| DA_Repos
    DA_Repos -->|"uses"| DA_Connect
    DA_Connect -->|"connects to"| DA_DB
    DA_SQL ---|"populates"| DA_DB

    %% Relationships - API & Utilities interactions
    UI_Ctrl -->|"fetches"| API_Mod
    API_Mod -->|"provides"| UI_Ctrl
    API_Mod -->|"assists"| BL_Services
    UI_Ctrl -->|"utilizes"| Util_Tools

    %% Relationships - Testing
    Test_Unit -->|"verifies"| BL_Services
    Test_Unit -->|"tests"| API_Mod
    Test_Unit -->|"checks"| DA_Connect

    %% Click Events
    click UI_FXML "https://github.com/mthang1201/webook/tree/master/src/main/resources/org/uet/library_management/ui"
    click UI_Ctrl "https://github.com/mthang1201/webook/tree/master/src/main/java/org/uet/library_management/ui"
    click BL_Entities "https://github.com/mthang1201/webook/tree/master/src/main/java/org/uet/library_management/core/entities"
    click BL_Services "https://github.com/mthang1201/webook/tree/master/src/main/java/org/uet/library_management/core/services"
    click DA_Repos "https://github.com/mthang1201/webook/tree/master/src/main/java/org/uet/library_management/core/repositories"
    click DA_Connect "https://github.com/mthang1201/webook/blob/master/src/main/java/org/uet/library_management/ConnectJDBC.java"
    click DA_SQL "https://github.com/mthang1201/webook/tree/master/src/main/resources/org/uet/library_management/data"
    click API_Mod "https://github.com/mthang1201/webook/tree/master/src/main/java/org/uet/library_management/api"
    click Util_Tools "https://github.com/mthang1201/webook/tree/master/src/main/java/org/uet/library_management/tools"
    click Test_Unit "https://github.com/mthang1201/webook/tree/master/src/test"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef business fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef data fill:#FFCC99,stroke:#000,stroke-width:2px;
    classDef apis fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef testing fill:#FFE4E1,stroke:#000,stroke-width:2px;

    class UI_FXML,UI_Ctrl ui;
    class BL_Entities,BL_Services business;
    class DA_Repos,DA_Connect,DA_SQL,DA_DB data;
    class API_Mod,Util_Tools apis;
    class Test_Unit testing;
```
