# dd-se/ml-app architecture

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

- Interactive diagram: https://gitdiagram.com/dd-se/ml-app
- Repository: https://github.com/dd-se/ml-app

## Overview

##### Main Components
- Frontend/UI: Represented by the Streamlit app (app.py) which serves as the user interface. This is where user interactions (input via webcam, drawing, etc.) are captured.
- ML Model Management: Shown by resources (resources.py and the models inside the resources/models folder) that load and execute pre-trained machine learning models.
- Training & Evaluation: Highlight train_model.py and the Jupyter notebook (mnist_model_eval.ipynb) as part of the model development process. Also include the test_set directory (true_labels.txt) for evaluation.
- Configuration & Deployment: Indicate the configuration directories (.devcontainer, .streamlit) which facilitate development environment setup and Streamlit-specific configurations.

##### Relationships and Interactions
- For training and evaluation workflows, display a separate flow from train_model.py and mnist_model_eval.ipynb (evaluation notebook) to the models folder, indicating that these components are used to build, test, and update the models.
- A separate section for “Configurations” that influences both the development/deployment environments (represented by .devcontainer and .streamlit folders).

##### Architectural Patterns and Design Principles
- Layered, modular approach: Separate the user interface layer (Streamlit) from the ML processing layer. This separation shows clear responsibilities.
- If applicable, denote the pattern where a central “controller” (the main app.py) aggregates services or functionalities provided by the various utility modules.
- Point out that the system is designed with extendability in mind, allowing for plugging in alternative input sources (like webcam.py) or different visualization options.
- Mention dependency management and environment isolation via requirements.txt and packages.txt.

##### Relevant Technologies and Frameworks
- Python (version 3.10 or higher) as the language.
- Streamlit as the primary web UI framework.
- Machine learning libraries (implied by the model file names such as MLPClassifier and PCA-SVC).
- Container setup via .devcontainer (for VS Code containerized development) and a clear configuration in .streamlit.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction
    U["User/Client"]:::external

    %% Presentation Layer
    A["Streamlit UI (app.py)"]:::frontend

    %% ML Processing Layer
    MLM["ML Model Loader (resources.py)"]:::backend
    M["ML Models (resources/models)"]:::backend

    %% Supporting Utilities
    D["Drawing Utility (draw.py)"]:::utility
    P["Image Processing (pictures.py)"]:::utility
    W["Webcam Input Handler (webcam.py)"]:::utility

    %% Training and Evaluation
    T["Model Trainer (train_model.py)"]:::trainer
    E["Model Evaluator (mnist_model_eval.ipynb)"]:::trainer
    TS["Test Set (true_labels.txt)"]:::trainer

    %% Configuration and Deployment
    DC["Dev Container (.devcontainer)"]:::config
    ST["Streamlit Config (.streamlit)"]:::config
    PK["packages.txt"]:::config
    RT["requirements.txt"]:::config

    %% Connections
    U -->|"user_input"| A
    A -->|"calls"| MLM
    MLM -->|"loads"| M
    A -->|"utilizes"| D
    A -->|"utilizes"| P
    A -->|"utilizes"| W
    T -->|"updates"| M
    E -->|"evaluates"| M
    E -->|"uses"| TS
    DC -->|"configures"| A
    ST -->|"configures"| A
    PK -->|"supports"| A
    RT -->|"supports"| A

    %% Click Events
    click A "https://github.com/dd-se/ml-app/blob/main/app.py"
    click MLM "https://github.com/dd-se/ml-app/blob/main/resources.py"
    click M "https://github.com/dd-se/ml-app/tree/main/resources/models"
    click D "https://github.com/dd-se/ml-app/blob/main/draw.py"
    click P "https://github.com/dd-se/ml-app/blob/main/pictures.py"
    click W "https://github.com/dd-se/ml-app/blob/main/webcam.py"
    click T "https://github.com/dd-se/ml-app/blob/main/train_model.py"
    click E "https://github.com/dd-se/ml-app/blob/main/mnist_model_eval.ipynb"
    click TS "https://github.com/dd-se/ml-app/blob/main/test_set/true_labels.txt"
    click DC "https://github.com/dd-se/ml-app/blob/main/.devcontainer/devcontainer.json"
    click ST "https://github.com/dd-se/ml-app/blob/main/.streamlit/config.toml"
    click PK "https://github.com/dd-se/ml-app/blob/main/packages.txt"
    click RT "https://github.com/dd-se/ml-app/blob/main/requirements.txt"

    %% Styles
    classDef external fill:#f9d,stroke:#333,stroke-width:2px;
    classDef frontend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef backend fill:#cfc,stroke:#333,stroke-width:2px;
    classDef utility fill:#fc9,stroke:#333,stroke-width:2px;
    classDef trainer fill:#cff,stroke:#333,stroke-width:2px;
    classDef config fill:#ddd,stroke:#333,stroke-width:2px;
```
