# ginijhnc/speedy-stt architecture

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

- Interactive diagram: https://gitdiagram.com/ginijhnc/speedy-stt
- Repository: https://github.com/ginijhnc/speedy-stt

## Overview

##### What this project is (type + purpose)

**Speedy-STT** is a **Windows-only, native Rust desktop utility** (not a web service). It’s a **systray/background dictation app** that:

- Listens for a **global hotkey** (hold to record)
- Captures **microphone audio**
- Optionally performs **volume boost** and **audio ducking** (reduce other system audio during recording)
- Runs **Whisper transcription locally** via **whisper.cpp** (CPU-optimized)
- On completion, **auto-pastes** the transcribed text into the active window
- Has **lazy model loading** (load on demand, unload after idle cooldown)

##### How the file structure maps to architecture (what to extract into components)

Everything is in `src/` and is strongly suggestive of “one process / many modules”:

- `src/main.rs` — process entrypoint; wires modules together.
- `src/app.rs` — likely top-level orchestrator/state machine (recording/transcribing lifecycle).
- `src/hotkey.rs` — global hotkey registration + key events.
- `src/input.rs` — audio capture (mic stream) / device handling.
- `src/audio.rs` — audio processing utilities (buffering, format conversions, etc.).
- `src/volume.rs` — volume boost and/or system volume interactions.
- `src/feedback.rs` — “start/finish” sounds (assets).
- `src/whisper.rs` — whisper.cpp binding/runner; lazy load/unload model, run transcription.
- `src/config.rs` — reads `.env` configuration (hotkey, model path, cooldown, etc.).
- `src/volume.rs` + `src/audio.rs` + `src/input.rs` together form the “audio pipeline”.
- `assets/models/` — model files downloaded by `assets/scripts/download-model.ps1`.
- `assets/sounds/` — start/finish mp3s used by feedback.
- `build.ps1` — build pipeline; implies native dependencies (LLVM/Clang, VS C++).

- **Hold hotkey → record → release → transcribe → auto-paste**
- **Audio ducking:** fade background audio to silence during recording, restore after
- **Lazy model loading:** load whisper model on demand, then free after configurable idle cooldown

##### Context / Container view (C4 Level 1–2)
Shows: user, Windows OS services, the Speedy-STT process, local filesystem (model/assets), and whisper.cpp.

##### Runtime sequence / activity flow (the dictation pipeline)
Shows the hotkey press lifecycle, ducking, audio capture, transcription, paste, and feedback sounds.

##### Component view (module-level) mapping directly to `src/*.rs`
Shows internal module boundaries, who calls whom, and what each module owns.

This repo is small enough that a “component view” can be very faithful without becoming noise.

**External / Environment**
- **User**
- **Windows OS**
- Global hotkey API
- Audio capture APIs
- System audio session / ducking controls
- Clipboard / SendInput / active window automation (for auto-paste)
- System tray APIs
- **Filesystem**
- `.env` config
- `assets/models/<model>.bin` (or similar)
- `assets/sounds/start.mp3`, `finish.mp3`

**In-process: Speedy-STT (single executable)**
- **App Orchestrator** (`app.rs`)
- **Config** (`config.rs`)
- **Tray Controller** (`tray.rs`)
- **Hotkey Listener** (`hotkey.rs`)
- **Audio Input/Capture** (`input.rs`)
- **Audio Processing** (`audio.rs`)
- **Volume Boost / Ducking** (`volume.rs`)
- **Audio Feedback** (`feedback.rs`)
- **Transcription Engine Wrapper** (`whisper.rs` → whisper.cpp)

**Embedded / Native dependency**
- **whisper.cpp** (C/C++ library invoked from Rust; model loaded from disk)

##### Data flow (audio buffers and text)

- `User` → `Windows Hotkey API` → `hotkey.rs` → `app.rs`
- `app.rs` → `volume.rs` (start ducking / restore ducking)
- `app.rs` → `feedback.rs` (play start/finish sound)
- `app.rs` → `input.rs` (start/stop capture)
- `input.rs` → `audio.rs` (PCM frames/buffers)
- `audio.rs` → `whisper.rs` (final audio buffer / WAV-like input)
- `whisper.rs` ↔ `Filesystem(models)` (load/unload model files)
- `whisper.rs` → `whisper.cpp` (FFI call)
- `whisper.rs` → `app.rs` (transcribed text)
- `app.rs` → `Windows Automation (clipboard/keystrokes)` (auto-paste into active window)
- `tray.rs` ↔ `app.rs` (status, enable/disable, exit)
- `config.rs` → everyone (hotkey config, cooldown timers, model selection, volume boost)

