# nnminh-sam/library-management-app architecture

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

- Interactive diagram: https://gitdiagram.com/nnminh-sam/library-management-app
- Repository: https://github.com/nnminh-sam/library-management-app

## Overview

##### Main Components
- Domain Model / Business Logic:
- Title, Book, Reader, and BorrowedBook classes.
- Their relationships: a Title contains a linked list (catalogue) of Book objects; a Reader is stored in an AVL tree and has a BorrowedBookList (double linked list) of borrowing records.
- Data Structures Library:
- Custom implementations under the DataStructures directory (AVL Tree, DoubleLinkedList, LinkedList, DynamicArray, HashMap, etc.).
- Persistent Storage:
- "Databases" directory with text files and binary files to simulate persistent storage (e.g., DAU_SACH_DB.txt, DOC_GIA_DB.txt, indexes).
- UI/Presentation Layer:
- The Tabs folder contains various UI components (views for “DanhSachDauSach”, “DanhSachTheDocGia”, “LandingView”, “ThongKeTab”, UI elements such as Button, Component, Table, etc.).
- Helper & Utility Modules:
- Helper directory for constants, global variables, index generation, and packaging logic.
- Graphics / External Libraries:
- The Graphics directory shows usage of the BGI graphics libraries and related support files to render the UI.

##### Understand Relationships and Interactions
- User actions (via the UI components in the Tabs module) trigger operations in the business logic layer.
- The business logic uses the custom data structures to manage core entities efficiently.
- When changes occur (e.g., creation, update, deletion of data), the updates are reflected in the persistent text-based databases.
- The UI layer uses the Graphics module to display information, while Helper functions provide additional support (like generating indexes or managing configuration constants).

##### Architectural Patterns / Design Principles
- Although it’s all in one codebase, notice a separation of concerns: data management is achieved through encapsulated data structures; UI is managed in segregated “Tab” components; business rules are embedded in the Domain Model.
- The use of C++ Object-Oriented Programming and custom data-structures indicates a focus on performance and direct control over memory, albeit with some challenges (e.g., a noted memory leak).

##### Relevant Technologies and Frameworks
- Programming Language: C++20.
- UI/Graphics: BGI (graphics.h and its associated libraries).
- Build/Project Management: Visual Studio 2022 project (.sln file) with CMake support.
- Data Structures: Custom implementations for linked lists, AVL trees, etc.

##### What
- Clearly label major components: "Domain Model", "Data Structures", "UI Module", "Helper Utilities", "Persistent Database", and "Graphics Engine".
- From UI components to Domain Methods (e.g., when a user inputs a new "Title" or "Reader").
- From Domain/Business Logic to Data Structures (for storing and querying operations).
- From Domain to Database (for read/write of persistent storage).
- Incorporate annotations or notes regarding design decisions (e.g., “Uses AVL Tree for Reader list to ensure efficient searches/sorts”).
- Optionally, highlight how operations are affected by rules (e.g., borrowing restrictions and overdue check logic).

- Domain layer to the Database layer (text file representation) to illustrate persistence.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI/Presentation Layer"
        A1("LandingView"):::ui
        A2("DanhSachDauSachTab"):::ui
        A3("DanhSachTheDocGiaTab"):::ui
        A4("ThongKeTab"):::ui
        A5("UI Components"):::ui
    end

    subgraph "Domain Model / Business Logic"
        B1("Titles & Books"):::domain
        B2("Readers"):::domain
    end

    C("Data Structures Library"):::ds
    D("Persistent Storage"):::storage
    E("Helper Utilities"):::helper
    F("Graphics Engine"):::graphics

    %% UI triggers Domain Model
    A1 -->|"triggers"| B1
    A2 -->|"triggers"| B1
    A3 -->|"triggers"| B2
    A4 -->|"triggers"| B2
    A5 -->|"triggers"| B1

    %% Domain Model interactions with support layers
    B1 -->|"uses"| C
    B1 -->|"updates"| D
    B2 -->|"uses"| C
    B2 -->|"updates"| D

    %% UI supported by Helper and Graphics
    A1 -->|"rendersBy"| F
    A1 -->|"supportedBy"| E
    A2 -->|"rendersBy"| F
    A3 -->|"supportedBy"| E

    %% Click Events
    click A1 "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/Tabs/LandingView"
    click A2 "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/Tabs/DanhSachDauSachTab"
    click A3 "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/Tabs/DanhSachTheDocGiaTab"
    click A4 "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/Tabs/ThongKeTab"
    click A5 "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/Tabs/UI"
    click B1 "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/DauSach"
    click B2 "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/TheDocGia"
    click C "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/DataStructures"
    click D "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/Databases"
    click E "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/Helper"
    click F "https://github.com/nnminh-sam/library-management-app/tree/main/LibraryManagementTool/Graphics"

    %% Styles
    classDef ui fill:#a8d0e6,stroke:#000,stroke-width:2px;
    classDef domain fill:#f8b500,stroke:#000,stroke-width:2px;
    classDef ds fill:#219ebc,stroke:#000,stroke-width:2px;
    classDef storage fill:#ffb703,stroke:#000,stroke-width:2px;
    classDef helper fill:#8ecae6,stroke:#000,stroke-width:2px;
    classDef graphics fill:#6a4c93,stroke:#000,stroke-width:2px;
```
