# nightystudios/mlpg architecture

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

- Interactive diagram: https://gitdiagram.com/nightystudios/mlpg
- Repository: https://github.com/nightystudios/mlpg

## Overview

##### Project type and purpose
- MLPG is a standalone Python application offering both a desktop GUI (UI.py) and a console‐based CLI (mlpg.py / mlpg entry point).
- Purpose: Provide a “playground” for ML engineers to download, list, run, and delete AI models locally.

##### File structure
- Top‐level scripts:
- UI.py – launches the graphical interface
- mlpg.py / mlpg.bat – CLI entry point
- download_model.py / list_models.py / use_model.py / del_model.py – core CLI commands
- src/ – contains shared business logic and helper modules (model I/O, inference wrappers, config management)
- requirements.txt – lists external dependencies (PyTorch, sentencepiece, etc.)
- README.md – explains features and setup.

##### README for additional insights
- Two interfaces (GUI vs CLI) both rely on the same core modules.
- External requirements: CUDA-enabled PyTorch or CPU fallback.
- Models are stored/managed locally; list_models.py reflects supported models.

a. Main components
- User Interfaces
– GUI Layer (UI.py + Streamlit?/Tkinter?)
– CLI Layer (mlpg.py / entry scripts)
- Core Service Layer (src/)
– Model Manager (download, list, delete)
– Inference Engine (use_model)
– Configuration & Logging
- Local Storage
– Models folder (downloaded checkpoints, metadata)
- External Services & Repos
– Model hosting endpoints (HuggingFace, custom URLs)
- External Dependencies
– PyTorch (+ CUDA)
– sentencepiece
b. Relationships & interactions
- UI/CLI → Core Service Layer (function calls or module imports)
- Core Service → Local Storage (read/write model files)
- Core Service → External Services (HTTP to download models)
- Inference Engine → PyTorch (runs forward pass)
- Inference Engine → sentencepiece (tokenization)
c. Architectural patterns & design principles
- Layered architecture: Presentation (UI/CLI) → Business (Core Service) → Data (Local Storage)
- Single process, modular Python packages
- Clear separation: each command is a thin wrapper around core modules.
d. Relevant technologies
- Python 3.12
- PyTorch (GPU/CPU)
- sentencepiece
- Optional: future Streamlit for GUI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        UI["UI Layer\n(UI.py)"]:::presentation
        mlpg_py["mlpg.py"]:::presentation
        mlpg_bat["mlpg.bat"]:::presentation
        download_cmd["download_model.py"]:::presentation
        list_cmd["list_models.py"]:::presentation
        use_cmd["use_model.py"]:::presentation
        del_cmd["del_model.py"]:::presentation
    end

    %% Core Service Layer
    subgraph "Core Service Layer (src/)" 
        direction TB
        model_mgr["Model Manager"]:::core
        infer["Inference Engine"]:::core
        config["Config & Logging"]:::core
    end

    %% Local Storage
    storage["Models Folder\n(/models)"]:::storage

    %% External Services & Repos
    repos["Model Hosting Endpoints"]:::external

    %% External Dependencies
    pytorch["PyTorch (+CUDA)"]:::deps
    spiece["sentencepiece"]:::deps

    %% Documentation & Requirements
    subgraph "Project Docs"
        direction TB
        README["README.md"]:::external
        req["requirements.txt"]:::external
    end

    %% Connections: Presentation to Core
    UI -->|uses| model_mgr
    UI -->|uses| infer

    mlpg_py -->|invokes| download_cmd
    mlpg_py -->|invokes| list_cmd
    mlpg_py -->|invokes| use_cmd
    mlpg_py -->|invokes| del_cmd
    mlpg_bat -->|invokes| mlpg_py

    download_cmd -->|calls| model_mgr
    list_cmd -->|calls| model_mgr
    del_cmd -->|calls| model_mgr
    use_cmd -->|calls| infer

    %% Core to Storage & External
    model_mgr -->|read/write| storage
    model_mgr -->|HTTP GET/POST| repos

    infer -->|tokenize| spiece
    infer -->|run forward| pytorch

    %% Click Events
    click UI "https://github.com/nightystudios/mlpg/blob/master/UI.py"
    click mlpg_py "https://github.com/nightystudios/mlpg/blob/master/mlpg.py"
    click mlpg_bat "https://github.com/nightystudios/mlpg/blob/master/mlpg.bat"
    click download_cmd "https://github.com/nightystudios/mlpg/blob/master/download_model.py"
    click list_cmd "https://github.com/nightystudios/mlpg/blob/master/list_models.py"
    click use_cmd "https://github.com/nightystudios/mlpg/blob/master/use_model.py"
    click del_cmd "https://github.com/nightystudios/mlpg/blob/master/del_model.py"
    click src "https://github.com/nightystudios/mlpg/tree/master/src/"
    click req "https://github.com/nightystudios/mlpg/blob/master/requirements.txt"
    click README "https://github.com/nightystudios/mlpg/blob/master/README.md"

    %% Styles
    classDef presentation fill:#d0e7ff,stroke:#333,stroke-width:1px
    classDef core fill:#d4f8d4,stroke:#333,stroke-width:1px
    classDef storage fill:#fff5b1,stroke:#333,stroke-width:1px
    classDef external fill:#e2e2e2,stroke:#333,stroke-width:1px
    classDef deps fill:#ffd1a9,stroke:#333,stroke-width:1px
```
