# classiccosta/emma architecture

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

- Interactive diagram: https://gitdiagram.com/classiccosta/emma
- Repository: https://github.com/classiccosta/emma

## Overview

Emma is a local macOS voice assistant: the user speaks a wake phrase and request, Emma transcribes and routes it to a stock response or local model, then speaks and displays the reply. The graph preserves the documented audio, conversation, model, speech, settings, and panel capabilities. Some links reflect the README’s stage descriptions; unsampled modules are included where documented, without assuming their internal call relationships.

Main entry points: [`Sources/Emma/App/AssistantEngine.swift`](https://github.com/classiccosta/emma/blob/main/Sources/Emma/App/AssistantEngine.swift) (Assistant engine), [`Sources/Emma/Audio/AudioCapture.swift`](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Audio/AudioCapture.swift) (Audio capture), [`Sources/Emma/LLM/LocalLLMClient.swift`](https://github.com/classiccosta/emma/blob/main/Sources/Emma/LLM/LocalLLMClient.swift) (Local model client), [`Sources/Emma/App/ServiceSupervisor.swift`](https://github.com/classiccosta/emma/blob/main/Sources/Emma/App/ServiceSupervisor.swift) (Service supervisor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App orchestration"]
  node_engine["Assistant engine"]
  node_phase["Assistant phase<br/>[Phase.swift]"]
end

subgraph group_audio["Audio input"]
  node_audio_capture["Audio capture<br/>[AudioCapture.swift]"]
  node_endpointer["Endpointer<br/>[Endpointer.swift]"]
  node_wake["Wake detection"]
  node_transcriber["Transcription<br/>[Transcriber.swift]"]
end

subgraph group_conversation["Conversation and replies"]
  node_router["Reply routing<br/>[ReplyRouter.swift]"]
  node_stock["Stock replies<br/>[StockReplies.swift]"]
  node_history["Chat history<br/>[ChatHistory.swift]"]
  node_log["Conversation log"]
  node_reply_session["Reply session<br/>[ReplySession.swift]"]
  node_rules["Reply rules"]
  node_text_filter["Model text filter"]
  node_model["Local model client"]
end

subgraph group_speech["Speech and local services"]
  node_lmstudio["LM Studio<br/>[LMStudio.swift]"]
  node_services["Service supervisor"]
  node_kokoro_server["Kokoro server client<br/>[KokoroServer.swift]"]
  node_sidecar["Kokoro sidecar<br/>[tts_server.py]"]
  node_voice["Voice selection<br/>[Voice.swift]"]
  node_kokoro_speech["Kokoro speech<br/>[KokoroSpeech.swift]"]
  node_apple_speech["Apple speech fallback<br/>[AppleSpeech.swift]"]
end

subgraph group_interface["Settings and interface"]
  node_settings["Assistant settings<br/>[Settings.swift]"]
  node_settings_window["Settings window"]
  node_panel["Menu bar panel<br/>[PanelView.swift]"]
end

node_user(("User"))

node_user -->|"speaks to"| node_audio_capture
node_audio_capture -->|"segments audio"| node_endpointer
node_audio_capture -->|"forwards audio"| node_wake
node_audio_capture -->|"provides audio"| node_transcriber
node_wake -->|"signals wake"| node_engine
node_transcriber -->|"returns transcript"| node_engine
node_engine -->|"routes utterance"| node_router
node_router -->|"selects stock reply"| node_stock
node_engine -->|"uses context"| node_history
node_engine -->|"requests reply"| node_model
node_model -->|"uses prompt"| node_rules
node_model -->|"sends completion request"| node_lmstudio
node_engine -->|"filters reply"| node_text_filter
node_engine -->|"streams reply"| node_reply_session
node_engine -->|"records conversation"| node_log
node_engine -->|"checks services"| node_services
node_services -->|"starts and warms"| node_lmstudio
node_services -->|"starts voice service"| node_kokoro_server
node_kokoro_server -->|"sends synthesis requests"| node_sidecar
node_engine -->|"speaks response"| node_voice
node_voice -->|"selects Kokoro"| node_kokoro_speech
node_voice -->|"selects fallback"| node_apple_speech
node_kokoro_speech -->|"synthesizes speech"| node_kokoro_server
node_kokoro_speech -->|"falls back to"| node_apple_speech
node_engine -->|"updates phase"| node_phase
node_panel -->|"displays state"| node_engine
node_settings_window -->|"edits settings"| node_settings
node_settings_window -->|"applies changes"| node_engine
node_engine -->|"reads configuration"| node_settings

click node_engine "https://github.com/classiccosta/emma/blob/main/Sources/Emma/App/AssistantEngine.swift"
click node_phase "https://github.com/classiccosta/emma/blob/main/Sources/Emma/App/Phase.swift"
click node_audio_capture "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Audio/AudioCapture.swift"
click node_endpointer "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Audio/Endpointer.swift"
click node_wake "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Audio/WakeWordDetector.swift"
click node_transcriber "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Audio/Transcriber.swift"
click node_router "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Conversation/ReplyRouter.swift"
click node_stock "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Conversation/StockReplies.swift"
click node_history "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Conversation/ChatHistory.swift"
click node_log "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Conversation/ConversationLog.swift"
click node_reply_session "https://github.com/classiccosta/emma/blob/main/Sources/Emma/App/ReplySession.swift"
click node_rules "https://github.com/classiccosta/emma/blob/main/Sources/Emma/ReplyRules/PersonaPrompt.swift"
click node_text_filter "https://github.com/classiccosta/emma/blob/main/Sources/Emma/ReplyRules/ModelTextFilter.swift"
click node_model "https://github.com/classiccosta/emma/blob/main/Sources/Emma/LLM/LocalLLMClient.swift"
click node_lmstudio "https://github.com/classiccosta/emma/blob/main/Sources/Emma/LLM/LMStudio.swift"
click node_services "https://github.com/classiccosta/emma/blob/main/Sources/Emma/App/ServiceSupervisor.swift"
click node_kokoro_server "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Speech/KokoroServer.swift"
click node_sidecar "https://github.com/classiccosta/emma/blob/main/sidecars/kokoro/tts_server.py"
click node_voice "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Speech/Voice.swift"
click node_kokoro_speech "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Speech/KokoroSpeech.swift"
click node_apple_speech "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Speech/AppleSpeech.swift"
click node_settings "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Settings/Settings.swift"
click node_settings_window "https://github.com/classiccosta/emma/blob/main/Sources/Emma/Settings/SettingsWindow.swift"
click node_panel "https://github.com/classiccosta/emma/blob/main/Sources/Emma/UI/PanelView.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_engine,node_phase,node_user toneBlue
class node_audio_capture,node_endpointer,node_wake,node_transcriber toneAmber
class node_router,node_stock,node_history,node_log,node_reply_session,node_rules,node_text_filter,node_model toneMint
class node_lmstudio,node_services,node_kokoro_server,node_sidecar,node_voice,node_kokoro_speech,node_apple_speech toneRose
class node_settings,node_settings_window,node_panel toneIndigo
```

## Components

### App orchestration

- [Assistant engine](https://github.com/classiccosta/emma/blob/main/Sources/Emma/App/AssistantEngine.swift): `Sources/Emma/App/AssistantEngine.swift`
- [Assistant phase](https://github.com/classiccosta/emma/blob/main/Sources/Emma/App/Phase.swift): `Sources/Emma/App/Phase.swift`

### Audio input

- [Audio capture](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Audio/AudioCapture.swift): `Sources/Emma/Audio/AudioCapture.swift`
- [Endpointer](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Audio/Endpointer.swift): `Sources/Emma/Audio/Endpointer.swift`
- [Wake detection](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Audio/WakeWordDetector.swift): `Sources/Emma/Audio/WakeWordDetector.swift`
- [Transcription](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Audio/Transcriber.swift): `Sources/Emma/Audio/Transcriber.swift`

### Conversation and replies

- [Reply routing](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Conversation/ReplyRouter.swift): `Sources/Emma/Conversation/ReplyRouter.swift`
- [Stock replies](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Conversation/StockReplies.swift): `Sources/Emma/Conversation/StockReplies.swift`
- [Chat history](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Conversation/ChatHistory.swift): `Sources/Emma/Conversation/ChatHistory.swift`
- [Conversation log](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Conversation/ConversationLog.swift): `Sources/Emma/Conversation/ConversationLog.swift`
- [Reply session](https://github.com/classiccosta/emma/blob/main/Sources/Emma/App/ReplySession.swift): `Sources/Emma/App/ReplySession.swift`
- [Reply rules](https://github.com/classiccosta/emma/blob/main/Sources/Emma/ReplyRules/PersonaPrompt.swift): `Sources/Emma/ReplyRules/PersonaPrompt.swift`
- [Model text filter](https://github.com/classiccosta/emma/blob/main/Sources/Emma/ReplyRules/ModelTextFilter.swift): `Sources/Emma/ReplyRules/ModelTextFilter.swift`
- [Local model client](https://github.com/classiccosta/emma/blob/main/Sources/Emma/LLM/LocalLLMClient.swift): `Sources/Emma/LLM/LocalLLMClient.swift`

### Speech and local services

- [LM Studio](https://github.com/classiccosta/emma/blob/main/Sources/Emma/LLM/LMStudio.swift): `Sources/Emma/LLM/LMStudio.swift`
- [Service supervisor](https://github.com/classiccosta/emma/blob/main/Sources/Emma/App/ServiceSupervisor.swift): `Sources/Emma/App/ServiceSupervisor.swift`
- [Kokoro server client](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Speech/KokoroServer.swift): `Sources/Emma/Speech/KokoroServer.swift`
- [Kokoro sidecar](https://github.com/classiccosta/emma/blob/main/sidecars/kokoro/tts_server.py): `sidecars/kokoro/tts_server.py`
- [Voice selection](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Speech/Voice.swift): `Sources/Emma/Speech/Voice.swift`
- [Kokoro speech](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Speech/KokoroSpeech.swift): `Sources/Emma/Speech/KokoroSpeech.swift`
- [Apple speech fallback](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Speech/AppleSpeech.swift): `Sources/Emma/Speech/AppleSpeech.swift`

### Settings and interface

- [Assistant settings](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Settings/Settings.swift): `Sources/Emma/Settings/Settings.swift`
- [Settings window](https://github.com/classiccosta/emma/blob/main/Sources/Emma/Settings/SettingsWindow.swift): `Sources/Emma/Settings/SettingsWindow.swift`
- [Menu bar panel](https://github.com/classiccosta/emma/blob/main/Sources/Emma/UI/PanelView.swift): `Sources/Emma/UI/PanelView.swift`

### Other components

- **User**

## Connections

- User → Audio capture: speaks to (evidence: `README.md`)
- Audio capture → Endpointer: segments audio (evidence: `Sources/Emma/Audio/AudioCapture.swift`)
- Audio capture → Wake detection: forwards audio (evidence: `Sources/Emma/Audio/AudioCapture.swift`)
- Audio capture → Transcription: provides audio (evidence: `README.md`)
- Wake detection → Assistant engine: signals wake (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Transcription → Assistant engine: returns transcript (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Assistant engine → Reply routing: routes utterance (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Reply routing → Stock replies: selects stock reply (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Assistant engine → Chat history: uses context (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Assistant engine → Local model client: requests reply (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Local model client → Reply rules: uses prompt
- Local model client → LM Studio: sends completion request (evidence: `Sources/Emma/LLM/LocalLLMClient.swift`)
- Assistant engine → Model text filter: filters reply (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Assistant engine → Reply session: streams reply (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Assistant engine → Conversation log: records conversation (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Assistant engine → Service supervisor: checks services (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Service supervisor → LM Studio: starts and warms (evidence: `Sources/Emma/App/ServiceSupervisor.swift`)
- Service supervisor → Kokoro server client: starts voice service (evidence: `Sources/Emma/App/ServiceSupervisor.swift`)
- Kokoro server client → Kokoro sidecar: sends synthesis requests (evidence: `Sources/Emma/Speech/KokoroServer.swift`)
- Assistant engine → Voice selection: speaks response (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Voice selection → Kokoro speech: selects Kokoro (evidence: `Sources/Emma/Speech/Voice.swift`)
- Voice selection → Apple speech fallback: selects fallback (evidence: `Sources/Emma/Speech/Voice.swift`)
- Kokoro speech → Kokoro server client: synthesizes speech (evidence: `Sources/Emma/Speech/KokoroSpeech.swift`)
- Kokoro speech → Apple speech fallback: falls back to (evidence: `Sources/Emma/Speech/KokoroSpeech.swift`)
- Assistant engine → Assistant phase: updates phase (evidence: `Sources/Emma/App/AssistantEngine.swift`)
- Menu bar panel → Assistant engine: displays state (evidence: `Sources/Emma/UI/PanelView.swift`)
- Settings window → Assistant settings: edits settings (evidence: `Sources/Emma/Settings/SettingsWindow.swift`)
- Settings window → Assistant engine: applies changes (evidence: `Sources/Emma/Settings/SettingsWindow.swift`)
- Assistant engine → Assistant settings: reads configuration (evidence: `Sources/Emma/App/AssistantEngine.swift`)