A **timer/cooldown loop**:
- `app.rs` → `whisper.rs` (unload model after idle cooldown)

##### app → feedback: play finish.mp3

- `main.rs` (composition root)
- `app.rs` (state machine/orchestrator)
- `config.rs` (configuration provider)
- `tray.rs` (tray UI boundary)
- `hotkey.rs` (hotkey boundary)
- `input.rs` (mic boundary)
- `audio.rs` (DSP/format boundary)
- `volume.rs` (ducking/boost boundary)
- `feedback.rs` (sound boundary)
- `whisper.rs` (inference boundary)

##### Diagramming conventions to make it “principal-grade”

Of the following:

- **Clear labels**: use runtime nouns (“Audio Capture”, “Model Loader”, “Hotkey Listener”) and annotate with file names (`input.rs`, `whisper.rs`) in smaller text.
- Blue: in-process Rust modules
- Gray: Windows OS APIs
- Green: local filesystem assets/config
- Orange: native dependency (whisper.cpp)
- **Threading / async note**: add small callouts like “background thread for capture” and “transcription worker thread” if that’s how it’s implemented (verify in code, but it’s typical).
- **Resource lifecycle annotations**:
- “Lazy load model on first transcription”
- “Unload after idle cooldown (configurable)”
- “Ducking active only during Recording”

##### Don’t overthink it: maximize components, minimize ambiguity

