# mangio621/mangio-rvc-fork architecture

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

- Interactive diagram: https://gitdiagram.com/mangio621/mangio-rvc-fork
- Repository: https://github.com/mangio621/mangio-rvc-fork

## Overview

##### Main Components
- UI Layer
– **Web UI**: Gradio app in `infer-web.py` & `app.py`
– **CLI Interface**: stateful menu in `infer-web.py` with `--is_cli`, batch scripts (`go-web.bat`, `run.sh`)
- Core Engine
– **Inference Pipeline**
- F0 extraction modules (`lib/infer_pack/modules/F0Predictor/*`)
- Feature packing (`lib/infer_pack/transforms.py`, `infer-pack/commons.py`)
- Retrieval index lookup (Faiss `.index` files under `logs/…`)
- Conversion model execution (`lib/infer_pack/models*.py`, `lib/uvr5_pack/lib_v5/*`)
- Post-processing (resample, volume mix)
– **Training Pipeline**
- Data preprocessing (`train/data_utils.py`, `mel_processing.py`)
- Feature extraction (`train/losses.py`, `train/utils.py`)
- Model training (VITS + cycle discriminators)
- Logging & checkpointing (`logs/…`, TensorBoard via Makefile)
- Configuration & Localization
– `config.py`, JSON files under `configs/`
– i18n loader (`i18n.py`, `i18n/*.json`, `i18n/locale_diff.py`)
- Data & Storage
– Audio assets (`audios/`, `audio-outputs/`)
– Model artifacts (`pretrained/`, `pretrained_v2/`, `weights/`, `uvr5_weights/`)
– Retrieval indexes & logs (`logs/…/*.index`, `logs/…/mute/`)
- External Dependencies
– FFmpeg/ffprobe binaries
– Python libraries (PyTorch, Faiss, NumPy, Gradio, etc.)
– Docker container (Dockerfile) & CI/CD pipelines (`.github/workflows/*.yml`)

##### Relationships & Data Flows
- **User → UI**: Browser (Gradio) or Terminal (CLI)
- **UI → Core Engine**: passes user parameters (model path, audio path, f0 method, etc.)
- **Inference Engine**:
– calls F0 extract → packs features → queries Faiss → runs conversion model → writes output WAV
– returns result to UI/CLI
- **Training Engine**:
– ingests raw audio → preprocesses → extracts features → trains model → writes checkpoints and logs
– TensorBoard watches logs folder
- **Config & i18n** feed parameters into both pipelines
- **External tools** (FFmpeg) handle audio I/O

##### Architectural Patterns
- **Modular Separation** between UI, Inference, Training, Config, Utils
- **Plugin-style F0Predictors** (Harvest, Dio, Crepe, hybrid) under `lib/infer_pack/modules`
- **Retrieval-based conversion** using a Faiss index for top-1 matching
- **Stateful CLI Navigator** implementing a finite-state menu

##### Technologies
- Python 3.8+
- Gradio for Web UI
- PyTorch & ONNX (optional)
- Faiss for indexing
- FFmpeg for audio processing
- Docker & GitHub Actions for CI/CD

