Skip to main content

Architecture Overview

LLMRTC is a modular SDK for building real-time voice and text AI applications. This page explains the overall architecture and how components interact.


Package Structure​

PackagePurpose
@llmrtc/llmrtc-coreTypes, orchestrators, tools, protocol, hooks
@llmrtc/llmrtc-backendServer, WebRTC, VAD, session management
@llmrtc/llmrtc-web-clientBrowser client, audio capture, events
@llmrtc/llmrtc-provider-*LLM, STT, TTS provider implementations

High-Level Data Flow​

Flow:

  1. User speaks into microphone
  2. Audio streams to server via WebRTC
  3. VAD detects speech boundaries
  4. STT transcribes audio to text
  5. LLM generates response
  6. TTS synthesizes speech
  7. Audio streams back to browser via WebRTC

Conversation Turn Sequence​


Server Components​

ComponentResponsibility
WebSocket HandlerSignaling, control messages
WebRTC HandlerAudio/video streaming
SessionManagerSession lifecycle, reconnection
AudioProcessorAudio buffering, format conversion
VADVoice activity detection (Silero v5)
ConversationOrchestratorSimple STT → LLM → TTS pipeline
VoicePlaybookOrchestratorTwo-phase execution with tools

Orchestrator Types​

ConversationOrchestrator​

Simple pipeline for single-prompt assistants:

PlaybookOrchestrator​

Two-phase execution with stages and tools:

VoicePlaybookOrchestrator​

Wraps PlaybookOrchestrator with STT/TTS for voice:


Transport Layer​

LLMRTC uses WebRTC for low-latency audio and WebSocket for signaling:

TransportPurpose
WebSocketSignaling (SDP, ICE), control messages
DataChannelLow-latency JSON messages (transcripts, tool events)
Audio TrackBidirectional audio streaming

Provider Architecture​

Providers implement standardized interfaces:

Provider Selection​


Session Lifecycle​

StateDescription
CreatedSession initialized, awaiting WebRTC setup
ActiveConnected and ready for conversation
ProcessingCurrently handling a conversation turn
ReconnectingConnection lost, attempting recovery
ExpiredSession TTL exceeded or max reconnect attempts

Playbook State Machine​


Streaming TTS Architecture​

Key: Sentence chunking enables TTS to start before LLM finishes, reducing time-to-first-audio.