# fikrikarim/parlor architecture

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

- Interactive diagram: https://gitdiagram.com/fikrikarim/parlor
- Repository: https://github.com/fikrikarim/parlor

## Overview

#### Purpose and Entry Points
Parlor is a local-first, real-time multimodal voice assistant: browser microphone/camera input is processed by a Python server and returned as streamed transcripts and synthesized speech. The executable entry point is the `parlor` package/server, with the browser UI served by FastAPI.
- `src/parlor/server.py`
- `src/parlor/web/index.html`
- `src/parlor/web/static/app.js`

#### Connection and Session Orchestration
`server.py` owns the FastAPI application, HTTP UI serving, WebSocket endpoint, and per-connection conversation state. Each WebSocket session receives PCM audio and JPEG camera frames, manages interruption/barge-in, tracks conversation history and elapsed time, and emits transcript, UI-state, timer, and audio events.
- `src/parlor/server.py`
- `src/parlor/modes.py`
- `src/parlor/pipeline.py`

#### Browser Media Boundary
The browser captures microphone and camera data, uses client-side Silero VAD to detect speech/silence, sends media over WebSocket, and plays incremental TTS audio. It also renders transcript, timer, and mode state. VAD is deliberately client-side; semantic end-of-turn determination is server-side.
- `src/parlor/web/static/app.js`
- `src/parlor/web/index.html`
- `src/parlor/web/static/style.css`

#### Turn Detection and Multimodal Inference
Audio turns pass through smart-turn-v3 to distinguish completed utterances from mid-thought pauses. The local Gemma model, hosted through `llama-server`, consumes audio, current camera context, history, session timing, and mode instructions. Input can be prefetched into llama.cpp’s prompt cache while the user is speaking to reduce response latency.
- `src/parlor/turn_detector.py`
- `src/parlor/llama.py`
- `src/parlor/server.py`

#### Streaming Response Pipeline
The response pipeline commits and publishes recognized user transcript content, streams model output, segments it into speakable sentences, and feeds sentences to TTS as generation continues. Barge-in cancels active model/TTS work rather than waiting for a full response.
- `src/parlor/pipeline.py`
- `src/parlor/llama.py`
- `src/parlor/tts.py`

#### Actions, Modes, and Server-Owned Timers
Control is separated from spoken generation. A second grammar-constrained JSON inference pass decides actions such as timer creation/cancellation, translation/listen mode changes, and research delegation; its markup never reaches TTS. `modes.py` changes turn behavior: conversation replies, consecutive translation, or silent transcription. Timers are maintained by the server so they can fire independently of a subsequent user turn.
- `src/parlor/actions.py`
- `src/parlor/modes.py`
- `src/parlor/server.py`

#### Optional Background Research
Research actions are delegated asynchronously while local conversation remains responsive. The reasoner calls a configurable OpenAI-compatible endpoint—defaulting to OpenRouter—and later injects/speaks its result. Without `REASONER_API_KEY`, this branch is disabled and operation remains on-device.
- `src/parlor/reasoner.py`
- `src/parlor/actions.py`
- `.env.example`

#### Runtime and Model Infrastructure
Python 3.12+ runs FastAPI and the orchestration stack. llama.cpp is an external local inference runtime for quantized Gemma 4 plus multimodal projector; models download on demand. Kokoro TTS uses MLX on Apple Silicon and ONNX on Linux/GPU-capable environments. smart-turn-v3 is a local turn-classification dependency.
- `pyproject.toml`
- `src/parlor/llama.py`
- `src/parlor/tts.py`

