# sivapprakash-chinnaraj/mgc architecture

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

- Interactive diagram: https://gitdiagram.com/sivapprakash-chinnaraj/mgc
- Repository: https://github.com/sivapprakash-chinnaraj/mgc

## Overview

##### Project type and purpose
- This is a machine-learning pipeline plus lightweight web UI. It ingests audio files, converts them into mel spectrograms, trains a CNN model, and exposes inference via a Streamlit app.

##### File structure
- Top level:
- app.py – Streamlit front-end for model inference
- notebooks/ – exploratory notebooks and saved model artifacts
- requirements.txt – dependencies
- src/
- preprocessing.py – audio → mel spectrogram conversion
- (implicitly) model.py – CNN training and evaluation (referenced in README)
- Generated artifacts during runtime:
- notebooks/genre_classifier_model.h5 and model.h5 – trained model binaries
- spectrograms/ folder (not shown but described) – image dataset

##### Extract key architecture insights from README
- Two distinct pipelines:
a. Data preparation: audio files → spectrogram generation → image dataset
b. Model lifecycle: training (model.py) → saved model → inference (app.py)
- Technologies: Python, Librosa (audio processing), TensorFlow (CNN), Streamlit (UI)

##### Main components
a. Data layer
- Raw audio files (DATA STORE)
- Spectrogram artifact store (FILE SYSTEM or object storage)
b. Processing layer
- Preprocessing module (preprocessing.py)
- Model training module (model.py)
c. Model artifact
- Trained CNN model (model.h5)
d. Serving layer
- Streamlit app (app.py)
- User interface (browser)
e. External services/libraries
- Librosa, NumPy, TensorFlow, Pillow, Matplotlib, Scikit-learn

##### Relationships and interactions (data flow)
1. Raw audio → preprocessing.py → mel spectrogram PNGs
2. Spectrograms → model.py → train CNN → output model.h5
3. User uploads .wav in Streamlit UI → app.py
4. app.py calls preprocessing logic (in-memory) → converts to spectrogram → loads model.h5 → predicts genre → displays result

##### Architectural patterns and principles
- Layered pipeline: clear separation of preprocessing, training, serving
- Artifact versioning: model binaries stored alongside code
- Single codebase monolith: uses modules rather than microservices
- Reusability: preprocessing module shared by training and inference

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Data Layer
  subgraph "Data Layer"
    RawAudio["Raw Audio Files"]:::storage
    SpectrogramStore["Spectrogram Store (PNG)"]:::storage
  end

  %% Preprocessing & Feature Generation
  subgraph "Preprocessing & Feature Generation"
    Preprocessing["Preprocessing Module"]:::compute
    TestNotebook["Exploratory Notebook"]:::compute
  end

  %% Model Training & Artifacts
  subgraph "Model Training & Artifacts"
    ModelTraining["Model Training Module"]:::compute
    ModelArtifact["Trained Model Artifact"]:::storage
  end

  %% Serving & UI
  subgraph "Serving & UI"
    StreamlitApp["Streamlit App"]:::ui
    UserBrowser["User Interface (Browser)"]:::ui
  end

  %% Documentation & Config
  subgraph "Documentation & Config"
    Requirements["requirements.txt"]:::docs
    Readme["README.md"]:::docs
  end

  %% External Libraries
  subgraph "Libraries"
    Librosa["Librosa"]:::ext
    TensorFlow["TensorFlow"]:::ext
    Others["NumPy, Matplotlib, Pillow, Scikit-learn"]:::ext
  end

  %% Data Flow
  RawAudio -->|"Load WAV"| Preprocessing
  Preprocessing -->|"Generate Mel-Spectrogram"| SpectrogramStore
  SpectrogramStore -->|"Load Spectrograms"| ModelTraining
  ModelTraining -->|"Train CNN"| ModelArtifact

  UserBrowser -->|"Upload WAV"| StreamlitApp
  StreamlitApp -->|"Call Preprocessing"| Preprocessing
  StreamlitApp -->|"Load Model"| ModelArtifact
  StreamlitApp -->|"Predict Genre"| StreamlitApp
  StreamlitApp -->|"Display Result"| UserBrowser

  %% Dependencies Usage
  Librosa --> Preprocessing
  TensorFlow --> ModelTraining
  Others --> Preprocessing
  Others --> ModelTraining
  Others --> StreamlitApp

  Requirements --> Preprocessing
  Requirements --> ModelTraining
  Requirements --> StreamlitApp

  Readme --> RawAudio
  Readme --> SpectrogramStore
  Readme --> Preprocessing
  Readme --> ModelTraining
  Readme --> StreamlitApp

  %% Click Events
  click Preprocessing "https://github.com/sivapprakash-chinnaraj/mgc/blob/main/src/preprocessing.py"
  click StreamlitApp "https://github.com/sivapprakash-chinnaraj/mgc/blob/main/app.py"
  click ModelArtifact "https://github.com/sivapprakash-chinnaraj/mgc/blob/main/notebooks/genre_classifier_model.h5"
  click TestNotebook "https://github.com/sivapprakash-chinnaraj/mgc/blob/main/notebooks/test_preprocessing.ipynb"
  click Requirements "https://github.com/sivapprakash-chinnaraj/mgc/blob/main/requirements.txt"
  click Readme "https://github.com/sivapprakash-chinnaraj/mgc/blob/main/README.md"

  %% Styles
  classDef storage fill:#cfe2f3,stroke:#08519c,stroke-width:1px;
  classDef compute fill:#d4efdf,stroke:#196f3d,stroke-width:1px;
  classDef ui fill:#fce5cd,stroke:#a63d40,stroke-width:1px;
  classDef docs fill:#eeeeee,stroke:#666666,stroke-width:1px,stroke-dasharray: 2 2;
  classDef ext fill:#fcf8e3,stroke:#8a6d3b,stroke-width:1px;
```
