# g-nitin/artedge architecture

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

- Interactive diagram: https://gitdiagram.com/g-nitin/artedge
- Repository: https://github.com/g-nitin/artedge

## Overview

##### Project Type and Purpose
- Type: A mobile-first iOS application (Swift/SwiftUI) for real-time Neural Style Transfer (NST) on device, accompanied by an offline Python-based model development and conversion pipeline.
- Purpose: Demonstrate edge-computing NST: train/adapt models in PyTorch, convert to Core ML, and run in an iOS app with low latency & privacy.

##### File Structure
- Top-Level Directories
– ArtEdge/: iOS app source – UI (ContentView, CameraPreviewView, ImagePicker), service (CameraService, StyleTransferService), assets, and Core ML models (.mlpackage).
– models/: Python code – training/inference for four NST architectures (AdaIN, FST, StyTR-2, AesFA), plus conversion scripts.
- Key Config/Project Files:
– ArtEdge.xcodeproj: Xcode project definition.
– pyproject.toml / uv.lock: Python dependency management.
– convert.py scripts – transform PyTorch models → Core ML packages.

##### Main Components
A. Model Development Pipeline (Offline)
1. PyTorch Training Modules (models/AdaIN, AesFA, FST, StyTR-2)
2. convert.py & Core ML Tools (TorchScript → .mlpackage)
3. Generated Core ML Models (.mlpackage files in ArtEdge/models/)

B. iOS Application (Runtime)
1. UI Layer (SwiftUI Views: ContentView, CameraPreviewView, ImagePicker)
2. Service Layer (CameraService captures input, StyleTransferService invokes Core ML)
3. Core ML Inference Engine (Apple Core ML framework + Neural Engine hardware)
5. Hardware/OS (iOS device, Neural Engine, GPU/CPU)

C. External Frameworks & Tools
- PyTorch (model development)
- Core ML Tools (model conversion)
- SwiftUI, AVFoundation (camera), Core ML (inference)

##### Relationships & Data Flows
- Offline Flow:
PyTorch Training → TorchScript → Core ML Tools → .mlpackage → Xcode Project
- Runtime Flow:
User taps “Select Style” → UI (ContentView) passes image to StyleTransferService → Core ML model inference → Stylized image → UI displays result
- Hardware Acceleration: StyleTransferService → Core ML framework → Neural Engine/GPU → returns output buffer

##### Architectural Patterns & Design Principles
- MVVM-ish / Service Pattern in SwiftUI:
– Views bound to models (StyleInfo) and call services for business logic.
- Separation of Concerns:
– Offline model development vs. on-device inference.
– UI, services, ML inference all modular.
- Edge-Computing Principle:
– All image data and inference occur locally, no network.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Offline Pipeline
    subgraph "Offline Pipeline" 
        direction TB
        PT["PyTorch Training Modules"]:::offline
        subgraph "Training Variants"
            direction TB
            A1["AdaIN"]:::offline
            A2["AesFA"]:::offline
            A3["FST"]:::offline
            A4["StyTR-2"]:::offline
        end
        CS["Conversion Scripts"]:::offline
        GM["Generated Core ML Models"]:::offline
        PD["Python Dependencies"]:::external
    end

    %% iOS Application
    subgraph "ArtEdge iOS App" 
        direction TB
        UI["UI Layer"]:::ios
        subgraph "UI Components"
            direction TB
            U1["ArtEdgeApp.swift"]:::ios
            U2["ContentView.swift"]:::ios
            U3["CameraPreviewView.swift"]:::ios
            U4["ImagePicker.swift"]:::ios
        end
        SV["Service Layer"]:::ios
        subgraph "Service Components"
            direction TB
            S1["CameraService.swift"]:::ios
            S2["StyleTransferService.swift"]:::ios
        end
        ML["Core ML Inference Engine"]:::ios
        AS["Asset & Model Storage"]:::ios
    end

    %% External & Hardware
    subgraph "External & Hardware" 
        direction TB
        E1["PyTorch"]:::external
        E2["Core ML Tools"]:::external
        E3["SwiftUI"]:::external
        E4["AVFoundation"]:::external
        E5["Core ML Framework"]:::external
        E6["Neural Engine/GPU"]:::external
    end

    %% Offline Flow
    A1 -->|"trains model"| CS
    A2 -->|"trains model"| CS
    A3 -->|"trains model"| CS
    A4 -->|"trains model"| CS
    CS -->|"produces .mlpackage"| GM
    GM -->|"bundled into Xcode"| UI
    PD -->|"manages deps"| A1
    PD -->|"manages deps"| A2
    PD -->|"manages deps"| A3
    PD -->|"manages deps"| A4

    %% Runtime Flow
    U2 -->|"user selects style"| S2
    U3 -->|"feeds camera frames"| S1
    S2 -->|"invokes model"| ML
    ML -->|"accelerated by"| E6
    ML -->|"via Core ML"| E5
    ML -->|"returns stylized image"| U2

    %% Dependency on External Tools
    A1 -->|"uses"| E1
    CS -->|"uses"| E2
    U1 -->|"built with"| E3
    U3 -->|"built with"| E4

    %% Click Events - Training Modules
    click A1 "https://github.com/g-nitin/artedge/blob/main/models/AdaIN/code/train_adain.py"
    click A2 "https://github.com/g-nitin/artedge/blob/main/models/AesFA/code/model.py"
    click A3 "https://github.com/g-nitin/artedge/blob/main/models/FST/inference.py"
    click A4 "https://github.com/g-nitin/artedge/blob/main/models/StyTR-2/train.py"
    %% Click Events - Conversion Scripts
    click CS "https://github.com/g-nitin/artedge/blob/main/models/AdaIN/code/convert.py"
    click CS "https://github.com/g-nitin/artedge/blob/main/models/AesFA/code/convert.py"
    click CS "https://github.com/g-nitin/artedge/blob/main/models/FST/convert.py"
    click CS "https://github.com/g-nitin/artedge/blob/main/models/StyTR-2/convert.py"
    %% Click Events - Generated Models Directory
    click GM "https://github.com/g-nitin/artedge/tree/main/ArtEdge/models/"
    %% Click Events - Python Dependencies
    click PD "https://github.com/g-nitin/artedge/blob/main/models/pyproject.toml"
    click PD "https://github.com/g-nitin/artedge/blob/main/models/uv.lock"
    %% Click Events - UI Components
    click U1 "https://github.com/g-nitin/artedge/blob/main/ArtEdge/ArtEdgeApp.swift"
    click U2 "https://github.com/g-nitin/artedge/blob/main/ArtEdge/ContentView.swift"
    click U3 "https://github.com/g-nitin/artedge/blob/main/ArtEdge/CameraPreviewView.swift"
    click U4 "https://github.com/g-nitin/artedge/blob/main/ArtEdge/ImagePicker.swift"
    %% Click Events - Service Components
    click S1 "https://github.com/g-nitin/artedge/blob/main/ArtEdge/CameraService.swift"
    click S2 "https://github.com/g-nitin/artedge/blob/main/ArtEdge/StyleTransferService.swift"
    %% Click Events - Assets
    click AS "https://github.com/g-nitin/artedge/blob/main/ArtEdge/Assets.xcassets"

    %% Styles
    classDef offline fill:#D0E8FF,stroke:#004080,color:#004080
    classDef ios fill:#DFFFE0,stroke:#208020,color:#208020
    classDef external fill:#FFE8C0,stroke:#804000,color:#804000
```
