# ahmeds2099/via---interrupt-aware-voice-agent architecture

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

- Interactive diagram: https://gitdiagram.com/ahmeds2099/via---interrupt-aware-voice-agent
- Repository: https://github.com/ahmeds2099/via---interrupt-aware-voice-agent

## Overview

#### Purpose and entry points
Via is a document-grounded, interruption-aware voice agent. A Next.js browser client captures microphone PCM, plays streamed TTS, and exposes provider/state telemetry; a FastAPI backend owns the real-time voice state machine and HTTP APIs. Runtime entry points are `backend/app/main.py` (Uvicorn ASGI app) and `frontend/app/page.tsx` (browser UI).

#### Client voice transport and UI
The frontend establishes and supervises the voice session, records 16 kHz PCM, exchanges WebSocket events, and renders connection/voice state plus an architecture dashboard. API base URL/environment handling is isolated from UI behavior.
- `frontend/hooks/usevoice.ts`
- `frontend/lib/voice/websocket.ts`
- `frontend/lib/voice/recorder.ts`
- `frontend/components/dashboard/architecturedashboard.tsx`

#### API boundary
FastAPI exposes HTTP endpoints for health/status, document upload and search/ask workflows, STT/TTS, plus the primary streaming voice endpoint. The WebSocket boundary accepts audio and control events and emits transcript, playback, response, and observability events.
- `backend/app/api/voice.py`
- `backend/app/api/stream.py`
- `backend/app/api/upload.py`
- `backend/app/main.py`

#### Voice orchestration and interruption state
The backend explicitly owns voice control rather than delegating it to LangGraph/Vapi. Per-session state tracks active speech, paused responses, playback acknowledgments, interruption intent, and reconnect restoration. The dispatcher routes audio/control/ping messages; the voice pipeline coordinates VAD, streaming STT, response generation, TTS, cancellation, and resume behavior.
- `backend/app/services/voice/voice_pipeline.py`
- `backend/app/services/voice/dispatcher.py`
- `backend/app/services/voice/session_manager.py`
- `backend/app/services/conversation/response_controller.py`
- `backend/app/services/conversation/paused_response.py`

#### Speech and affect providers
Speech detection is pluggable: full deployments use local Silero VAD; lite deployments use energy VAD. Deepgram is the primary live transcription service, with an optional consent-based local Whisper fallback. Cartesia produces streamed speech. Emotion recognition is an optional local signal, used only when confidence/recent-turn smoothing supports adaptation.
- `backend/app/services/voice/vad.py`
- `backend/app/services/voice/deepgram.py`
- `backend/app/services/stt/factory.py`
- `backend/app/services/tts/cartesia.py`
- `backend/app/services/emotion/provider.py`

#### Grounded-answer pipeline
Uploads are extracted and chunked with source metadata, embedded through FastEmbed, and stored as vectors. At answer time, retrieval supplies relevant source context to prompt construction and Groq-backed LLM generation. The system can operate without an uploaded document as a general assistant.
- `backend/app/services/document_ingestion.py`
- `backend/app/services/chunker.py`
- `backend/app/services/embedder.py`
- `backend/app/services/retrieval.py`
- `backend/app/services/llm.py`

#### Persistence, infrastructure, and deployment modes
Qdrant Cloud is the durable semantic store for document chunks and long-term memory; Upstash Redis stores session snapshots, recent messages, and restoration state. Configuration selects full versus constrained lite runtime behavior, including model/provider availability. Required external services are Groq, Deepgram, Cartesia, Qdrant, and Upstash Redis.
- `backend/app/core/config.py`
- `backend/app/core/qdrant.py`
- `backend/app/services/session_repository.py`
- `backend/app/services/memory_service.py`
- `backend/requirements-lite.txt`

