# huuthanh2k4/wed_chuan_doan_benh architecture

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

- Interactive diagram: https://gitdiagram.com/huuthanh2k4/wed_chuan_doan_benh
- Repository: https://github.com/huuthanh2k4/wed_chuan_doan_benh

## Overview

##### Project type and purpose
- This is a Python-based, multi-page web application (likely Streamlit or a similar framework) that loads pre-trained ML models (.sav files) from disk and exposes prediction functionality via different UI pages (admin, history).

##### File structure
- Top-level files:
- app.py – the main entry point that launches the web server and routes to page modules
- requirements.txt – lists Python dependencies (e.g., streamlit or Flask, scikit-learn)
- pages/ directory:
- admin.py – administrative interface (model management or user controls)
- lich_su.py – “history” page (logs or past predictions)
- Model/ directory:
- CDTC_knn.sav, ML_heartattack.sav, NutriAI.sav, NutriAI1.sav – serialized ML models for different prediction tasks

##### README
- Minimal content (“Cập nhập” = “Update” in Vietnamese), no embedded architecture details. Rely on file structure to infer architecture.

##### Main components and their interactions
a. Client (Web Browser)
b. Web Application Server (app.py + pages/*.py)
c. Model Storage (Model/*.sav files on disk)
d. Dependencies / Libraries (scikit-learn, Streamlit/Flask, pandas, etc.)

Relationships:
- Client sends HTTP requests (UI interactions) to the Web App Server.
- Server routes requests to the appropriate page module (admin or history).
- Page module code loads the required ML model from disk, processes user input, and returns prediction results.
- Server sends back rendered HTML (or Streamlit UI) to the Client.

##### Architectural patterns and design principles
- Monolithic, single-process server that combines routing and model-serving
- Separation of concerns: routing logic in app.py, UI per page in pages/, ML logic decoupled in separate model files
- Lazy loading of models: load only the needed .sav file when a page is accessed (improves memory usage)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Client["Client (Browser)"]:::frontend

    %% Server Layer
    subgraph "Web Application Server"
        AP["app.py (Entry Point)"]:::backend
        subgraph "Pages / Routing"
            Admin["admin.py"]:::backend
            History["lich_su.py"]:::backend
        end
        subgraph "Libraries"
            Lib["Dependencies\n(scikit-learn, Streamlit, pandas)"]:::external
        end
    end

    %% Model Storage Layer
    subgraph "Model Store"
        CDTC["CDTC_knn.sav"]:::storage
        Heart["ML_heartattack.sav"]:::storage
        Nutri1["NutriAI.sav"]:::storage
        Nutri2["NutriAI1.sav"]:::storage
    end

    %% Documentation and Requirements
    Requirements["requirements.txt"]:::external
    README["README.md"]:::external

    %% Connections
    Client -->|"HTTP Request"| AP
    AP -->|"render_page()"| Client
    AP -->|"routes to"| Admin
    AP -->|"routes to"| History
    AP -->|"uses libraries"| Lib

    Admin -->|"load_model() & predict()"| CDTC
    Admin -->|"load_model() & predict()"| MLHeart["ML_heartattack.sav"]:::storage
    History -->|"load_model() & predict()"| Nutri1
    History -->|"load_model() & predict()"| Nutri2

    AP -->|"dependency definitions"| Requirements
    AP -->|"project docs"| README

    %% Click Events
    click AP "https://github.com/huuthanh2k4/wed_chuan_doan_benh/blob/main/app.py"
    click Admin "https://github.com/huuthanh2k4/wed_chuan_doan_benh/blob/main/pages/admin.py"
    click History "https://github.com/huuthanh2k4/wed_chuan_doan_benh/blob/main/pages/lich_su.py"
    click CDTC "https://github.com/huuthanh2k4/wed_chuan_doan_benh/blob/main/Model/CDTC_knn.sav"
    click MLHeart "https://github.com/huuthanh2k4/wed_chuan_doan_benh/blob/main/Model/ML_heartattack.sav"
    click Nutri1 "https://github.com/huuthanh2k4/wed_chuan_doan_benh/blob/main/Model/NutriAI.sav"
    click Nutri2 "https://github.com/huuthanh2k4/wed_chuan_doan_benh/blob/main/Model/NutriAI1.sav"
    click Requirements "https://github.com/huuthanh2k4/wed_chuan_doan_benh/blob/main/requirements.txt"
    click README "https://github.com/huuthanh2k4/wed_chuan_doan_benh/blob/main/README.md"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef storage fill:#FFD580,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