##### Putting It All Together
- **Top Row**: User Clients (Browser / CLI) → UI Layer
- **Middle Row**:
– Config & i18n loader → splits into Inference vs Training pipelines
– Inference: F0 Extract → Retrieval → Model → Post-proc → Output
– Training: Preproc → Feature Extract → Model Train → Checkpoint & Logs
- **Bottom Row**: Data Stores & External Tools
– Model repositories, indexes, audio folders, TensorBoard, FFmpeg

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Clients
    subgraph "User Clients"
        Browser["Browser (Gradio)"]:::frontend
        CLI["Terminal (CLI)"]:::frontend
    end

    %% UI Layer
    subgraph "UI Layer"
        WebUI["Web UI"]:::frontend
        CLIUI["CLI Interface"]:::frontend
    end

    Browser -->|"use web UI"| WebUI
    CLI -->|"use CLI"| CLIUI

    WebUI -->|passes parameters| Config
    CLIUI -->|passes parameters| Config

    %% Configuration & Localization
    Config["Config & i18n Loader"]:::processing

    %% Inference Pipeline
    subgraph "Inference Pipeline" 
        subgraph "F0 Extraction"
            Dio["DioF0Predictor"]:::processing
            Harvest["HarvestF0Predictor"]:::processing
            PM["PMF0Predictor"]:::processing
            BaseF0["F0Predictor"]:::processing
        end
        subgraph "Feature Packing"
            Transforms["transforms.py"]:::processing
            Commons["commons.py"]:::processing
        end
        Retrieval["Retrieval Index Lookup"]:::processing
        subgraph "Conversion Model"
            ModelsPy["models.py"]:::processing
            ONNX["models_onnx.py"]:::processing
            DML["models_dml.py"]:::processing
            UVR5["lib_v5"]:::processing
        end
        Post["Post-Processing"]:::processing
        Out["Output WAV"]:::datastore
    end

    Config -->|config params| Dio
    Config -->|config params| Harvest
    Config -->|config params| PM
    Config -->|config params| BaseF0

    Dio --> Transforms
    Harvest --> Transforms
    PM --> Transforms
    BaseF0 --> Transforms

    Transforms --> Commons
    Commons --> Retrieval
    Retrieval --> ModelsPy
    Retrieval --> ONNX
    Retrieval --> DML
    Retrieval --> UVR5
    UVR5 --> Post
    ModelsPy --> Post
    ONNX --> Post
    DML --> Post

    Post --> Out

    %% Training Pipeline
    subgraph "Training Pipeline"
        Preproc["Data Preprocessing"]:::processing
        Feat["Feature Extraction"]:::processing
        Train["Model Training"]:::processing
        Logging["Logging & Checkpointing"]:::processing
        TB["TensorBoard"]:::external
    end

    Config -->|config params| Preproc
    Preproc --> Feat
    Feat --> Train
    Train --> Logging
    Logging -->|watch logs| TB

    %% Data & Storage
    subgraph "Data Stores"
        AudioIn["audios/"]:::datastore
        AudioOut["audio-outputs/"]:::datastore
        ModelsStore["pretrained/, pretrained_v2/, weights/, uvr5_weights/"]:::datastore
        Indexes["logs/*/.index"]:::datastore
        LogsStore["logs/"]:::datastore
    end

    Out --> AudioOut
    Retrieval --> Indexes
    Logging --> LogsStore
    UVR5 --> ModelsStore
    ModelsPy --> ModelsStore
    ONNX --> ModelsStore
    DML --> ModelsStore

    %% External Dependencies
    subgraph "External"
        FFmpeg["FFmpeg/ffprobe"]:::external
        DockerCI["Dockerfile & CI/CD"]:::external
    end

    Post -->|audio I/O| FFmpeg
    WebUI -->|container| DockerCI
    CLIUI -->|container| DockerCI

    %% Click Events
    click WebUI "https://github.com/mangio621/mangio-rvc-fork/blob/main/app.py"
    click WebUI "https://github.com/mangio621/mangio-rvc-fork/blob/main/infer-web.py"
    click CLIUI "https://github.com/mangio621/mangio-rvc-fork/blob/main/infer-web.py"
    click CLIUI "https://github.com/mangio621/mangio-rvc-fork/blob/main/go-web.bat"
    click CLIUI "https://github.com/mangio621/mangio-rvc-fork/blob/main/run.sh"
    click Dio "https://github.com/mangio621/mangio-rvc-fork/blob/main/lib/infer_pack/modules/F0Predictor/DioF0Predictor.py"
    click Harvest "https://github.com/mangio621/mangio-rvc-fork/blob/main/lib/infer_pack/modules/F0Predictor/HarvestF0Predictor.py"
    click PM "https://github.com/mangio621/mangio-rvc-fork/blob/main/lib/infer_pack/modules/F0Predictor/PMF0Predictor.py"
    click BaseF0 "https://github.com/mangio621/mangio-rvc-fork/blob/main/lib/infer_pack/modules/F0Predictor/F0Predictor.py"
    click Transforms "https://github.com/mangio621/mangio-rvc-fork/blob/main/lib/infer_pack/transforms.py"
    click Commons "https://github.com/mangio621/mangio-rvc-fork/blob/main/lib/infer_pack/commons.py"
    click Indexes "https://github.com/mangio621/mangio-rvc-fork/tree/main/logs/"
    click ModelsPy "https://github.com/mangio621/mangio-rvc-fork/blob/main/lib/infer_pack/models.py"
    click ONNX "https://github.com/mangio621/mangio-rvc-fork/blob/main/lib/infer_pack/models_onnx.py"
    click DML "https://github.com/mangio621/mangio-rvc-fork/blob/main/lib/infer_pack/models_dml.py"
    click UVR5 "https://github.com/mangio621/mangio-rvc-fork/tree/main/lib/uvr5_pack/lib_v5/"
    click Post "https://github.com/mangio621/mangio-rvc-fork/blob/main/my_utils.py"
    click Preproc "https://github.com/mangio621/mangio-rvc-fork/blob/main/train/data_utils.py"
    click Preproc "https://github.com/mangio621/mangio-rvc-fork/blob/main/train/mel_processing.py"
    click Feat "https://github.com/mangio621/mangio-rvc-fork/blob/main/train/losses.py"
    click Feat "https://github.com/mangio621/mangio-rvc-fork/blob/main/train/utils.py"
    click Train "https://github.com/mangio621/mangio-rvc-fork/blob/main/train/process_ckpt.py"
    click Train "https://github.com/mangio621/mangio-rvc-fork/blob/main/train/utils.py"
    click Logging "https://github.com/mangio621/mangio-rvc-fork/tree/main/Makefile"
    click Config "https://github.com/mangio621/mangio-rvc-fork/blob/main/config.py"
    click Config "https://github.com/mangio621/mangio-rvc-fork/blob/main/configs/32k.json"
    click Config "https://github.com/mangio621/mangio-rvc-fork/blob/main/configs/32k_v2.json"
    click Config "https://github.com/mangio621/mangio-rvc-fork/blob/main/configs/40k.json"
    click Config "https://github.com/mangio621/mangio-rvc-fork/blob/main/configs/48k.json"
    click Config "https://github.com/mangio621/mangio-rvc-fork/blob/main/configs/48k_v2.json"
    click Config "https://github.com/mangio621/mangio-rvc-fork/blob/main/i18n.py"
    click Config "https://github.com/mangio621/mangio-rvc-fork/blob/main/i18n/locale_diff.py"
    click Config "https://github.com/mangio621/mangio-rvc-fork/blob/main/i18n/en.json"
    click Config "https://github.com/mangio621/mangio-rvc-fork/blob/main/i18n/zh.json"
    click AudioIn "https://github.com/mangio621/mangio-rvc-fork/tree/main/audios/"
    click AudioOut "https://github.com/mangio621/mangio-rvc-fork/tree/main/audio-outputs/"
    click ModelsStore "https://github.com/mangio621/mangio-rvc-fork/tree/main/pretrained/"
    click ModelsStore "https://github.com/mangio621/mangio-rvc-fork/tree/main/pretrained_v2/"
    click ModelsStore "https://github.com/mangio621/mangio-rvc-fork/tree/main/weights/"
    click ModelsStore "https://github.com/mangio621/mangio-rvc-fork/tree/main/uvr5_weights/"
    click DockerCI "https://github.com/mangio621/mangio-rvc-fork/tree/main/Dockerfile"
    click DockerCI "https://github.com/mangio621/mangio-rvc-fork/blob/main/.github/workflows/ci.yml"
    click FFmpeg "https://github.com/mangio621/mangio-rvc-fork/blob/main/stftpitchshift.exe"
    click FFmpeg "https://github.com/mangio621/mangio-rvc-fork/blob/main/stftpitchshift.lib"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef processing fill:#E6FFEA,stroke:#28a745,color:#28a745;
    classDef datastore fill:#FFF4E5,stroke:#FF8C00,color:#FF8C00;
    classDef external fill:#F0F0F0,stroke:#6a737d,color:#6a737d;
```
