Code reference
Every source file, what it owns, and how it connects. The codebase is written to be read: files carry header comments explaining their role, and non-obvious decisions are documented where they live. This atlas is the index; the code is the detail.
Entry and configuration
| File | Owns |
|---|---|
src/index.ts | Process entrypoint: one Express app + HTTP server, every channel's routes, the WebSocket upgrade router (/ws pairing, /media call audio), fail-fast credential preflight, session sweeping. |
src/config.ts | All configuration, read once from env into one typed object. Every knob documented inline: voice modes, providers, speech tuning, languages, abuse thresholds, booking, recording, admin, intake. |
The realtime voice path
| File | Owns |
|---|---|
src/realtime/route.ts | The /voice-realtime webhook: TwiML that opens the media stream, plus minting and verifying the HMAC media token. |
src/realtime/twilioBridge.ts | The bridge between Twilio's media WebSocket and whatever voice model is active: the 20 ms drift-corrected pacer, barge-in orchestration (flush + truncate + cancel), the greeting play-to-end gate, per-call prompt assembly (static/dynamic split), tool dispatch, call logging, recording taps. |
src/realtime/types.ts | The provider-neutral contract (RealtimeModel, RealtimeFactory, handlers) that makes voice architectures swappable. |
src/realtime/geminiLive.ts | Fused speech-to-speech on Vertex AI: Application Default Credentials rather than an API key, inside the GCP BAA. Declares the SDK surface structurally so the adapter is testable offline against a fake session. |
src/realtime/audio/g711.ts | The μ-law codec plus the stateful resamplers between Twilio's 8 kHz phone audio and a model that speaks 16/24 kHz PCM. Carries interpolation state and decimation remainders across chunk boundaries. |
src/realtime/factory.ts | The runtime architecture switch: owner override persisted with an optional deadline, env default, resolved per call from the store so overlapping instances agree. |
src/realtime/deepgramCascade.ts | The production architecture's turn engine: utterance queue and merge, streaming LLM with sentence emission, per-language TTS sessions and reply-voice selection, echo suppression, the uninterruptible-greeting synthesis lock, turn-failure recovery. Every dependency injectable for offline verification. |
src/realtime/deepgram/stt.ts | Streaming STT over Deepgram's WebSocket: μ-law passthrough, VAD + endpointing, intent-gated barge-in, echo filtering hooks, per-word language tags with majority vote per utterance. |
src/realtime/deepgram/tts.ts | Streaming Aura TTS: per-call warm sessions (one socket per voice), pre-warming during LLM thinking, cancellation mid-synthesis, and a sessionless fallback path. |
src/realtime/openaiRealtime.ts | The fused speech-to-speech implementation of the same contract, the live demonstration of the other end of the fusion spectrum. |
The turn-based paths
| File | Owns |
|---|---|
src/ai.ts | The turn engine for text-mediated channels (web chat, cascaded voice): persona + context assembly, the tool loop (RAG search, fact saving, booking, pairing visuals). |
src/voice.ts | The original Gather/Say phone path, kept as fallback transport; Twilio signature validation; the abuse gate for this path. |
src/web.ts | The public API: chat, resume, profile, pairing; the per-IP rate limiter; the pairing WebSocket with typed-input injection into live calls. |
src/webchat.ts | Web-chat session shaping around the turn engine. |
src/sms.ts | The SMS agent: booking-management persona and tools, outreach-context injection, the verbal-consent confirmation text. |
src/telegram.ts | The owner intake channel: the call-report tool ("has anyone called?"), outreach tools (send, check), the architecture-switch tool, the two-gate security model, short-lived owner thread state. |
Shared foundations
| File | Owns |
|---|---|
src/persona.ts | The one persona every channel shares: identity, the adaptive conversation template, grounding rules, the caller-identity hard rule, the consent script requirements, the bilingual mirror rule, per-call context assembly. |
src/knowledge.ts | The markdown knowledge base: heading-scoped chunking, the BM25 index, search, the resume-section renderer for the website. |
src/db.ts | SQLite: schema (callers, calls, facts, transcripts, bookings, outreach, consent, settings), prepared-statement helpers. |
src/sessions.ts | Live call sessions: pairing codes, browser sockets, web-event fan-out, stale sweeping. |
src/callerPolicy.ts | Repeat-caller assessment: normal → limited → blocked, with the limited-tier note and duration cap. |
src/admin.ts | Owner views: live-probe status page, recent calls with transcripts, bookings; timing-safe token guard. |
Reasoning providers
| File | Owns |
|---|---|
src/llm/types.ts | The neutral chat contract: messages, tools, streaming, the static/dynamic system split, the conversation-cache flag. |
src/llm/provider.ts | Provider selection from config; the rest of the app imports one provider. |
src/llm/anthropic.ts | Claude via the Anthropic API: streaming, tool use, cache-aware system blocks, per-call token logging. |
src/llm/anthropicShared.ts | Message conversion shared by the Anthropic and Vertex clients, including the conversation cache breakpoint. |
src/llm/vertex.ts | The same models via Google Vertex AI (kept for BAA-covered deployments); auth by Application Default Credentials, no API key. |
src/llm/openai.ts | Any OpenAI-compatible endpoint (open models, self-hosted vLLM) behind the same contract. |
Booking and recording
| File | Owns |
|---|---|
src/booking/booking.ts | The book_intro_call tool: validation, free/busy, tentative event creation, lead-capture fallback, booking rows. |
src/booking/calendar.ts | The Google Calendar client (ADC auth), injectable for tests. |
src/recording/recorder.ts · wav.ts · blob.ts | Off-by-default call recording: stereo WAV assembly (caller left, Elle right), GCS upload with JSON sidecar. |
Verification suites
Seven offline suites (*.verify.ts) fake every network dependency and assert
the real logic: the bridge's barge-in trio, the cascade's streaming/tool/re-framing/bilingual
behavior, BM25 retrieval, booking outcomes, abuse escalation, and WAV framing. They run in CI
fashion before any deploy: npm run typecheck && npm run verify:*.
Reading order
config.ts, every capability announces itself here.index.ts, how channels mount.realtime/types.tsthentwilioBridge.ts, the seam, then the hardest consumer of it.deepgramCascade.ts, the heart of the system; the header comment is the map.persona.ts, where behavior is actually specified.