- Mirrors the `src/*.rs` modules as components
- Treats Windows integrations as first-class dependencies
- Captures the dictation lifecycle + model lifecycle explicitly

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================
  %% Diagram 1: Context / Container
  %% =========================
  subgraph D1["Diagram 1 — System Context / Container"]
    direction TB

    U["User"]:::external

    subgraph WIN["Windows OS Services"]
      direction TB
      OSHotkey["Global Hotkey API"]:::os
      OSTray["System Tray APIs"]:::os
      OSAudioCap["Audio Capture APIs"]:::os
      OSAudioCtl["Audio Session Control (Ducking)"]:::os
      OSAutomation["Clipboard / SendInput (Auto-paste)"]:::os
      OSTimer["Timers / Scheduling"]:::os
    end

    subgraph FS["Local Filesystem"]
      direction TB
      Env[".env / .env.example"]:::fs
      Models[("assets/models/* (Whisper models)")]:::fs
      Sounds[("assets/sounds/* (start/finish mp3)")]:::fs
      PlanDucking["assets/plans/AUDIO_DUCKING_PLAN.md"]:::fs
      PlanLazy["assets/plans/LAZY_LOADING_PLAN.md"]:::fs
      Scripts["assets/scripts/* (download model)"]:::fs
      Build["build.ps1 (build pipeline)"]:::fs
    end

    subgraph PROC["Speedy-STT.exe (Rust, single process)"]
      direction TB
      AppExe["Speedy-STT.exe"]:::app
    end

    WhisperCpp["whisper.cpp (native library)"]:::native

    %% Context connections
    U -->|"hold/release_hotkey"| OSHotkey
    OSHotkey -->|"hotkey_event"| AppExe

    AppExe -->|"tray_status/menu"| OSTray
    AppExe -->|"start/stop_capture"| OSAudioCap
    AppExe -->|"duck/restore"| OSAudioCtl
    AppExe -->|"paste_text"| OSAutomation
    AppExe -->|"cooldown_scheduling"| OSTimer

    AppExe -->|"read_config"| Env
    AppExe -->|"load_model_files"| Models
    AppExe -->|"play_sounds"| Sounds
    AppExe -->|"reference_plans"| PlanDucking
    AppExe -->|"reference_plans"| PlanLazy
    Scripts -->|"download_models"| Models
    Build -->|"build_steps"| AppExe

    AppExe -->|"FFI_calls"| WhisperCpp
    WhisperCpp -->|"reads_model_from_disk"| Models
    WhisperCpp -->|"returns_transcribed_text"| AppExe
  end

  %% =========================
  %% Diagram 2: Runtime Sequence (Hold-to-record) - represented as a vertical flow
  %% =========================
  subgraph D2["Diagram 2 — Runtime Sequence (Hold-to-record)"]
    direction TB

    S0["User presses hotkey (hold)"]:::external
    S1["hotkey.rs: HotkeyDown event → app.rs"]:::rust
    S2["app.rs → volume.rs: Enable ducking (Recording)"]:::rust
    S3["app.rs → feedback.rs: Play start.mp3"]:::rust
    S4["app.rs → input.rs: Start microphone capture"]:::rust
    S4n["Note: Background capture thread\nPCM frames buffered/converted"]:::os
    S5["User releases hotkey"]:::external
    S6["hotkey.rs: HotkeyUp event → app.rs"]:::rust
    S7["app.rs → input.rs: Stop capture"]:::rust
    S8["input.rs → audio.rs: Deliver captured PCM buffers"]:::rust
    S9["audio.rs → whisper.rs: Provide final audio buffer (WAV-like)"]:::rust
    S10["app.rs → whisper.rs: Ensure model loaded + Transcribe()"]:::rust
    S10n["Note: Lazy load on first use\nUnload after idle cooldown (configurable)"]:::os
    S11["whisper.rs → app.rs: Transcribed text"]:::rust
    S12["app.rs → Windows Automation: Paste text into active window"]:::os
    S13["app.rs → volume.rs: Restore system audio"]:::rust
    S14["app.rs → feedback.rs: Play finish.mp3"]:::rust

    S0 --> S1 --> S2 --> S3 --> S4 --> S4n --> S5 --> S6 --> S7 --> S8 --> S9 --> S10 --> S10n --> S11 --> S12 --> S13 --> S14
  end

  %% =========================
  %% Diagram 3: Component / Module view (src/*.rs)
  %% =========================
  subgraph D3["Diagram 3 — Component (Module) View — Speedy-STT.exe"]
    direction TB

    Main["main.rs\nComposition root"]:::rust
    App["app.rs\nOrchestrator + State Machine\nIdle → Recording → Transcribing → Pasting"]:::rust

    Cfg["config.rs\nConfiguration Provider (.env)"]:::rust
    Tray["tray.rs\nTray Controller"]:::rust
    HotkeyMod["hotkey.rs\nGlobal Hotkey Listener"]:::rust

    Input["input.rs\nAudio Input / Mic Capture"]:::rust
    Audio["audio.rs\nAudio Processing (buffer/format)"]:::rust
    Volume["volume.rs\nVolume Boost + Ducking"]:::rust
    Feedback["feedback.rs\nAudio Feedback (start/finish)"]:::rust
    Whisper["whisper.rs\nTranscription Wrapper (lazy load/unload)"]:::rust

    OSHotkey2["Windows Hotkey API"]:::os
    OSTray2["Windows Tray APIs"]:::os
    OSAudioCap2["Windows Audio Capture APIs"]:::os
    OSAudioCtl2["Windows Audio Session Control"]:::os
    OSAutomation2["Windows Clipboard / SendInput"]:::os
    FSModels2[("assets/models/*")]:::fs
    FSSounds2[("assets/sounds/*")]:::fs
    FSEnv2[".env / .env.example"]:::fs
    WhisperCpp2["whisper.cpp"]:::native
    OSTimer2["Timers / Cooldown"]:::os

    %% Wiring
    Main -->|"constructs/wires"| Cfg
    Main -->|"constructs/wires"| Tray
    Main -->|"constructs/wires"| HotkeyMod
    Main -->|"constructs/wires"| App
    Main -->|"constructs/wires"| Input
    Main -->|"constructs/wires"| Audio
    Main -->|"constructs/wires"| Volume
    Main -->|"constructs/wires"| Feedback
    Main -->|"constructs/wires"| Whisper

    %% Config fan-out
    Cfg -->|"hotkey_model_cooldown_settings"| App
    Cfg -->|"hotkey_binding"| HotkeyMod
    Cfg -->|"audio_device_settings"| Input
    Cfg -->|"boost/ducking_settings"| Volume
    Cfg -->|"model_path"| Whisper

    %% External API boundaries
    HotkeyMod -->|"register/listen"| OSHotkey2
    Tray -->|"tray_icon/menu"| OSTray2
    Input -->|"capture_stream"| OSAudioCap2
    Volume -->|"duck/restore_sessions"| OSAudioCtl2
    App -->|"auto_paste"| OSAutomation2

    %% Runtime control flow
    HotkeyMod -.->|"HotkeyDown/Up events"| App
    Tray -.->|"enable/disable/exit events"| App
    App -->|"start/stop_capture"| Input
    Input -->|"PCM_frames"| Audio
    Audio -->|"final_audio_buffer"| Whisper
    App -->|"play_start/finish"| Feedback
    App -->|"duck/restore"| Volume

    %% Model + assets
    Whisper -->|"load/unload_model_files"| FSModels2
    Feedback -->|"read_sounds"| FSSounds2
    Cfg -->|"read_env"| FSEnv2

    %% Native dependency
    Whisper -->|"FFI_calls"| WhisperCpp2
    WhisperCpp2 -->|"reads_models"| FSModels2
    Whisper -->|"transcribed_text"| App

    %% Cooldown lifecycle
    App -->|"schedule_unload_after_idle"| OSTimer2
    OSTimer2 -.->|"cooldown_elapsed"| Whisper
  end

  %% =========================
  %% Click events (from component_mapping)
  %% =========================
  click Main "https://github.com/ginijhnc/speedy-stt/blob/main/src/main.rs"
  click App "https://github.com/ginijhnc/speedy-stt/blob/main/src/app.rs"
  click Cfg "https://github.com/ginijhnc/speedy-stt/blob/main/src/config.rs"
  click Tray "https://github.com/ginijhnc/speedy-stt/blob/main/src/tray.rs"
  click HotkeyMod "https://github.com/ginijhnc/speedy-stt/blob/main/src/hotkey.rs"
  click Input "https://github.com/ginijhnc/speedy-stt/blob/main/src/input.rs"
  click Audio "https://github.com/ginijhnc/speedy-stt/blob/main/src/audio.rs"
  click Volume "https://github.com/ginijhnc/speedy-stt/blob/main/src/volume.rs"
  click Feedback "https://github.com/ginijhnc/speedy-stt/blob/main/src/feedback.rs"
  click Whisper "https://github.com/ginijhnc/speedy-stt/blob/main/src/whisper.rs"
  click Models "https://github.com/ginijhnc/speedy-stt/tree/main/assets/models/"
  click FSModels2 "https://github.com/ginijhnc/speedy-stt/tree/main/assets/models/"
  click Scripts "https://github.com/ginijhnc/speedy-stt/blob/main/assets/scripts/download-model.ps1"
  click Sounds "https://github.com/ginijhnc/speedy-stt/blob/main/assets/sounds/start.mp3"
  click FSSounds2 "https://github.com/ginijhnc/speedy-stt/blob/main/assets/sounds/finish.mp3"
  click Env "https://github.com/ginijhnc/speedy-stt/blob/main/.env.example"
  click Build "https://github.com/ginijhnc/speedy-stt/blob/main/build.ps1"
  click PlanDucking "https://github.com/ginijhnc/speedy-stt/blob/main/assets/plans/AUDIO_DUCKING_PLAN.md"
  click PlanLazy "https://github.com/ginijhnc/speedy-stt/blob/main/assets/plans/LAZY_LOADING_PLAN.md"

  %% =========================
  %% Styles
  %% =========================
  classDef rust fill:#2563EB,stroke:#0B3AA4,color:#FFFFFF,stroke-width:1px
  classDef app fill:#1D4ED8,stroke:#0B3AA4,color:#FFFFFF,stroke-width:2px
  classDef os fill:#6B7280,stroke:#374151,color:#FFFFFF,stroke-width:1px
  classDef fs fill:#16A34A,stroke:#166534,color:#FFFFFF,stroke-width:1px
  classDef native fill:#F59E0B,stroke:#B45309,color:#111827,stroke-width:2px
  classDef external fill:#0EA5E9,stroke:#075985,color:#FFFFFF,stroke-width:1px
```
