# supertone-inc/supertonic architecture

> Architecture diagram of the GitHub repository supertone-inc/supertonic, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/supertone-inc/supertonic
- Repository: https://github.com/supertone-inc/supertonic

## Overview

1. **What this repo is**
   - This repository is not a single application; it is a **multi-runtime example and packaging repo** for the Supertonic on-device TTS model.
   - The actual inference product is the **shared ONNX model assets**; the code here shows how to wire that model into different languages and platforms.

2. **Main boundary: model assets vs. sample code**
   - Each runtime folder has an `assets/` directory expected to contain the downloaded Supertonic checkpoint and preset voice data.
   - The README makes clear that the first run can fetch these assets from **Hugging Face**, and all examples stay local after that.
   - This creates the key architectural boundary: **text input and voice settings in the app/runtime → ONNX Runtime inference → WAV audio output**.

3. **Shared execution pattern across all runtimes**
   - The examples all follow the same high-level flow:
     - normalize/load model assets from local `assets/`
     - prepare text, language code, voice/style inputs
     - run ONNX inference
     - emit 44.1 kHz WAV audio or playback it directly
   - The repo is therefore organized around **portable inference adapters**, not around a central service or backend.

4. **Python as the reference implementation**
   - `py/` is the most complete reference path and includes:
     - `example_onnx.py` for direct local inference
     - `example_pypi.py` for package-style usage
     - `helper.py` for shared loading/synthesis utilities
   - Its tooling (`pyproject.toml`, `requirements.txt`, `uv.lock`) indicates it is the primary “getting started” environment and likely the clearest canonical API shape.

5. **C/C++-style native runtime layer**
   - `cpp/` is a CMake-based native sample using `example_onnx.cpp`, `helper.cpp`, and `helper.h`.
   - This is the lowest-level integration path in the repo and likely mirrors how other non-managed runtimes invoke ONNX Runtime directly.
   - Because it is native, this folder represents the boundary where model execution is closest to the host OS and filesystem.

6. **Managed desktop/runtime bindings**
   - `csharp/`, `java/`, `go/`, `rust/`, and `swift/` each implement the same inference idea in their ecosystem’s idiomatic packaging:
     - C# uses a `.csproj`
     - Java uses Maven
     - Go uses modules
     - Rust uses Cargo
     - Swift uses Swift Package Manager
   - These folders are separate integration surfaces, but architecturally they are all wrappers around the same local ONNX model execution.

7. **Node.js and browser paths**
   - `nodejs/` is the server-side JavaScript example, while `web/` is the browser example.
   - The browser stack is materially different because it uses **client-side inference via `onnxruntime-web`**, with `index.html`, `main.js`, `helper.js`, `style.css`, and Vite config supporting a static dev/build workflow.
   - This is the only path in the repo that is explicitly browser-native and does not depend on a desktop runtime.

8. **Mobile and app-shell integrations**
   - `ios/ExampleiOSApp` is a full SwiftUI iOS sample, with dedicated files for:
     - `TTSService` for synthesis orchestration
     - `TTSViewModel` for app state
     - `AudioPlayer` for playback
     - `ContentView` for the UI
   - `flutter/` is the cross-platform app wrapper, and its `macos/` subtree shows it is configured as a desktop-capable Flutter app rather than a generic library.
   - These platforms are important because they show how the same model can be embedded inside a UI app with playback and state management.

9. **Support code inside each example**
   - Many runtimes include a `Helper.*` file alongside the entry example file.
   - These helpers are the local abstraction layer for repetitive tasks such as loading assets, configuring the model session, and writing audio output.
   - In architectural terms, they are the **runtime-specific glue** between the app entrypoint and the shared model assets.

10. **Tooling and build boundaries**
   - Build systems are deliberately per-language, not centralized:
     - C++: CMake
     - Java: Maven
     - Rust: Cargo
     - Go: module tooling
     - Node/web: npm + Vite
     - Swift: Swift Package Manager
     - iOS: Xcodegen-generated Xcode project
     - Python: uv/pyproject-based environment
     - C#: .NET project file
   - This reinforces that the repo is a **polyglot SDK/demo collection**, not a single cross-language framework.

11. **Test and orchestration**
   - `test_all.sh` suggests a repo-level smoke-test or validation script that likely exercises multiple example paths.
   - The existence of this script is a clue that the examples are intended to stay behaviorally aligned across runtimes.

