# auto-d/shaperx architecture

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

- Interactive diagram: https://gitdiagram.com/auto-d/shaperx
- Repository: https://github.com/auto-d/shaperx

## Overview

##### Project type and purpose
- It bundles a PyTorch-based CNN pipeline (model training/inference) with a Gradio UI for interactive demos.

##### File structure
Top level
- app/
– app.py       → Entrypoint for Gradio UI and inference pipeline
– cnn.py       → Convolutional neural network definition and forward logic
– dataset.py   → Dataset loading, preprocessing, and data-augmentation code
- data/          → Tab-delimited dataset manifests and associated 3D model artifacts (STLs)
- experimentation.ipynb → Notebook for exploratory model development and evaluation
- requirements.txt     → Python dependencies (PyTorch, Gradio, Open3D, etc.)
- README.md      → Project overview, run instructions, and known issues

##### README for additional insights
- The pipeline stages run sequentially: raw 3D models → histogram/non-DL baselines → CNN training → Gradio UI for demo.
- Deployment is local (Gradio on port 7860), with hard-coded paths to data/.
- Key external libs: PyTorch, Gradio, Open3D (for mesh loading).

##### Main components
a. Data Layer
- Raw 3D model files (.stl) and manifest files in data/
b. Preprocessing & Dataset Loader
- dataset.py: loads meshes via Open3D, applies scaling/lighting, sampling, converts to images/tensors
c. Model Training & Inference
- cnn.py: defines model architecture, loss, metrics
- experimentation.ipynb: dev/testing harness
d. Application Layer (Gradio UI)
- app.py: ties together data download, preprocessing, model inference, and UI widgets
e. Environment & Dependencies
- Python runtime, PyTorch, Gradio, Open3D

##### Relationships and interactions
- Data files → dataset.py → tensor batches
- Batches → cnn.py (training/inference) → prediction labels/confidence
- Predictions → app.py → displayed in Gradio frontend
- experimentation.ipynb sits off to the side: pulls from dataset.py & cnn.py for experiments

##### Architectural patterns & design principles
- Separation of concerns: data loading vs. model logic vs. UI
- Modular ML pipeline: interchangeable preprocessing or model components
- Single-process, single-repo deploy (no microservices)

##### Essential elements
- Clear component names and boundaries
- Arrowheads indicating data flow (preprocessed → model → predictions)
- Third-party dependencies next to each module (e.g., “PyTorch”, “Gradio”, “Open3D”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DL1["MedShapeNetDataset.txt"]:::data
        DL2["MedShapeNetDataset_vertebrae.txt"]:::data
        DL3["MedShapeNetDataset_vertebrae_labeled.txt"]:::data
        DL4["MedShapeNetDataset_vertebrae_min_labeled.txt"]:::data
    end

    %% Processing Layer
    subgraph "Processing Layer"
        direction TB
        DLoader["dataset.py\n(Open3D loader + transforms)"]:::processing
    end

    %% Model Layer
    subgraph "Model Layer"
        direction TB
        CNN["cnn.py\n(PyTorch CNN)"]:::processing
    end

    %% UI Layer
    subgraph "UI Layer"
        direction TB
        App["app.py\n(Gradio endpoints)"]:::ui
    end

    %% Experimentation Notebook
    Notebook["experimentation.ipynb\n(Jupyter Notebook)"]:::ui

    %% Documentation & Environment
    Docs["requirements.txt\n&\nREADME.md"]:::docs

    %% Data Flow
    DL1 -->|loads| DLoader
    DL2 -->|loads| DLoader
    DL3 -->|loads| DLoader
    DL4 -->|loads| DLoader
    DLoader -->|batches→tensors| CNN
    CNN -->|predictions| App
    App -->|serves UI| UI["Gradio Frontend"]:::ui

    %% Notebook interactions
    Notebook -.->|imports| DLoader
    Notebook -.->|imports| CNN

    %% Docs reference
    Docs -.->|specifies deps| DLoader
    Docs -.->|specifies deps| CNN
    Docs -.->|specifies deps| App

    %% Click Events
    click DL1 "https://github.com/auto-d/shaperx/blob/main/data/MedShapeNetDataset.txt"
    click DL2 "https://github.com/auto-d/shaperx/blob/main/data/MedShapeNetDataset_vertebrae.txt"
    click DL3 "https://github.com/auto-d/shaperx/blob/main/data/MedShapeNetDataset_vertebrae_labeled.txt"
    click DL4 "https://github.com/auto-d/shaperx/blob/main/data/MedShapeNetDataset_vertebrae_min_labeled.txt"
    click DLoader "https://github.com/auto-d/shaperx/blob/main/app/dataset.py"
    click CNN "https://github.com/auto-d/shaperx/blob/main/app/cnn.py"
    click App "https://github.com/auto-d/shaperx/blob/main/app/app.py"
    click Notebook "https://github.com/auto-d/shaperx/blob/main/experimentation.ipynb"
    click Docs "https://github.com/auto-d/shaperx/blob/main/requirements.txt"

    %% Styles
    classDef data fill:#a2f5a2,stroke:#038f03,color:#034d03;
    classDef processing fill:#a0c4ff,stroke:#023e7d,color:#001845;
    classDef ui fill:#ffd6a5,stroke:#d65a31,color:#5a2a27;
    classDef docs fill:#e0e0e0,stroke:#888888,color:#333333;
```
