# hloc26/project-dbms architecture

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

- Interactive diagram: https://gitdiagram.com/hloc26/project-dbms
- Repository: https://github.com/hloc26/project-dbms

## Overview

Based on our analysis of both the file tree and the README file, this project is a Windows Forms-based bookstore management system built using C# with Visual Studio 2022 and backed by Microsoft SQL Server. Its primary purpose is to streamline the management of employees, inventory (books and stationery), and customers, including membership programs.

- User Interface (Presentation Layer): This covers all Windows Forms (e.g., FLogin, FMain, FKhachhang, FRegis, FThemTTSach). These forms are responsible for user interaction such as login, registering users, and managing transaction interfaces.
- Data Access Layer: Represented by the DAO classes (e.g., EmployeeDAO, HangHoaDAO, HoaDonBanDAO, HoaDonNhapDAO, KhachHangDAO, ThemTTSachDAO, TraCuuDAO). This layer abstracts the underlying database operations.
- Domain/Data Models (DTOs): The DTO directory (for instance, Employee, HangHoa, KhachHang, NXB, Sach, TacGia, TheTV, VatPham) encapsulates the data transferred between the UI and DAO layers.
- Business/Logic Layer (if implicit): While business logic might be interleaved in the UI code or in additional service classes, note that the data flow starts from the UI, passes through the DAO and possibly some business logic embedded in forms.
- Database Layer: The backend SQL Server database, with its schema, stored procedures, triggers, views, functions, and scripts provided in the “DB Scripts” folder. Include the “FullScript.sql” as the central script to create and initialize the database.
- Configuration: The App.config file (inside DBMS_BookStore) which holds configuration settings like the database connection string.

##### Detail the relationships and interactions
- The User Interface sends user inputs (login requests, customer/data management operations) to the underlying Data Access Layer.
- The DAO classes use the database connection (configured in App.config and implemented via DBConnection.cs) to execute SQL commands, queries, stored procedures, and so forth.
- Data results are passed back to the UI using DTO objects.
- The SQL scripts indicate that business rules (triggers, views, procedures) exist in the database to enforce data integrity and advanced operations.

##### Architectural patterns and design principles
- Layered Architecture: The project clearly adheres to a layered architecture separating presentation, data access, and data models.
- Separation of Concerns: UI, DAO, and DTO directories indicate a clear separation between the user interface logic, database access logic, and data representation.
- Configuration Management: Use of App.config demonstrates how external configuration is used to decouple code and environment settings.

##### Technologies, frameworks, and libraries
- Programming Language: C#
- Application Framework: .NET Framework for Windows Forms
- Database: Microsoft SQL Server
- Development Environment: Visual Studio 2022
- Tools: SQL Scripts for schema and data initialization (including procedures, triggers, views, etc.)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        UI1("FLogin"):::ui
        UI2("FMain"):::ui
        UI3("FKhachhang"):::ui
        UI4("FRegis"):::ui
        UI5("FThemTTSach"):::ui
    end

    subgraph "Data Access Layer (DAO)"
        DAO1("DBConnection.cs"):::dao
        DAO2("EmployeeDAO.cs"):::dao
        DAO3("HangHoaDAO.cs"):::dao
        DAO4("HoaDonBanDAO.cs"):::dao
        DAO5("HoaDonNhapDAO.cs"):::dao
        DAO6("KhachHangDAO.cs"):::dao
        DAO7("ThemTTSachDAO.cs"):::dao
        DAO8("TraCuuDAO.cs"):::dao
    end

    subgraph "Domain/Data Models (DTOs)"
        DTO1("Employee.cs"):::dto
        DTO2("HangHoa.cs"):::dto
        DTO3("KhachHang.cs"):::dto
        DTO4("NXB.cs"):::dto
        DTO5("Sach.cs"):::dto
        DTO6("TacGia.cs"):::dto
        DTO7("TheTV.cs"):::dto
        DTO8("VatPham.cs"):::dto
    end

    subgraph "Database Layer"
        DB1("SQL Server Database"):::db
        DB2("FullScript.sql"):::db
    end

    subgraph "Configuration"
        CFG("App.config"):::config
    end

    %% Connections between layers
    UI1 -->|"sends_request"| DAO1
    CFG -->|"connection_string"| DAO1
    DAO1 -->|"executes_SQL"| DB1
    DB1 -->|"returns_data"| DAO1
    DAO1 -->|"maps_to_DTO"| DTO1
    DTO1 -->|"delivers_data"| UI2

    %% Additional representative interaction
    UI2 -->|"initiates_action"| DAO2
    DAO2 -->|"executes_SQL"| DB1

    %% Click Events for User Interface
    click UI1 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/FLogin.cs"
    click UI2 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/FMain.cs"
    click UI3 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/FKhachhang.cs"
    click UI4 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/FRegis.cs"
    click UI5 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/FThemTTSach.cs"

    %% Click Events for Data Access Layer
    click DAO1 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DAO/DBConnection.cs"
    click DAO2 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DAO/EmployeeDAO.cs"
    click DAO3 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DAO/HangHoaDAO.cs"
    click DAO4 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DAO/HoaDonBanDAO.cs"
    click DAO5 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DAO/HoaDonNhapDAO.cs"
    click DAO6 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DAO/KhachHangDAO.cs"
    click DAO7 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DAO/ThemTTSachDAO.cs"
    click DAO8 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DAO/TraCuuDAO.cs"

    %% Click Events for Domain/Data Models
    click DTO1 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DTO/Employee.cs"
    click DTO2 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DTO/HangHoa.cs"
    click DTO3 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DTO/KhachHang.cs"
    click DTO4 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DTO/NXB.cs"
    click DTO5 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DTO/Sach.cs"
    click DTO6 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DTO/TacGia.cs"
    click DTO7 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DTO/TheTV.cs"
    click DTO8 "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/DTO/VatPham.cs"

    %% Click Events for Database Layer and Configuration
    click DB2 "https://github.com/hloc26/project-dbms/blob/master/DB Scripts/FullScript.sql"
    click CFG "https://github.com/hloc26/project-dbms/blob/master/DBMS_BookStore/App.config"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef dao fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef dto fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef db fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef config fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
