# giabao1340/ql_thu_vien architecture

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

- Interactive diagram: https://gitdiagram.com/giabao1340/ql_thu_vien
- Repository: https://github.com/giabao1340/ql_thu_vien

## Overview

##### Project Type and Purpose
- QLThuVien is a desktop or possibly a web-based application (given the forms and Java Swing files) for managing a library system.
- Its functionality likely includes managing book states (borrowed, returned, lost), handling member states (active, blocked, suspended, etc.), and sending email communications through a factory-based email sender.
- The use of design patterns suggests that robust, maintainable, and scalable code architecture was a priority.

##### Main Components
a. Presentation (View) Layer:
- GUI components found in the “view” package (e.g., HomePage, LoginForm, BookForm, MemberForm, etc.).
- Form definitions (.form files) which indicate the UI design layout and user interactions.

b. Business Logic / Application Layer:
- Core application logic from packages such as “com.mycompany.qlthuvien”.
- Separate submodules using design patterns:
- Memento Pattern: Classes under “MemberMemento” (MemberMemento, MemberRestore) which handle state snapshots.
- Proxy Pattern: Classes under “ProxyMember” (BorrowingProxy, RealBookBorrowing, TicketBorrowing) for controlling access to borrowing functionality.
- Factory Method Pattern: Classes under “FactoryMethod” (EmailFactory, EmailSender, EmailTemplate, and various Email classes) to encapsulate email generation.
- State Pattern: Under “BorrowedTicketStates”, “bookstate”, and “memberState” packages, illustrate how the system maintains and transitions states for borrowed tickets, books, and members.
- Command Pattern: In the “command” package, include Command, CommandManager, and concrete command classes (like DeleteBookCommand) to encapsulate operations.

- “QLThuVien” main class which likely integrates these modules.

c. Data Access and Persistence:
- DAO classes from the “dao” package (BookDAO, BorrowedTicketDAO, MemberDao, etc.) for accessing the database.
- “DatabaseConnection” class which handles connections to the data store.
- “model” package (Book, BorrowedTicket, Member) as the core data objects exchanged between the application layers.

d. Infrastructure and Configuration:
- Project configuration elements like pom.xml which handles dependency management.
- Optionally, indicate the “sql” directory if scripts for database initialization or schema setup exist.
- Recognize the “target” directory as output of the build process (not necessarily part of the design but showing build artifacts).

##### Relationships and Interactions
- From the View Layer to the Business Logic when users trigger actions.
- From the Business Logic to the Data Access Layer (DAO) to fetch or persist data.
- From the Business Logic to the Mail components when an email is sent (via the Factory Method).
- Interactions among design pattern modules (e.g., the Proxy uses the RealBookBorrowing to handle specifics, the Memento keeps track of member states, while the State pattern governs the behavior of borrowed tickets and books).

##### Architectural Patterns and Principles
- Use of layered architecture with clear separation between GUI (view), business logic (including design pattern implementations), and data access layers.
- That the design patterns give the system flexibility (e.g., adding new email templates or new commands without major refactoring).
- Principles such as encapsulation, modularity, and separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        V("View Layer (GUI: HomePage, LoginForm, etc.)"):::presentation
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        M("QLThuVien Main"):::business
        MM("Memento Module"):::business
        P("Proxy Module"):::business
        EF("Email Factory Module"):::business
        TS("Ticket State Module"):::business
        BS("Book State Module"):::business
        C("Command Module"):::business
        MS("Member State Module"):::business
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        D("DAO Module"):::dataAccess
        MO("Model Objects"):::dataAccess
        DC("Database Connection"):::dataAccess
    end

    %% Infrastructure & Configuration
    subgraph "Infrastructure & Configuration"
        PX("pom.xml"):::infrastructure
        SQ("SQL Scripts"):::infrastructure
    end

    %% Relationships
    V -->|"triggers"| M

    M -->|"calls"| MM
    M -->|"calls"| P
    M -->|"calls"| EF
    M -->|"calls"| TS
    M -->|"calls"| BS
    M -->|"calls"| C
    M -->|"calls"| MS

    M -->|"fetch/save"| D
    D -->|"manages"| MO
    D -->|"uses"| DC
    PX -->|"configures"| DC

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef business fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef dataAccess fill:#FFD580,stroke:#000,stroke-width:2px;
    classDef infrastructure fill:#D3D3D3,stroke:#000,stroke-width:2px;

    %% Click Events
    click V "https://github.com/giabao1340/ql_thu_vien/tree/main/src/main/java/com/mycompany/qlthuvien/view"
    click M "https://github.com/giabao1340/ql_thu_vien/blob/main/src/main/java/com/mycompany/qlthuvien/QLThuVien.java"
    click MM "https://github.com/giabao1340/ql_thu_vien/tree/main/src/main/java/MemberMemento"
    click P "https://github.com/giabao1340/ql_thu_vien/tree/main/src/main/java/ProxyMember"
    click EF "https://github.com/giabao1340/ql_thu_vien/tree/main/src/main/java/com/mycompany/qlthuvien/FactoryMethod"
    click TS "https://github.com/giabao1340/ql_thu_vien/tree/main/src/main/java/com/mycompany/qlthuvien/BorrowedTicketStates"
    click BS "https://github.com/giabao1340/ql_thu_vien/tree/main/src/main/java/com/mycompany/qlthuvien/bookstate"
    click C "https://github.com/giabao1340/ql_thu_vien/tree/main/src/main/java/com/mycompany/qlthuvien/command"
    click MS "https://github.com/giabao1340/ql_thu_vien/tree/main/src/main/java/memberState"
    click D "https://github.com/giabao1340/ql_thu_vien/tree/main/src/main/java/com/mycompany/qlthuvien/dao"
    click MO "https://github.com/giabao1340/ql_thu_vien/tree/main/src/main/java/com/mycompany/qlthuvien/model"
    click DC "https://github.com/giabao1340/ql_thu_vien/blob/main/src/main/java/com/mycompany/qlthuvien/DatabaseConnection.java"
    click PX "https://github.com/giabao1340/ql_thu_vien/blob/main/pom.xml"
    click SQ "https://github.com/giabao1340/ql_thu_vien/tree/main/sql"
```
