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

FileOwns
src/index.tsProcess 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.tsAll 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

FileOwns
src/realtime/route.tsThe /voice-realtime webhook: TwiML that opens the media stream, plus minting and verifying the HMAC media token.
src/realtime/twilioBridge.tsThe 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.tsThe provider-neutral contract (RealtimeModel, RealtimeFactory, handlers) that makes voice architectures swappable.
src/realtime/geminiLive.tsFused 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.tsThe μ-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.tsThe 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.tsThe 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.tsStreaming 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.tsStreaming 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.tsThe fused speech-to-speech implementation of the same contract, the live demonstration of the other end of the fusion spectrum.

The turn-based paths

FileOwns
src/ai.tsThe 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.tsThe original Gather/Say phone path, kept as fallback transport; Twilio signature validation; the abuse gate for this path.
src/web.tsThe public API: chat, resume, profile, pairing; the per-IP rate limiter; the pairing WebSocket with typed-input injection into live calls.
src/webchat.tsWeb-chat session shaping around the turn engine.
src/sms.tsThe SMS agent: booking-management persona and tools, outreach-context injection, the verbal-consent confirmation text.
src/telegram.tsThe 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

FileOwns
src/persona.tsThe 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.tsThe markdown knowledge base: heading-scoped chunking, the BM25 index, search, the resume-section renderer for the website.
src/db.tsSQLite: schema (callers, calls, facts, transcripts, bookings, outreach, consent, settings), prepared-statement helpers.
src/sessions.tsLive call sessions: pairing codes, browser sockets, web-event fan-out, stale sweeping.
src/callerPolicy.tsRepeat-caller assessment: normal → limited → blocked, with the limited-tier note and duration cap.
src/admin.tsOwner views: live-probe status page, recent calls with transcripts, bookings; timing-safe token guard.

Reasoning providers

FileOwns
src/llm/types.tsThe neutral chat contract: messages, tools, streaming, the static/dynamic system split, the conversation-cache flag.
src/llm/provider.tsProvider selection from config; the rest of the app imports one provider.
src/llm/anthropic.tsClaude via the Anthropic API: streaming, tool use, cache-aware system blocks, per-call token logging.
src/llm/anthropicShared.tsMessage conversion shared by the Anthropic and Vertex clients, including the conversation cache breakpoint.
src/llm/vertex.tsThe same models via Google Vertex AI (kept for BAA-covered deployments); auth by Application Default Credentials, no API key.
src/llm/openai.tsAny OpenAI-compatible endpoint (open models, self-hosted vLLM) behind the same contract.

Booking and recording

FileOwns
src/booking/booking.tsThe book_intro_call tool: validation, free/busy, tentative event creation, lead-capture fallback, booking rows.
src/booking/calendar.tsThe Google Calendar client (ADC auth), injectable for tests.
src/recording/recorder.ts · wav.ts · blob.tsOff-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

  1. config.ts, every capability announces itself here.
  2. index.ts, how channels mount.
  3. realtime/types.ts then twilioBridge.ts, the seam, then the hardest consumer of it.
  4. deepgramCascade.ts, the heart of the system; the header comment is the map.
  5. persona.ts, where behavior is actually specified.