12. **Infrastructure and external dependency**
   - The only material external infrastructure is **Hugging Face Hub** for model download/storage.
   - There is no cloud inference service in this repo; the architecture is explicitly **offline/local-first**, with optional first-run asset download.

13. **How to draw the diagram**
   - A good architecture diagram would show:
     - a shared **Supertonic model assets** block
     - multiple **runtime adapters** around it (Python, native, JVM, .NET, Go, Rust, Swift, Node, browser, iOS, Flutter)
     - a common data flow from **text + language + voice/style inputs** to **ONNX Runtime / onnxruntime-web** to **audio output**
     - optional initial dependency arrow from **Hugging Face** to the local `assets/` folder
   - The main architectural point is that all examples are parallel front doors into the same local TTS model, not separate products.

Main entry points: [`py/example_onnx.py`](https://github.com/supertone-inc/supertonic/blob/main/py/example_onnx.py) (Python sample), [`cpp/example_onnx.cpp`](https://github.com/supertone-inc/supertonic/blob/main/cpp/example_onnx.cpp) (C++ sample), [`web/main.js`](https://github.com/supertone-inc/supertonic/blob/main/web/main.js) (Web app), [`test_all.sh`](https://github.com/supertone-inc/supertonic/blob/main/test_all.sh) (Smoke tests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core model"]
  node_huggingface(("Hugging Face<br/>external source"))
  node_assets[("Model assets<br/>local checkpoint")]
  node_input["Text + voice<br/>app input"]
  node_ort{{"ONNX Runtime<br/>inference engine"}}
  node_audio["WAV output<br/>audio render"]
end

subgraph group_python["Python"]
  node_py_ref["Python sample<br/>reference runtime<br/>[example_onnx.py]"]
  node_py_helper["Python helper<br/>shared glue<br/>[helper.py]"]
end

subgraph group_native["Native"]
  node_cpp_sample["C++ sample<br/>native runtime<br/>[example_onnx.cpp]"]
  node_cpp_helper["C++ helper<br/>native glue<br/>[helper.cpp]"]
end

subgraph group_managed["Managed runtimes"]
  node_csharp["C# sample<br/>managed runtime<br/>[ExampleONNX.cs]"]
  node_java["Java sample<br/>managed runtime<br/>[ExampleONNX.java]"]
  node_go["Go sample<br/>managed runtime<br/>[example_onnx.go]"]
  node_rust["Rust sample<br/>managed runtime<br/>[example_onnx.rs]"]
  node_swift["Swift sample<br/>managed runtime<br/>[ExampleONNX.swift]"]
end

subgraph group_js["JavaScript"]
  node_ortweb{{"ORT Web<br/>browser engine"}}
  node_nodejs["Node sample<br/>js runtime<br/>[example_onnx.js]"]
  node_webapp["Web app<br/>browser app<br/>[main.js]"]
end

subgraph group_mobile["Mobile apps"]
  node_iosapp["iOS app<br/>mobile app<br/>[TTSService.swift]"]
  node_flutterapp["Flutter app<br/>cross-platform app<br/>[main.dart]"]
end

subgraph group_tooling["Tooling"]
  node_testall["Smoke tests<br/>repo validation<br/>[test_all.sh]"]
end

node_huggingface -->|"download"| node_assets
node_assets -->|"load"| node_py_ref
node_assets -->|"load"| node_cpp_sample
node_assets -->|"load"| node_csharp
node_assets -->|"load"| node_java
node_assets -->|"load"| node_go
node_assets -->|"load"| node_rust
node_assets -->|"load"| node_swift
node_assets -->|"load"| node_nodejs
node_assets -->|"load"| node_webapp
node_assets -->|"load"| node_iosapp
node_assets -->|"load"| node_flutterapp
node_py_ref -->|"uses"| node_py_helper
node_cpp_sample -->|"uses"| node_cpp_helper
node_input -->|"feeds"| node_py_ref
node_input -->|"feeds"| node_cpp_sample
node_input -->|"feeds"| node_csharp
node_input -->|"feeds"| node_java
node_input -->|"feeds"| node_go
node_input -->|"feeds"| node_rust
node_input -->|"feeds"| node_swift
node_input -->|"feeds"| node_nodejs
node_input -->|"feeds"| node_webapp
node_input -->|"feeds"| node_iosapp
node_input -->|"feeds"| node_flutterapp
node_py_ref -->|"runs on"| node_ort
node_cpp_sample -->|"runs on"| node_ort
node_csharp -->|"runs on"| node_ort
node_java -->|"runs on"| node_ort
node_go -->|"runs on"| node_ort
node_rust -->|"runs on"| node_ort
node_swift -->|"runs on"| node_ort
node_nodejs -->|"runs on"| node_ort
node_webapp -->|"runs on"| node_ortweb
node_iosapp -->|"runs on"| node_ort
node_flutterapp -->|"runs on"| node_ort
node_ort -->|"emits"| node_audio
node_ortweb -->|"emits"| node_audio
node_testall -.->|"checks"| node_py_ref
node_testall -.->|"checks"| node_cpp_sample
node_testall -.->|"checks"| node_webapp

click node_py_ref "https://github.com/supertone-inc/supertonic/blob/main/py/example_onnx.py"
click node_py_helper "https://github.com/supertone-inc/supertonic/blob/main/py/helper.py"
click node_cpp_sample "https://github.com/supertone-inc/supertonic/blob/main/cpp/example_onnx.cpp"
click node_cpp_helper "https://github.com/supertone-inc/supertonic/blob/main/cpp/helper.cpp"
click node_csharp "https://github.com/supertone-inc/supertonic/blob/main/csharp/ExampleONNX.cs"
click node_java "https://github.com/supertone-inc/supertonic/blob/main/java/ExampleONNX.java"
click node_go "https://github.com/supertone-inc/supertonic/blob/main/go/example_onnx.go"
click node_rust "https://github.com/supertone-inc/supertonic/blob/main/rust/src/example_onnx.rs"
click node_swift "https://github.com/supertone-inc/supertonic/blob/main/swift/Sources/ExampleONNX.swift"
click node_nodejs "https://github.com/supertone-inc/supertonic/blob/main/nodejs/example_onnx.js"
click node_webapp "https://github.com/supertone-inc/supertonic/blob/main/web/main.js"
click node_iosapp "https://github.com/supertone-inc/supertonic/blob/main/ios/ExampleiOSApp/TTSService.swift"
click node_flutterapp "https://github.com/supertone-inc/supertonic/blob/main/flutter/lib/main.dart"
click node_testall "https://github.com/supertone-inc/supertonic/blob/main/test_all.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_huggingface,node_assets,node_input,node_ort,node_audio,node_testall toneBlue
class node_py_ref,node_py_helper toneAmber
class node_cpp_sample,node_cpp_helper toneMint
class node_csharp,node_java,node_go,node_rust,node_swift toneRose
class node_ortweb,node_nodejs,node_webapp toneIndigo
class node_iosapp,node_flutterapp toneTeal
```

## Components

### Core model

Shared local assets and inference boundary

- **Hugging Face**: external source · Optional first-run model download source
- **Model assets**: local checkpoint · Downloaded Supertonic checkpoint and voice data under each runtime's assets folder
- **Text + voice**: app input · Text, language, voice, and style settings
- **ONNX Runtime**: inference engine · Local model execution for desktop, mobile, and native runtimes
- **WAV output**: audio render · 44.1 kHz synthesized audio or direct playback

### Python

Reference implementation and package-style usage

- [Python sample](https://github.com/supertone-inc/supertonic/blob/main/py/example_onnx.py): reference runtime · Primary Python path for direct inference and package-style usage · `py/example_onnx.py`
- [Python helper](https://github.com/supertone-inc/supertonic/blob/main/py/helper.py): shared glue · Shared loading and synthesis utilities · `py/helper.py`

### Native

Lowest-level C/C++ integration

- [C++ sample](https://github.com/supertone-inc/supertonic/blob/main/cpp/example_onnx.cpp): native runtime · CMake-based direct ONNX Runtime integration · `cpp/example_onnx.cpp`
- [C++ helper](https://github.com/supertone-inc/supertonic/blob/main/cpp/helper.cpp): native glue · Native asset loading and synthesis support · `cpp/helper.cpp`

### Managed runtimes

Language-specific wrappers around local ONNX inference

- [C# sample](https://github.com/supertone-inc/supertonic/blob/main/csharp/ExampleONNX.cs): managed runtime · .NET example for local inference · `csharp/ExampleONNX.cs`
- [Java sample](https://github.com/supertone-inc/supertonic/blob/main/java/ExampleONNX.java): managed runtime · Maven-based JVM example · `java/ExampleONNX.java`
- [Go sample](https://github.com/supertone-inc/supertonic/blob/main/go/example_onnx.go): managed runtime · Go module example for local inference · `go/example_onnx.go`
- [Rust sample](https://github.com/supertone-inc/supertonic/blob/main/rust/src/example_onnx.rs): managed runtime · Cargo-based example using local assets · `rust/src/example_onnx.rs`
- [Swift sample](https://github.com/supertone-inc/supertonic/blob/main/swift/Sources/ExampleONNX.swift): managed runtime · Swift Package Manager example · `swift/Sources/ExampleONNX.swift`

### JavaScript

Node.js and browser paths

- **ORT Web**: browser engine · Client-side ONNX inference in the browser
- [Node sample](https://github.com/supertone-inc/supertonic/blob/main/nodejs/example_onnx.js): js runtime · Server-side JavaScript example · `nodejs/example_onnx.js`
- [Web app](https://github.com/supertone-inc/supertonic/blob/main/web/main.js): browser app · Static browser example with Vite and onnxruntime-web · `web/main.js`

### Mobile apps

iOS and Flutter app shells

- [iOS app](https://github.com/supertone-inc/supertonic/blob/main/ios/ExampleiOSApp/TTSService.swift): mobile app · SwiftUI sample with service, view model, and audio playback · `ios/ExampleiOSApp/TTSService.swift`
- [Flutter app](https://github.com/supertone-inc/supertonic/blob/main/flutter/lib/main.dart): cross-platform app · Flutter wrapper with macOS-capable app shell · `flutter/lib/main.dart`

### Tooling

Repo-level validation and smoke testing

- [Smoke tests](https://github.com/supertone-inc/supertonic/blob/main/test_all.sh): repo validation · Repo-level script to exercise multiple example paths · `test_all.sh`

## Connections

- Hugging Face → Model assets: download · Fetch model checkpoint and voice data on first run
- Model assets → Python sample: load · Python example reads local assets
- Model assets → C++ sample: load · Native sample reads local assets
- Model assets → C# sample: load · Managed runtime reads local assets
- Model assets → Java sample: load · Managed runtime reads local assets
- Model assets → Go sample: load · Managed runtime reads local assets
- Model assets → Rust sample: load · Managed runtime reads local assets
- Model assets → Swift sample: load · Managed runtime reads local assets
- Model assets → Node sample: load · Node.js example reads local assets
- Model assets → Web app: load · Browser example loads bundled local assets
- Model assets → iOS app: load · iOS sample reads local assets
- Model assets → Flutter app: load · Flutter sample reads local assets
- Python sample → Python helper: uses · Shared Python synthesis utilities
- C++ sample → C++ helper: uses · Native helper utilities
- Text + voice → Python sample: feeds · Text, language, and voice settings
- Text + voice → C++ sample: feeds · Text, language, and voice settings
- Text + voice → C# sample: feeds · Text, language, and voice settings
- Text + voice → Java sample: feeds · Text, language, and voice settings
- Text + voice → Go sample: feeds · Text, language, and voice settings
- Text + voice → Rust sample: feeds · Text, language, and voice settings
- Text + voice → Swift sample: feeds · Text, language, and voice settings
- Text + voice → Node sample: feeds · Text, language, and voice settings
- Text + voice → Web app: feeds · Text, language, and voice settings
- Text + voice → iOS app: feeds · Text, language, and voice settings
- Text + voice → Flutter app: feeds · Text, language, and voice settings
- Python sample → ONNX Runtime: runs on · Python invokes local ONNX inference
- C++ sample → ONNX Runtime: runs on · C++ invokes local ONNX inference
- C# sample → ONNX Runtime: runs on · C# invokes local ONNX inference
- Java sample → ONNX Runtime: runs on · Java invokes local ONNX inference
- Go sample → ONNX Runtime: runs on · Go invokes local ONNX inference
- Rust sample → ONNX Runtime: runs on · Rust invokes local ONNX inference
- Swift sample → ONNX Runtime: runs on · Swift invokes local ONNX inference
- Node sample → ONNX Runtime: runs on · Node.js invokes local ONNX inference
- Web app → ORT Web: runs on · Browser uses onnxruntime-web
- iOS app → ONNX Runtime: runs on · iOS sample invokes local ONNX inference
- Flutter app → ONNX Runtime: runs on · Flutter sample invokes local ONNX inference
- ONNX Runtime → WAV output: emits · Synthesized WAV or playable audio
- ORT Web → WAV output: emits · Browser playback output
- Smoke tests → Python sample: checks · Smoke test across example paths
- Smoke tests → C++ sample: checks · Smoke test across example paths
- Smoke tests → Web app: checks · Smoke test across example paths
