# ktlt11/doancuoiky architecture

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

## Overview

##### Main Components
- GUI (Presentation Layer): This is located primarily in the “gui” directory. It includes all the UI layout files (e.g., Admin_ui.py, login_ui.py, User_ui.py, and associated resource files such as “_rc.py” files and .ui files).
- Service Layer (Business Logic): Found in the “services” folder, these modules (login_service.py, admin_service.py, user_service.py, etc.) handle event processing, data validation, and communicating between the front end and the database.
- Database Access Layer: Contained in the “database” directory with files like API_Admin.py, API_Login.py, API_User.py, and api.py. These modules encapsulate the interaction with MongoDB.
- Data Files: The “data” folder holds JSON files for invoice, product, supplier, and user information which might be used for initial configuration, testing, or offline operations.
- External API Integration: Although not in a separate directory, the README indicates that weather data is integrated via an API (OpenWeatherMap) using an API key provided in .env.
- Configuration and Environment: The .env file, requirements.txt, and set_up.py play a role in configuring the environment, setting up dependencies, and connecting to MongoDB.

##### Relationships and Interactions
- The GUI sends user events (e.g., login, inventory updates, invoice creation) to the service layer.
- The service layer processes these events, performing validation and business logic, and then communicates with the database access layer.
- The database layer executes CRUD operations on MongoDB using appropriate APIs.
- For the weather feature in the dashboard, the service layer interacts with the external OpenWeatherMap API.
- Data flows from the external APIs and database to the GUI for display (e.g., charts, tables, and reports).

##### Architectural Patterns Highlighted
- Layered Architecture: Clear separation exists between presentation (GUI), business logic/services, and data access layers.
- MVC-like Separation (even if not strictly MVC): The GUI acts as a “view”, services act as the “controller”, and the database/API modules serve as the “model”.
- Environment and Dependency Management: Use of .env and configuration files to isolate sensitive and environment-specific data.

##### Relevant Technologies, Frameworks, and Libraries
- PySide6 for creating the GUI.
- Python (>=3.10) as the programming language.
- MongoDB as the database, with pymongo for integration.
- dotenv for configuration management.
- OpenWeatherMap API for retrieving weather data.
- Additional Python libraries referenced in requirements.txt.

## Diagram (Mermaid)

```mermaid
graph TD
    MAIN["main.py (Application Bootstrap)"]:::mainStyle
    GUI["GUI Layer<br/>(Qt-based User Interface)"]:::guiStyle
    SERVICE["Service Layer<br/>(Business Logic)"]:::serviceStyle
    DATABASE["Database Access Layer"]:::databaseStyle
    MONGO["MongoDB"]:::mongoStyle
    EXTERNAL["External API:<br/>OpenWeatherMap"]:::externalStyle
    CONFIG["Configuration & Environment<br/>(.env, requirements.txt, set_up.py)"]:::configStyle
    DATA["Data Files<br/>(JSON configurations)"]:::dataStyle

    MAIN -->|"launches"| GUI
    GUI -->|"sends_events"| SERVICE
    SERVICE -->|"CRUD_ops"| DATABASE
    SERVICE -->|"fetch_weather"| EXTERNAL
    DATABASE -->|"database_calls"| MONGO
    CONFIG -->|"db_connection"| DATABASE
    CONFIG -->|"env_config"| SERVICE
    MAIN -->|"setup"| CONFIG
    DATA -->|"loads_initial_data"| DATABASE

    click MAIN "https://github.com/ktlt11/doancuoiky/blob/master/main.py"
    click GUI "https://github.com/ktlt11/doancuoiky/tree/master/gui"
    click SERVICE "https://github.com/ktlt11/doancuoiky/tree/master/services"
    click DATABASE "https://github.com/ktlt11/doancuoiky/tree/master/database"
    click DATA "https://github.com/ktlt11/doancuoiky/tree/master/data"
    click CONFIG "https://github.com/ktlt11/doancuoiky/blob/master/.env"

    classDef mainStyle fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef guiStyle fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef serviceStyle fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef databaseStyle fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef externalStyle fill:#C39BD3,stroke:#8E44AD,stroke-width:2px;
    classDef configStyle fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef dataStyle fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef mongoStyle fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
```