Main entry points: [`backend/app/services/voice/voice_pipeline.py`](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/voice/voice_pipeline.py) (Voice pipeline), [`backend/app/main.py`](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/main.py) (ASGI application), [`frontend/hooks/usevoice.ts`](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/hooks/usevoice.ts) (Voice session hook), [`backend/app/api/upload.py`](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/api/upload.py) (Document & speech APIs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_ui["Voice UI &amp; dashboard<br/>Next.js UI<br/>[page.tsx]"]
  node_voice_hook["Voice session hook<br/>client controller<br/>[usevoice.ts]"]
  node_browser_transport["WebSocket transport<br/>client transport<br/>[websocket.ts]"]
  node_recorder["PCM recorder<br/>audio capture<br/>[recorder.ts]"]
  node_dashboard["Architecture dashboard<br/>UI component"]
end

subgraph group_api["FastAPI boundary"]
  node_asgi["ASGI application<br/>FastAPI app<br/>[main.py]"]
  node_http_api["Document &amp; speech APIs<br/>HTTP routes<br/>[upload.py]"]
  node_voice_ws["Streaming voice endpoint<br/>WebSocket route<br/>[voice.py]"]
  node_stream_api["Stream API<br/>stream routes<br/>[stream.py]"]
end

subgraph group_voice["Voice orchestration"]
  node_dispatcher["Event dispatcher<br/>voice router<br/>[dispatcher.py]"]
  node_voice_pipeline["Voice pipeline<br/>realtime orchestrator<br/>[voice_pipeline.py]"]
  node_session_manager["Voice session manager<br/>session state<br/>[session_manager.py]"]
  node_response_control["Response control<br/>conversation state"]
  node_speech_stack["VAD and live STT<br/>speech providers<br/>[factory.py]"]
  node_cartesia["Cartesia TTS<br/>streaming TTS<br/>[cartesia.py]"]
end

subgraph group_grounding["Grounded answers"]
  node_ingestion["Document ingestion<br/>ingestion pipeline"]
  node_retrieval["Retrieval<br/>[retrieval.py]"]
  node_llm["Groq answer generation<br/>LLM service<br/>[llm.py]"]
end

subgraph group_state["State and providers"]
  node_qdrant[("Qdrant Cloud<br/>vector store<br/>[qdrant.py]")]
  node_redis[("Upstash Redis<br/>session store")]
  node_runtime_config["Runtime mode config<br/>deployment config<br/>[config.py]"]
end

node_ui -->|"drives"| node_voice_hook
node_ui -->|"renders"| node_dashboard
node_voice_hook -->|"captures audio"| node_recorder
node_voice_hook -->|"supervises"| node_browser_transport
node_browser_transport -->|"WebSocket events"| node_voice_ws
node_asgi -->|"serves"| node_http_api
node_asgi -->|"serves"| node_voice_ws
node_asgi -->|"serves"| node_stream_api
node_voice_ws -->|"incoming events"| node_dispatcher
node_dispatcher -->|"audio and control"| node_voice_pipeline
node_dispatcher -->|"session events"| node_session_manager
node_voice_pipeline -->|"detects and transcribes"| node_speech_stack
node_voice_pipeline -->|"interrupts or resumes"| node_response_control
node_voice_pipeline -->|"requests answer"| node_llm
node_voice_pipeline -->|"streams speech"| node_cartesia
node_voice_pipeline -->|"updates voice state"| node_session_manager
node_session_manager -->|"snapshots and restoration"| node_redis
node_http_api -->|"uploads documents"| node_ingestion
node_http_api -->|"searches and asks"| node_retrieval
node_ingestion -->|"stores vectors"| node_qdrant
node_retrieval -->|"retrieves context"| node_qdrant
node_retrieval -->|"grounding context"| node_llm
node_runtime_config -.->|"selects providers"| node_speech_stack
node_runtime_config -.->|"enables availability"| node_cartesia

click node_ui "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/app/page.tsx"
click node_voice_hook "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/hooks/usevoice.ts"
click node_browser_transport "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/lib/voice/websocket.ts"
click node_recorder "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/lib/voice/recorder.ts"
click node_dashboard "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/components/dashboard/architecturedashboard.tsx"
click node_asgi "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/main.py"
click node_http_api "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/api/upload.py"
click node_voice_ws "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/api/voice.py"
click node_stream_api "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/api/stream.py"
click node_dispatcher "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/voice/dispatcher.py"
click node_voice_pipeline "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/voice/voice_pipeline.py"
click node_session_manager "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/voice/session_manager.py"
click node_response_control "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/conversation/response_controller.py"
click node_speech_stack "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/stt/factory.py"
click node_cartesia "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/tts/cartesia.py"
click node_ingestion "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/document_ingestion.py"
click node_retrieval "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/retrieval.py"
click node_llm "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/llm.py"
click node_qdrant "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/core/qdrant.py"
click node_redis "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/session_repository.py"
click node_runtime_config "https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/core/config.py"

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_voice_hook,node_browser_transport,node_recorder,node_dashboard toneBlue
class node_asgi,node_http_api,node_voice_ws,node_stream_api toneAmber
class node_dispatcher,node_voice_pipeline,node_session_manager,node_response_control,node_speech_stack,node_cartesia toneMint
class node_ingestion,node_retrieval,node_llm toneRose
class node_qdrant,node_redis,node_runtime_config toneIndigo
```

## Components

### Browser client

- [Voice UI & dashboard](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/app/page.tsx): Next.js UI · Shows voice state, telemetry, and architecture. · `frontend/app/page.tsx`
- [Voice session hook](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/hooks/usevoice.ts): client controller · Supervises the browser voice session. · `frontend/hooks/usevoice.ts`
- [WebSocket transport](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/lib/voice/websocket.ts): client transport · Exchanges audio, control, and voice events. · `frontend/lib/voice/websocket.ts`
- [PCM recorder](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/lib/voice/recorder.ts): audio capture · Captures 16 kHz microphone PCM. · `frontend/lib/voice/recorder.ts`
- [Architecture dashboard](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/frontend/components/dashboard/architecturedashboard.tsx): UI component · `frontend/components/dashboard/architecturedashboard.tsx`

### FastAPI boundary

- [ASGI application](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/main.py): FastAPI app · Hosts HTTP and streaming API routes. · `backend/app/main.py`
- [Document & speech APIs](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/api/upload.py): HTTP routes · Provides health, upload, search/ask, STT, and TTS workflows. · `backend/app/api/upload.py`
- [Streaming voice endpoint](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/api/voice.py): WebSocket route · Accepts audio/control events and emits transcript, playback, response, and observability events. · `backend/app/api/voice.py`
- [Stream API](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/api/stream.py): stream routes · `backend/app/api/stream.py`

### Voice orchestration

- [Event dispatcher](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/voice/dispatcher.py): voice router · Routes audio, control, and ping messages. · `backend/app/services/voice/dispatcher.py`
- [Voice pipeline](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/voice/voice_pipeline.py): realtime orchestrator · Coordinates detection, transcription, generation, speech, cancellation, and resume. · `backend/app/services/voice/voice_pipeline.py`
- [Voice session manager](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/voice/session_manager.py): session state · Tracks speech, playback acknowledgments, interruption, and reconnect state. · `backend/app/services/voice/session_manager.py`
- [Response control](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/conversation/response_controller.py): conversation state · Manages interruption and paused-response behavior. · `backend/app/services/conversation/response_controller.py`
- [VAD and live STT](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/stt/factory.py): speech providers · Uses Silero or energy VAD and Deepgram with optional Whisper fallback. · `backend/app/services/stt/factory.py`
- [Cartesia TTS](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/tts/cartesia.py): streaming TTS · `backend/app/services/tts/cartesia.py`

### Grounded answers

- [Document ingestion](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/document_ingestion.py): ingestion pipeline · Extracts, chunks, embeds, and preserves source metadata. · `backend/app/services/document_ingestion.py`
- [Retrieval](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/retrieval.py): semantic retrieval · Supplies relevant source context for answers. · `backend/app/services/retrieval.py`
- [Groq answer generation](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/llm.py): LLM service · Generates grounded or general-assistant responses. · `backend/app/services/llm.py`

### State and providers

- [Qdrant Cloud](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/core/qdrant.py): vector store · Durable store for document chunks and long-term memory. · `backend/app/core/qdrant.py`
- [Upstash Redis](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/services/session_repository.py): session store · Stores snapshots, recent messages, and restoration state. · `backend/app/services/session_repository.py`
- [Runtime mode config](https://github.com/ahmeds2099/via---interrupt-aware-voice-agent/blob/main/backend/app/core/config.py): deployment config · Selects full or constrained lite provider behavior. · `backend/app/core/config.py`

## Connections

- Voice UI & dashboard → Voice session hook: drives
- Voice UI & dashboard → Architecture dashboard: renders
- Voice session hook → PCM recorder: captures audio
- Voice session hook → WebSocket transport: supervises
- WebSocket transport → Streaming voice endpoint: WebSocket events
- ASGI application → Document & speech APIs: serves
- ASGI application → Streaming voice endpoint: serves
- ASGI application → Stream API: serves
- Streaming voice endpoint → Event dispatcher: incoming events
- Event dispatcher → Voice pipeline: audio and control
- Event dispatcher → Voice session manager: session events
- Voice pipeline → VAD and live STT: detects and transcribes
- Voice pipeline → Response control: interrupts or resumes
- Voice pipeline → Groq answer generation: requests answer
- Voice pipeline → Cartesia TTS: streams speech
- Voice pipeline → Voice session manager: updates voice state
- Voice session manager → Upstash Redis: snapshots and restoration
- Document & speech APIs → Document ingestion: uploads documents
- Document & speech APIs → Retrieval: searches and asks
- Document ingestion → Qdrant Cloud: stores vectors
- Retrieval → Qdrant Cloud: retrieves context
- Retrieval → Groq answer generation: grounding context
- Runtime mode config → VAD and live STT: selects providers
- Runtime mode config → Cartesia TTS: enables availability
