# nfarina/whisper-dictate architecture

> Architecture diagram of the GitHub repository nfarina/whisper-dictate, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nfarina/whisper-dictate
- Repository: https://github.com/nfarina/whisper-dictate

## Overview

##### Project type and purpose
- WhisperDictate is a native macOS menu bar application built with SwiftUI.
- It captures audio via a global hotkey, sends it to OpenAI’s Whisper API for transcription, and injects the resulting text into any active application using macOS accessibility services.

##### File structure
- Top-level Xcode project: WhisperDictate.xcodeproj (build configs, schemes).
- Swift source files under WhisperDictate/:
– WhisperDictateApp.swift (app entry point)
– ContentView.swift, MenuBarView.swift (UI layer)
– AudioManager.swift (audio capture and buffer management)
– HotkeyManager.swift (global hotkey registration & handling)
– RecordingCoordinator.swift (state machine for recording sessions)
– TranscriptionManager.swift (HTTP client to OpenAI Whisper API)
– Logger.swift (centralized logging)
- WhisperDictate.entitlements (accessibility, keystroke permissions)

##### README for additional insights
- Describes a simple event-driven architecture: hotkey → record audio → call Whisper API → type text.
- Lists external dependencies: OpenAI Whisper API; macOS Keychain for secure storage; SwiftUI for UI.
- Mentions privacy/security requirements (no local audio storage, secure API key).

##### Main components
a. UI Layer
– Displays recording state and settings (API key entry).
b. Hotkey & Input Handling
– HotkeyManager: listens for ⌘+Ctrl+R, triggers recording.
c. Audio Capture & Coordination
– AudioManager: interfaces with AVFoundation, streams audio buffers.
– RecordingCoordinator: manages recording lifecycle (start/stop, state transitions).
d. Transcription Service
– TranscriptionManager: sends audio buffers over HTTPS to OpenAI Whisper API; receives text.
e. Text Injection
– Uses macOS accessibility APIs to “type” the transcribed text into the active application.
f. Security & Persistence
– Keychain Integration: secure storage/retrieval of OpenAI API key.
g. Logging
– Logger: centralized logging of events, errors, API responses.

##### Interactions & Data Flows
2. RecordingCoordinator invokes AudioManager to capture audio.
3. AudioManager streams audio data to RecordingCoordinator.
4. On stop, RecordingCoordinator forwards audio to TranscriptionManager.
5. TranscriptionManager retrieves API key from Keychain → HTTPS POST to Whisper API → receives transcript.
6. TranscriptionManager passes text back to RecordingCoordinator → triggers TextInjection via accessibility APIs.
7. Logger records each step (start/stop, API call, errors).

##### Architectural patterns & design principles
- Event-driven, MVC/MVVM-style separation:
– View (SwiftUI views) ←→ Controller/Coordinator (RecordingCoordinator) ←→ Model/Service (AudioManager, TranscriptionManager).
- Single process, modular manager classes.
- Dependency inversion: managers expose protocols/interfaces (e.g., audio, transcription).
- Secure by design: Keychain for secrets, no local audio caching.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Subgraphs and modules
    subgraph "UI Layer"
        UIApp["WhisperDictateApp"]:::internal
        ContentView["ContentView"]:::ui
        MenuBarView["MenuBarView"]:::ui
    end

    subgraph "Core Logic"
        HotkeyManager["HotkeyManager"]:::internal
        RecordingCoordinator["RecordingCoordinator"]:::internal
        AudioManager["AudioManager"]:::internal
        TranscriptionManager["TranscriptionManager"]:::internal
        Logger["Logger"]:::internal
    end

    subgraph "OS Services"
        KeychainService[(Keychain Service)]:::os
        AccessibilityAPI["Accessibility API"]:::os
    end

    subgraph "External Services"
        OpenAIWhisper((OpenAI Whisper API)):::external
    end

    %% Connections
    UIApp -->|initializes| ContentView
    UIApp -->|initializes| MenuBarView
    UIApp -->|sets up| HotkeyManager

    MenuBarView -->|click or hotkey| HotkeyManager
    HotkeyManager -->|"startRecording()"| RecordingCoordinator
    RecordingCoordinator -->|"startCapture()"| AudioManager
    AudioManager -->|"audioBuffer"| RecordingCoordinator
    RecordingCoordinator -->|"stopRecording()"| TranscriptionManager
    TranscriptionManager -->|"getAPIKey()"| KeychainService
    TranscriptionManager -->|"POST /transcribe"| OpenAIWhisper
    OpenAIWhisper -->|"transcript"| TranscriptionManager
    TranscriptionManager -->|"transcribedText"| RecordingCoordinator
    RecordingCoordinator -->|"injectText()"| AccessibilityAPI

    %% Logging arrows
    HotkeyManager -->|"log event"| Logger
    RecordingCoordinator -->|"log event"| Logger
    AudioManager -->|"log event"| Logger
    TranscriptionManager -->|"log event"| Logger

    %% Click Events
    click ContentView "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/ContentView.swift"
    click MenuBarView "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/MenuBarView.swift"
    click UIApp "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/WhisperDictateApp.swift"
    click HotkeyManager "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/HotkeyManager.swift"
    click AudioManager "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/AudioManager.swift"
    click RecordingCoordinator "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/RecordingCoordinator.swift"
    click TranscriptionManager "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/TranscriptionManager.swift"
    click Logger "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/Logger.swift"
    click Assets "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/Assets.xcassets"
    click Info "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/Info.plist"
    click Entitlements "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate/WhisperDictate.entitlements"
    click XcodeProj "https://github.com/nfarina/whisper-dictate/blob/main/WhisperDictate.xcodeproj"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,color:#000;
    classDef internal fill:#90EE90,stroke:#333,color:#000;
    classDef os fill:#FFFF99,stroke:#333,color:#000;
    classDef external fill:#F08080,stroke:#333,color:#000;
```
