# kuberwastaken/megaphone architecture

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

- Interactive diagram: https://gitdiagram.com/kuberwastaken/megaphone
- Repository: https://github.com/kuberwastaken/megaphone

## Overview

Megaphone is a native, on-device macOS dictation app. The principal workflow is a user-triggered hold/toggle shortcut, live audio capture and streaming transcription, transcript cleanup, then insertion into the active app; dictionary learning, inline commands with app context, and run history extend that flow. The graph also preserves settings/setup, diagnostics, and updating. Relationship evidence is limited to the README and the supplied source excerpts/index; undocumented wiring is omitted.

Main entry points: [`Sources/App.swift`](https://github.com/kuberwastaken/megaphone/blob/main/Sources/App.swift) (App lifecycle), [`Sources/SpeechAnalyzerService.swift`](https://github.com/kuberwastaken/megaphone/blob/main/Sources/SpeechAnalyzerService.swift) (SpeechAnalyzer), [`Sources/HotkeyManager.swift`](https://github.com/kuberwastaken/megaphone/blob/main/Sources/HotkeyManager.swift) (Shortcut backend), [`Sources/SettingsView.swift`](https://github.com/kuberwastaken/megaphone/blob/main/Sources/SettingsView.swift) (Settings and setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and interaction"]
  node_app["App lifecycle<br/>[App.swift]"]
  node_settings["Settings and setup<br/>[SettingsView.swift]"]
  node_setup["First-run setup<br/>[SetupView.swift]"]
  node_context["Active-app context"]
end

subgraph group_capture["Shortcut and capture"]
  node_shortcut["Shortcut backend"]
  node_matcher["Shortcut matching"]
  node_session["Dictation session"]
  node_audio["Audio recording"]
end

subgraph group_language["Transcription and language"]
  node_speech["SpeechAnalyzer"]
  node_cleanup["Smart cleanup"]
  node_tidy["Basic cleanup"]
  node_dictionary[("Personal dictionary")]
  node_wake["Wake phrase"]
  node_transforms[("Voice macros")]
end

subgraph group_support["History and support"]
  node_history[("Run history")]
  node_historyitem["History records"]
  node_debug["Pipeline diagnostics"]
  node_export["Test-case export"]
  node_updater["Update manager"]
end

node_user(("Mac user"))
node_activeapp["Active application"]
node_release["Release service"]

node_user -->|"triggers"| node_shortcut
node_shortcut -->|"reduces input"| node_matcher
node_shortcut -.->|"dispatches events"| node_session
node_user -->|"speaks"| node_audio
node_audio -->|"streams audio"| node_speech
node_speech -->|"provides transcript"| node_cleanup
node_speech -->|"fallback cleanup"| node_tidy
node_cleanup -->|"uses context"| node_activeapp
node_context -.->|"reads context"| node_activeapp
node_speech -.->|"uses vocabulary"| node_dictionary
node_speech -.->|"checks trigger"| node_wake
node_speech -.->|"applies macros"| node_transforms
node_app -->|"configures"| node_shortcut
node_app -->|"starts recording"| node_audio
node_app -->|"coordinates transcription"| node_speech
node_app -->|"requests cleanup"| node_cleanup
node_app -.->|"captures context"| node_context
node_app -->|"stores run history"| node_history
node_history -->|"persists records"| node_historyitem
node_settings -->|"configures"| node_dictionary
node_settings -->|"checks updates"| node_updater
node_setup -->|"configures"| node_app
node_debug -->|"exports cases"| node_export
node_debug -->|"displays pipeline"| node_historyitem
node_updater -->|"checks releases"| node_release
node_app -->|"shows interface"| node_settings

click node_app "https://github.com/kuberwastaken/megaphone/blob/main/Sources/App.swift"
click node_settings "https://github.com/kuberwastaken/megaphone/blob/main/Sources/SettingsView.swift"
click node_setup "https://github.com/kuberwastaken/megaphone/blob/main/Sources/SetupView.swift"
click node_context "https://github.com/kuberwastaken/megaphone/blob/main/Sources/AppContextService.swift"
click node_shortcut "https://github.com/kuberwastaken/megaphone/blob/main/Sources/HotkeyManager.swift"
click node_matcher "https://github.com/kuberwastaken/megaphone/blob/main/Sources/ShortcutCore/ShortcutMatcher.swift"
click node_session "https://github.com/kuberwastaken/megaphone/blob/main/Sources/ShortcutCore/DictationShortcutSessionController.swift"
click node_audio "https://github.com/kuberwastaken/megaphone/blob/main/Sources/AudioRecorder.swift"
click node_speech "https://github.com/kuberwastaken/megaphone/blob/main/Sources/SpeechAnalyzerService.swift"
click node_cleanup "https://github.com/kuberwastaken/megaphone/blob/main/Sources/AppleFoundationModelsPostProcessor.swift"
click node_tidy "https://github.com/kuberwastaken/megaphone/blob/main/Sources/TranscriptTidier.swift"
click node_dictionary "https://github.com/kuberwastaken/megaphone/blob/main/Sources/DictionaryStore.swift"
click node_wake "https://github.com/kuberwastaken/megaphone/blob/main/Sources/WakePhraseMatcher.swift"
click node_transforms "https://github.com/kuberwastaken/megaphone/blob/main/Sources/TransformStore.swift"
click node_history "https://github.com/kuberwastaken/megaphone/blob/main/Sources/PipelineHistoryStore.swift"
click node_historyitem "https://github.com/kuberwastaken/megaphone/blob/main/Sources/PipelineHistoryItem.swift"
click node_debug "https://github.com/kuberwastaken/megaphone/blob/main/Sources/PipelineDebugPanelView.swift"
click node_export "https://github.com/kuberwastaken/megaphone/blob/main/Sources/TestCaseExporter.swift"
click node_updater "https://github.com/kuberwastaken/megaphone/blob/main/Sources/UpdateManager.swift"

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_settings,node_setup,node_context,node_user toneBlue
class node_shortcut,node_matcher,node_session,node_audio toneAmber
class node_speech,node_cleanup,node_tidy,node_dictionary,node_wake,node_transforms toneMint
class node_history,node_historyitem,node_debug,node_export,node_updater toneRose
class node_activeapp,node_release toneIndigo
```

## Components

### App and interaction

- [App lifecycle](https://github.com/kuberwastaken/megaphone/blob/main/Sources/App.swift): `Sources/App.swift`
- [Settings and setup](https://github.com/kuberwastaken/megaphone/blob/main/Sources/SettingsView.swift): `Sources/SettingsView.swift`
- [First-run setup](https://github.com/kuberwastaken/megaphone/blob/main/Sources/SetupView.swift): `Sources/SetupView.swift`
- [Active-app context](https://github.com/kuberwastaken/megaphone/blob/main/Sources/AppContextService.swift): `Sources/AppContextService.swift`

### Shortcut and capture

- [Shortcut backend](https://github.com/kuberwastaken/megaphone/blob/main/Sources/HotkeyManager.swift): `Sources/HotkeyManager.swift`
- [Shortcut matching](https://github.com/kuberwastaken/megaphone/blob/main/Sources/ShortcutCore/ShortcutMatcher.swift): `Sources/ShortcutCore/ShortcutMatcher.swift`
- [Dictation session](https://github.com/kuberwastaken/megaphone/blob/main/Sources/ShortcutCore/DictationShortcutSessionController.swift): `Sources/ShortcutCore/DictationShortcutSessionController.swift`
- [Audio recording](https://github.com/kuberwastaken/megaphone/blob/main/Sources/AudioRecorder.swift): `Sources/AudioRecorder.swift`

### Transcription and language

- [SpeechAnalyzer](https://github.com/kuberwastaken/megaphone/blob/main/Sources/SpeechAnalyzerService.swift): `Sources/SpeechAnalyzerService.swift`
- [Smart cleanup](https://github.com/kuberwastaken/megaphone/blob/main/Sources/AppleFoundationModelsPostProcessor.swift): `Sources/AppleFoundationModelsPostProcessor.swift`
- [Basic cleanup](https://github.com/kuberwastaken/megaphone/blob/main/Sources/TranscriptTidier.swift): `Sources/TranscriptTidier.swift`
- [Personal dictionary](https://github.com/kuberwastaken/megaphone/blob/main/Sources/DictionaryStore.swift): `Sources/DictionaryStore.swift`
- [Wake phrase](https://github.com/kuberwastaken/megaphone/blob/main/Sources/WakePhraseMatcher.swift): `Sources/WakePhraseMatcher.swift`
- [Voice macros](https://github.com/kuberwastaken/megaphone/blob/main/Sources/TransformStore.swift): `Sources/TransformStore.swift`

### History and support

- [Run history](https://github.com/kuberwastaken/megaphone/blob/main/Sources/PipelineHistoryStore.swift): `Sources/PipelineHistoryStore.swift`
- [History records](https://github.com/kuberwastaken/megaphone/blob/main/Sources/PipelineHistoryItem.swift): `Sources/PipelineHistoryItem.swift`
- [Pipeline diagnostics](https://github.com/kuberwastaken/megaphone/blob/main/Sources/PipelineDebugPanelView.swift): `Sources/PipelineDebugPanelView.swift`
- [Test-case export](https://github.com/kuberwastaken/megaphone/blob/main/Sources/TestCaseExporter.swift): `Sources/TestCaseExporter.swift`
- [Update manager](https://github.com/kuberwastaken/megaphone/blob/main/Sources/UpdateManager.swift): `Sources/UpdateManager.swift`

### Other components

- **Mac user**
- **Active application**
- **Release service**

## Connections

- Mac user → Shortcut backend: triggers
- Shortcut backend → Shortcut matching: reduces input (evidence: `Sources/HotkeyManager.swift`)
- Shortcut backend → Dictation session: dispatches events
- Mac user → Audio recording: speaks
- Audio recording → SpeechAnalyzer: streams audio
- SpeechAnalyzer → Smart cleanup: provides transcript
- SpeechAnalyzer → Basic cleanup: fallback cleanup
- Smart cleanup → Active application: uses context
- Active-app context → Active application: reads context
- SpeechAnalyzer → Personal dictionary: uses vocabulary
- SpeechAnalyzer → Wake phrase: checks trigger
- SpeechAnalyzer → Voice macros: applies macros
- App lifecycle → Shortcut backend: configures (evidence: `Sources/AppState.swift`)
- App lifecycle → Audio recording: starts recording (evidence: `Sources/AppState.swift`)
- App lifecycle → SpeechAnalyzer: coordinates transcription (evidence: `Sources/AppState.swift`)
- App lifecycle → Smart cleanup: requests cleanup (evidence: `Sources/AppState.swift`)
- App lifecycle → Active-app context: captures context
- App lifecycle → Run history: stores run history (evidence: `Sources/AppState.swift`)
- Run history → History records: persists records (evidence: `Sources/PipelineHistoryStore.swift`)
- Settings and setup → Personal dictionary: configures (evidence: `Sources/SettingsView.swift`)
- Settings and setup → Update manager: checks updates (evidence: `Sources/SettingsView.swift`)
- First-run setup → App lifecycle: configures (evidence: `Sources/SetupView.swift`)
- Pipeline diagnostics → Test-case export: exports cases (evidence: `Sources/PipelineDebugPanelView.swift`)
- Pipeline diagnostics → History records: displays pipeline (evidence: `Sources/PipelineDebugPanelView.swift`)
- Update manager → Release service: checks releases (evidence: `Sources/UpdateManager.swift`)
- App lifecycle → Settings and setup: shows interface (evidence: `Sources/App.swift`)
