# lmtvinh/doanquanlycuahangsach architecture

> Architecture diagram of the GitHub repository lmtvinh/doanquanlycuahangsach, 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/lmtvinh/doanquanlycuahangsach
- Repository: https://github.com/lmtvinh/doanquanlycuahangsach

## Overview

##### Main Components
- User Interface (Presentation) Layer:
- Represented primarily by the “giaodienchuan” package and further detailed in the model/FrontEnd directory.
- Comprises various forms (e.g., LoginForm, BanHangForm, QuanLySanPhamForm) and visual elements (e.g., NavBar, MyButton, image resources).
- Business Logic Layer:
- Found in the “BUS” subpackages within model/BackEnd.
- Contains classes like QuanLyHoaDonBUS, QuanLyKhachHangBUS, etc., that enforce business rules and application logic.
- Data Access Layer:
- Represented by the “DAO” packages, responsible for interacting with the database via classes (e.g., QuanLyChiTietHoaDonDAO.java).
- Includes a dedicated DB connector (src/giaodienchuan/model/BackEnd/ConnectionDB/ConnectionDB.java) that abstracts the database connectivity.
- Data Model / DTOs:
- Comprised of the “DTO” subpackages. They serve as data carriers between layers.
- External Libraries and Utilities:
- The “lib” folder includes various JAR files for additional functionalities – for example, LGoodDatePicker for date picking, POI for Excel processing, iText for PDF generation, and the MySQL connector for DB connectivity.
- Additional utilities exist under modules like WorkWithExcel, WritePDF, and ReadWriteFile.
- Database:
- Shown via the “QuanLyCuaHangSach.sql” file – indicating a MySQL (or similar) database that stores the persistent data.

##### Relationships and Interactions
- UI (FrontEnd forms and components) interacts directly with the Business Logic (BUS) layer to process user actions (e.g., creating an invoice, managing customers).
- The Business Logic layer validates and orchestrates the operations by invoking DAO methods to retrieve or update data.
- DAO classes interact with the database using connection settings defined in the ConnectionDB component.
- The front-end may also include auxiliary functions such as printing/exporting through utilities (Excel, PDF) that integrate with external libraries.

##### Architectural Patterns and Design Principles
- MVC or Layered Architecture: Separation of UI, Business Logic, and Data Access promotes maintainability and modularity.
- Use of DTOs to decouple the internal data structure from presentation details.
- Utilization of utility classes for specialized tasks (file read/write, Excel, PDF) adds a service-like component to the overall design.
- The naming conventions (QuanLy – “management”) suggest domain-driven design focusing on distinct business entities such as HoaDon (Invoice), KhachHang (Customer), SanPham (Product), etc.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["User Interface (Swing Forms)"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        BUS["Business Logic (BUS Classes)"]:::bus
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        DAO["Data Access (DAO Classes)"]:::dao
        DBConnect["DB Connector"]:::dao
    end

    %% Data Model Layer
    subgraph "Data Model / DTO"
        DTO["DTO Classes"]:::dto
    end

    %% External Libraries & Utilities
    subgraph "External Libraries & Utilities"
        LIB["Third-Party Libraries"]:::lib
        UTIL1["File Operations (Utilities)"]:::lib
        UTIL2["Excel Processing"]:::lib
        UTIL3["PDF Generation"]:::lib
    end

    %% Database
    subgraph "Database"
        DB["Database (MySQL)"]:::db
        SQL["SQL Script"]:::db
    end

    %% Relationships
    UI -->|"calls"| BUS
    BUS -->|"invokes"| DAO
    DAO -->|"utilizes"| DBConnect
    DBConnect -->|"queries"| DB
    DB -->|"stores/retrieves"| SQL
    BUS -->|"uses data"| DTO

    LIB ---|"supports"| UI
    LIB ---|"supports"| DAO
    UTIL1 ---|"handles"| BUS
    UTIL2 ---|"processes"| BUS
    UTIL3 ---|"generates"| BUS

    %% Click Events
    click UI "https://github.com/lmtvinh/doanquanlycuahangsach/tree/main/src/giaodienchuan/model/FrontEnd"
    click BUS "https://github.com/lmtvinh/doanquanlycuahangsach/tree/main/src/giaodienchuan/model/BackEnd/BUS"
    click DAO "https://github.com/lmtvinh/doanquanlycuahangsach/tree/main/src/giaodienchuan/model/BackEnd/DAO"
    click DBConnect "https://github.com/lmtvinh/doanquanlycuahangsach/blob/main/src/giaodienchuan/model/BackEnd/ConnectionDB/ConnectionDB.java"
    click DTO "https://github.com/lmtvinh/doanquanlycuahangsach/tree/main/src/giaodienchuan/model/BackEnd/DTO"
    click LIB "https://github.com/lmtvinh/doanquanlycuahangsach/tree/main/src/lib"
    click UTIL1 "https://github.com/lmtvinh/doanquanlycuahangsach/blob/main/src/giaodienchuan/model/BackEnd/ReadWriteFile/WorkWithFile.java"
    click UTIL2 "https://github.com/lmtvinh/doanquanlycuahangsach/tree/main/src/giaodienchuan/model/BackEnd/WorkWithExcel"
    click UTIL3 "https://github.com/lmtvinh/doanquanlycuahangsach/blob/main/src/giaodienchuan/model/BackEnd/WritePDF/WritePDF.java"
    click SQL "https://github.com/lmtvinh/doanquanlycuahangsach/blob/main/QuanLyCuaHangSach.sql"

    %% Style Definitions
    classDef ui fill:#a8dadc,stroke:#1d3557,stroke-width:2px;
    classDef bus fill:#f4a261,stroke:#e76f51,stroke-width:2px;
    classDef dao fill:#e9c46a,stroke:#264653,stroke-width:2px;
    classDef dto fill:#9575cd,stroke:#4a148c,stroke-width:2px;
    classDef lib fill:#ffde7d,stroke:#f6aa1c,stroke-width:2px;
    classDef db fill:#ffb4a2,stroke:#d62828,stroke-width:2px;
```
