# nhattruong0205/soundsanctuary architecture

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

- Interactive diagram: https://gitdiagram.com/nhattruong0205/soundsanctuary
- Repository: https://github.com/nhattruong0205/soundsanctuary

## Overview

SoundSanctuary is an offline-first bird-sound identifier with few-shot species enrollment and an optional shared review service. The main user workflow runs from microphone or file audio through windowing and on-device inference to species/soundscape results; Document Mode can add exemplars for later matching. A separate ML pipeline builds the model and reference library consumed by the app. Edges reflect shown calls or README-documented flows; unsampled internals are represented only where the README establishes their role.

Main entry points: [`app/src/App.tsx`](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/App.tsx) (App shell), [`app/src/components/IdentifyView.tsx`](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/IdentifyView.tsx) (Identify mode), [`app/src/components/DocumentView.tsx`](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/DocumentView.tsx) (Document mode), [`app/src/lib/model.ts`](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/model.ts) (Inference client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Offline web app"]
  node_app["App shell<br/>[App.tsx]"]
  node_audio["Audio capture<br/>[audio.ts]"]
  node_identify["Identify mode<br/>[IdentifyView.tsx]"]
  node_decision["Matching &amp; priors<br/>[identify.ts]"]
  node_library["Species library<br/>[library.ts]"]
  node_modelclient["Inference client<br/>[model.ts]"]
  node_worker["Model worker<br/>[model.worker.ts]"]
  node_display["Audio visualizations<br/>[Spectrogram.tsx]"]
  node_soundscape["Soundscape bars<br/>[SoundscapeBars.tsx]"]
  node_document["Document mode<br/>[DocumentView.tsx]"]
  node_localdb[("Offline records<br/>[db.ts]")]
  node_libraryview["Library browser<br/>[LibraryView.tsx]"]
  node_settings["Settings &amp; sync<br/>[SettingsView.tsx]"]
  node_sync["Review sync client<br/>[sync.ts]"]
end

subgraph group_ml["Model pipeline"]
  node_data["Training data prep<br/>[prepare.py]"]
  node_fetch["Data acquisition<br/>[fetch_data.py]"]
  node_student["Student network<br/>[model.py]"]
  node_training["Student training<br/>[train_student.py]"]
  node_export["Quantized export<br/>[export.py]"]
  node_buildlib["Reference library build<br/>[build_library.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
end

subgraph group_review["Shared review"]
  node_reviewserver["Review API<br/>[app.py]"]
  node_reviewpage["Editor review page<br/>[review.html]"]
end

node_user(("Listener"))
node_microphone(("Microphone / file"))
node_onnx["ONNX model asset<br/>[sanctuary.onnx]"]
node_modelassets["Model library assets<br/>[library.json]"]
node_birdnet["BirdNET teacher"]
node_xc["Audio data sources"]

node_user -->|"uses"| node_app
node_app -->|"loads"| node_library
node_app -->|"loads model"| node_modelclient
node_app -->|"routes to"| node_identify
node_app -->|"routes to"| node_document
node_app -->|"routes to"| node_libraryview
node_app -->|"routes to"| node_settings
node_microphone -->|"provides audio"| node_audio
node_audio -->|"supplies windows"| node_identify
node_identify -->|"requests inference"| node_modelclient
node_identify -->|"analyses results"| node_decision
node_decision -->|"matches against"| node_library
node_identify -->|"saves detections"| node_localdb
node_identify -->|"renders spectrogram"| node_display
node_identify -->|"renders scores"| node_soundscape
node_modelclient -->|"dispatches jobs"| node_worker
node_modelclient -->|"loads model"| node_onnx
node_library -->|"loads references"| node_modelassets
node_library -->|"reads user species"| node_localdb
node_document -->|"captures clips"| node_audio
node_document -->|"embeds calls"| node_modelclient
node_document -->|"stores exemplars"| node_localdb
node_document -->|"renders previews"| node_display
node_document -->|"submits species"| node_sync
node_libraryview -->|"reads records"| node_localdb
node_settings -->|"starts sync"| node_sync
node_sync -.->|"HTTP exchange"| node_reviewserver
node_reviewpage -->|"editorial review"| node_reviewserver
node_xc -->|"provides recordings"| node_fetch
node_fetch -->|"supplies datasets"| node_data
node_data -->|"prepares examples"| node_training
node_birdnet -->|"teacher targets"| node_training
node_training -->|"trains network"| node_student
node_student -->|"quantizes"| node_export
node_student -->|"embeds references"| node_buildlib
node_buildlib -->|"evaluated with"| node_evaluation
node_export -->|"writes model"| node_onnx
node_buildlib -->|"writes library"| node_modelassets

click node_app "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/App.tsx"
click node_audio "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/audio.ts"
click node_identify "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/IdentifyView.tsx"
click node_decision "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/identify.ts"
click node_library "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/library.ts"
click node_modelclient "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/model.ts"
click node_worker "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/model.worker.ts"
click node_display "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/Spectrogram.tsx"
click node_soundscape "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/SoundscapeBars.tsx"
click node_document "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/DocumentView.tsx"
click node_localdb "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/db.ts"
click node_libraryview "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/LibraryView.tsx"
click node_settings "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/SettingsView.tsx"
click node_sync "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/sync.ts"
click node_data "https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/prepare.py"
click node_fetch "https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/fetch_data.py"
click node_student "https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/model.py"
click node_training "https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/train_student.py"
click node_export "https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/export.py"
click node_buildlib "https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/build_library.py"
click node_evaluation "https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/evaluate.py"
click node_reviewserver "https://github.com/nhattruong0205/soundsanctuary/blob/main/server/app.py"
click node_reviewpage "https://github.com/nhattruong0205/soundsanctuary/blob/main/server/review.html"
click node_onnx "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/public/models/sanctuary.onnx"
click node_modelassets "https://github.com/nhattruong0205/soundsanctuary/blob/main/app/public/models/library.json"

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_app,node_audio,node_identify,node_decision,node_library,node_modelclient,node_worker,node_display,node_soundscape,node_document,node_localdb,node_libraryview,node_settings,node_sync toneBlue
class node_data,node_fetch,node_student,node_training,node_export,node_buildlib,node_evaluation toneAmber
class node_reviewserver,node_reviewpage toneMint
class node_user,node_microphone,node_onnx,node_modelassets,node_birdnet,node_xc toneIndigo
```

## Components

### Offline web app

- [App shell](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/App.tsx): `app/src/App.tsx`
- [Audio capture](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/audio.ts): `app/src/lib/audio.ts`
- [Identify mode](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/IdentifyView.tsx): `app/src/components/IdentifyView.tsx`
- [Matching & priors](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/identify.ts): `app/src/lib/identify.ts`
- [Species library](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/library.ts): `app/src/lib/library.ts`
- [Inference client](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/model.ts): `app/src/lib/model.ts`
- [Model worker](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/model.worker.ts): `app/src/lib/model.worker.ts`
- [Audio visualizations](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/Spectrogram.tsx): `app/src/components/Spectrogram.tsx`
- [Soundscape bars](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/SoundscapeBars.tsx): `app/src/components/SoundscapeBars.tsx`
- [Document mode](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/DocumentView.tsx): `app/src/components/DocumentView.tsx`
- [Offline records](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/db.ts): `app/src/lib/db.ts`
- [Library browser](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/LibraryView.tsx): `app/src/components/LibraryView.tsx`
- [Settings & sync](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/components/SettingsView.tsx): `app/src/components/SettingsView.tsx`
- [Review sync client](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/src/lib/sync.ts): `app/src/lib/sync.ts`

### Model pipeline

- [Training data prep](https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/prepare.py): `ml/prepare.py`
- [Data acquisition](https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/fetch_data.py): `ml/fetch_data.py`
- [Student network](https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/model.py): `ml/model.py`
- [Student training](https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/train_student.py): `ml/train_student.py`
- [Quantized export](https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/export.py): `ml/export.py`
- [Reference library build](https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/build_library.py): `ml/build_library.py`
- [Model evaluation](https://github.com/nhattruong0205/soundsanctuary/blob/main/ml/evaluate.py): `ml/evaluate.py`

### Shared review

- [Review API](https://github.com/nhattruong0205/soundsanctuary/blob/main/server/app.py): `server/app.py`
- [Editor review page](https://github.com/nhattruong0205/soundsanctuary/blob/main/server/review.html): `server/review.html`

### Other components

- **Listener**
- **Microphone / file**
- [ONNX model asset](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/public/models/sanctuary.onnx): `app/public/models/sanctuary.onnx`
- [Model library assets](https://github.com/nhattruong0205/soundsanctuary/blob/main/app/public/models/library.json): `app/public/models/library.json`
- **BirdNET teacher**
- **Audio data sources**

## Connections

- Listener → App shell: uses (evidence: `README.md`)
- App shell → Species library: loads (evidence: `app/src/App.tsx`)
- App shell → Inference client: loads model (evidence: `app/src/App.tsx`)
- App shell → Identify mode: routes to (evidence: `app/src/App.tsx`)
- App shell → Document mode: routes to (evidence: `app/src/App.tsx`)
- App shell → Library browser: routes to (evidence: `app/src/App.tsx`)
- App shell → Settings & sync: routes to (evidence: `app/src/App.tsx`)
- Microphone / file → Audio capture: provides audio (evidence: `app/src/lib/audio.ts`)
- Audio capture → Identify mode: supplies windows (evidence: `app/src/components/IdentifyView.tsx`)
- Identify mode → Inference client: requests inference (evidence: `app/src/components/IdentifyView.tsx`)
- Identify mode → Matching & priors: analyses results (evidence: `app/src/components/IdentifyView.tsx`)
- Matching & priors → Species library: matches against (evidence: `app/src/lib/identify.ts`)
- Identify mode → Offline records: saves detections (evidence: `app/src/components/IdentifyView.tsx`)
- Identify mode → Audio visualizations: renders spectrogram (evidence: `app/src/components/IdentifyView.tsx`)
- Identify mode → Soundscape bars: renders scores (evidence: `app/src/components/IdentifyView.tsx`)
- Inference client → Model worker: dispatches jobs (evidence: `app/src/lib/model.ts`)
- Inference client → ONNX model asset: loads model (evidence: `README.md`)
- Species library → Model library assets: loads references (evidence: `app/src/lib/library.ts`)
- Species library → Offline records: reads user species (evidence: `app/src/lib/library.ts`)
- Document mode → Audio capture: captures clips (evidence: `app/src/components/DocumentView.tsx`)
- Document mode → Inference client: embeds calls (evidence: `README.md`)
- Document mode → Offline records: stores exemplars (evidence: `app/src/components/DocumentView.tsx`)
- Document mode → Audio visualizations: renders previews (evidence: `app/src/components/DocumentView.tsx`)
- Document mode → Review sync client: submits species (evidence: `app/src/components/DocumentView.tsx`)
- Library browser → Offline records: reads records (evidence: `app/src/components/LibraryView.tsx`)
- Settings & sync → Review sync client: starts sync (evidence: `app/src/components/SettingsView.tsx`)
- Review sync client → Review API: HTTP exchange (evidence: `README.md`)
- Editor review page → Review API: editorial review (evidence: `README.md`)
- Audio data sources → Data acquisition: provides recordings (evidence: `README.md`)
- Data acquisition → Training data prep: supplies datasets (evidence: `README.md`)
- Training data prep → Student training: prepares examples (evidence: `README.md`)
- BirdNET teacher → Student training: teacher targets (evidence: `README.md`)
- Student training → Student network: trains network (evidence: `README.md`)
- Student network → Quantized export: quantizes (evidence: `README.md`)
- Student network → Reference library build: embeds references (evidence: `README.md`)
- Reference library build → Model evaluation: evaluated with (evidence: `README.md`)
- Quantized export → ONNX model asset: writes model (evidence: `README.md`)
- Reference library build → Model library assets: writes library (evidence: `README.md`)