Main entry points: [`src/parlor/server.py`](https://github.com/fikrikarim/parlor/blob/main/src/parlor/server.py) (FastAPI + WebSocket), [`src/parlor/pipeline.py`](https://github.com/fikrikarim/parlor/blob/main/src/parlor/pipeline.py) (Streaming response pipeline), [`src/parlor/actions.py`](https://github.com/fikrikarim/parlor/blob/main/src/parlor/actions.py) (Action planner), [`src/parlor/web/static/app.js`](https://github.com/fikrikarim/parlor/blob/main/src/parlor/web/static/app.js) (Media client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser client"]
  node_ui["Web UI<br/>HTML/CSS UI<br/>[index.html]"]
  node_browser_media["Media client<br/>browser media<br/>[app.js]"]
  node_client_vad["Client-side VAD<br/>Silero VAD<br/>[app.js]"]
end

subgraph group_server["Python session server"]
  node_fastapi_session{{"FastAPI + WebSocket<br/>connection host<br/>[server.py]"}}
  node_session_state["Conversation session<br/>session state<br/>[server.py]"]
  node_server_timers["Server timers<br/>timer scheduler<br/>[server.py]"]
  node_modes["Interaction modes<br/>turn policy<br/>[modes.py]"]
  node_actions["Action planner<br/>constrained JSON pass<br/>[actions.py]"]
end

subgraph group_local_ai["Local AI pipeline"]
  node_turn_detector["Semantic turn detector<br/>smart-turn-v3<br/>[turn_detector.py]"]
  node_response_pipeline["Streaming response pipeline<br/>turn pipeline<br/>[pipeline.py]"]
  node_llama_adapter["Llama inference adapter<br/>llama.cpp client<br/>[llama.py]"]
  node_llama_server[("llama-server + Gemma<br/>local model runtime<br/>[llama.py]")]
  node_tts["Streaming TTS<br/>Kokoro<br/>[tts.py]"]
end

subgraph group_research["Optional research"]
  node_reasoner["Research reasoner<br/>OpenAI-compatible client<br/>[reasoner.py]"]
  node_openrouter{{"Compatible reasoning endpoint<br/>remote API<br/>[.env.example]"}}
end

node_ui -->|"hosts controls"| node_browser_media
node_browser_media -->|"audio frames"| node_client_vad
node_browser_media -->|"WebSocket PCM, JPEG, events"| node_fastapi_session
node_client_vad -->|"speech/silence signals"| node_fastapi_session
node_fastapi_session -->|"creates and updates"| node_session_state
node_fastapi_session -->|"audio turns"| node_turn_detector
node_turn_detector -->|"completed utterance"| node_response_pipeline
node_session_state -->|"history, vision, timing"| node_response_pipeline
node_modes -->|"response policy"| node_response_pipeline
node_response_pipeline -->|"stream generation"| node_llama_adapter
node_llama_adapter -->|"prompt cache and inference"| node_llama_server
node_response_pipeline -->|"control decision"| node_actions
node_actions -->|"mode changes"| node_modes
node_actions -->|"create or cancel"| node_server_timers
node_actions -.->|"research delegation"| node_reasoner
node_reasoner -.->|"configured request"| node_openrouter
node_reasoner -.->|"later result"| node_response_pipeline
node_response_pipeline -->|"speakable sentences"| node_tts
node_tts -->|"incremental audio"| node_fastapi_session
node_fastapi_session -->|"transcript, state, timer, audio"| node_browser_media
node_fastapi_session -->|"barge-in cancellation"| node_response_pipeline
node_server_timers -->|"timer events"| node_fastapi_session

click node_ui "https://github.com/fikrikarim/parlor/blob/main/src/parlor/web/index.html"
click node_browser_media "https://github.com/fikrikarim/parlor/blob/main/src/parlor/web/static/app.js"
click node_client_vad "https://github.com/fikrikarim/parlor/blob/main/src/parlor/web/static/app.js"
click node_fastapi_session "https://github.com/fikrikarim/parlor/blob/main/src/parlor/server.py"
click node_session_state "https://github.com/fikrikarim/parlor/blob/main/src/parlor/server.py"
click node_server_timers "https://github.com/fikrikarim/parlor/blob/main/src/parlor/server.py"
click node_modes "https://github.com/fikrikarim/parlor/blob/main/src/parlor/modes.py"
click node_turn_detector "https://github.com/fikrikarim/parlor/blob/main/src/parlor/turn_detector.py"
click node_response_pipeline "https://github.com/fikrikarim/parlor/blob/main/src/parlor/pipeline.py"
click node_llama_adapter "https://github.com/fikrikarim/parlor/blob/main/src/parlor/llama.py"
click node_llama_server "https://github.com/fikrikarim/parlor/blob/main/src/parlor/llama.py"
click node_actions "https://github.com/fikrikarim/parlor/blob/main/src/parlor/actions.py"
click node_tts "https://github.com/fikrikarim/parlor/blob/main/src/parlor/tts.py"
click node_reasoner "https://github.com/fikrikarim/parlor/blob/main/src/parlor/reasoner.py"
click node_openrouter "https://github.com/fikrikarim/parlor/blob/main/.env.example"

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_ui,node_browser_media,node_client_vad toneBlue
class node_fastapi_session,node_session_state,node_server_timers,node_modes,node_actions toneAmber
class node_turn_detector,node_response_pipeline,node_llama_adapter,node_llama_server,node_tts toneMint
class node_reasoner,node_openrouter toneRose
```

## Components

### Browser client

- [Web UI](https://github.com/fikrikarim/parlor/blob/main/src/parlor/web/index.html): HTML/CSS UI · Renders transcript, timer, and mode state. · `src/parlor/web/index.html`
- [Media client](https://github.com/fikrikarim/parlor/blob/main/src/parlor/web/static/app.js): browser media · Captures mic/camera and plays streamed speech. · `src/parlor/web/static/app.js`
- [Client-side VAD](https://github.com/fikrikarim/parlor/blob/main/src/parlor/web/static/app.js): Silero VAD · Detects local speech and silence. · `src/parlor/web/static/app.js`

### Python session server

- [FastAPI + WebSocket](https://github.com/fikrikarim/parlor/blob/main/src/parlor/server.py): connection host · Serves the UI and owns per-connection state. · `src/parlor/server.py`
- [Conversation session](https://github.com/fikrikarim/parlor/blob/main/src/parlor/server.py): session state · Tracks history, camera context, elapsed time, and interruption. · `src/parlor/server.py`
- [Server timers](https://github.com/fikrikarim/parlor/blob/main/src/parlor/server.py): timer scheduler · Fires independently of later user turns. · `src/parlor/server.py`
- [Interaction modes](https://github.com/fikrikarim/parlor/blob/main/src/parlor/modes.py): turn policy · Conversation, translation, and silent transcription behavior. · `src/parlor/modes.py`
- [Action planner](https://github.com/fikrikarim/parlor/blob/main/src/parlor/actions.py): constrained JSON pass · Separates control markup from spoken output. · `src/parlor/actions.py`

### Local AI pipeline

- [Semantic turn detector](https://github.com/fikrikarim/parlor/blob/main/src/parlor/turn_detector.py): smart-turn-v3 · Distinguishes completed turns from mid-thought pauses. · `src/parlor/turn_detector.py`
- [Streaming response pipeline](https://github.com/fikrikarim/parlor/blob/main/src/parlor/pipeline.py): turn pipeline · Publishes transcripts, segments output, and cancels on barge-in. · `src/parlor/pipeline.py`
- [Llama inference adapter](https://github.com/fikrikarim/parlor/blob/main/src/parlor/llama.py): llama.cpp client · Prefetches prompt context and streams local multimodal generation. · `src/parlor/llama.py`
- [llama-server + Gemma](https://github.com/fikrikarim/parlor/blob/main/src/parlor/llama.py): local model runtime · Hosts quantized Gemma 4 with the multimodal projector. · `src/parlor/llama.py`
- [Streaming TTS](https://github.com/fikrikarim/parlor/blob/main/src/parlor/tts.py): Kokoro · Uses MLX or ONNX according to platform. · `src/parlor/tts.py`

### Optional research

Disabled without a reasoner API key.

- [Research reasoner](https://github.com/fikrikarim/parlor/blob/main/src/parlor/reasoner.py): OpenAI-compatible client · Delegates background research without blocking conversation. · `src/parlor/reasoner.py`
- [Compatible reasoning endpoint](https://github.com/fikrikarim/parlor/blob/main/.env.example): remote API · Defaults to OpenRouter when configured. · `.env.example`

## Connections

- Web UI → Media client: hosts controls
- Media client → Client-side VAD: audio frames
- Media client → FastAPI + WebSocket: WebSocket PCM, JPEG, events
- Client-side VAD → FastAPI + WebSocket: speech/silence signals
- FastAPI + WebSocket → Conversation session: creates and updates
- FastAPI + WebSocket → Semantic turn detector: audio turns
- Semantic turn detector → Streaming response pipeline: completed utterance
- Conversation session → Streaming response pipeline: history, vision, timing
- Interaction modes → Streaming response pipeline: response policy
- Streaming response pipeline → Llama inference adapter: stream generation
- Llama inference adapter → llama-server + Gemma: prompt cache and inference
- Streaming response pipeline → Action planner: control decision
- Action planner → Interaction modes: mode changes
- Action planner → Server timers: create or cancel
- Action planner → Research reasoner: research delegation
- Research reasoner → Compatible reasoning endpoint: configured request
- Research reasoner → Streaming response pipeline: later result
- Streaming response pipeline → Streaming TTS: speakable sentences
- Streaming TTS → FastAPI + WebSocket: incremental audio
- FastAPI + WebSocket → Media client: transcript, state, timer, audio
- FastAPI + WebSocket → Streaming response pipeline: barge-in cancellation
- Server timers → FastAPI + WebSocket: timer events
