# shelunagori/ai-voice-calling-collections-agent architecture

> Architecture diagram of the GitHub repository shelunagori/ai-voice-calling-collections-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shelunagori/ai-voice-calling-collections-agent
- Repository: https://github.com/shelunagori/ai-voice-calling-collections-agent

## Overview

This is a real-time voice collections proof of concept: an operator starts a browser or PSTN session; caller speech is interpreted as typed proposals, then deterministic phase and policy checks govern identity verification, disclosure, repayment, consent, transfer, and contact suppression. The voice runtime handles turn-taking and playback, while audit and persistence preserve outcomes for the operator. The map includes documented evaluation and NLU post-training capabilities. Some integrations are shown from README-level descriptions because their implementation files were not sampled.

Main entry points: [`backend/app/voice/session.py`](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/voice/session.py) (Voice session), [`backend/app/domain/understanding.py`](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/understanding.py) (Utterance understanding), [`backend/app/api/session_service.py`](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/api/session_service.py) (Session service), [`backend/app/domain/controller.py`](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/controller.py) (Conversation controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_operator["Operator console"]
  node_console["Web console<br/>[page.tsx]"]
  node_proxy["Operator routes<br/>[route.ts]"]
  node_auditui["Session audit UI"]
end

subgraph group_conversation["Conversation runtime"]
  node_api["REST routes<br/>[routes.py]"]
  node_telephony["Telephony webhooks<br/>[telephony.py]"]
  node_browserws["Browser voice socket<br/>[ws_browser.py]"]
  node_sessionopen["Session service<br/>[session_service.py]"]
  node_runtime["Runtime assembly<br/>[runtime.py]"]
  node_voice["Voice session<br/>[session.py]"]
  node_audio["Audio and turns<br/>[audio.py]"]
end

subgraph group_domain["Collections domain"]
  node_controller["Conversation controller<br/>[controller.py]"]
  node_policy["Policy rules<br/>[policy.py]"]
  node_turnctx["Phase action contract<br/>[turn_context.py]"]
  node_understanding["Utterance understanding<br/>[understanding.py]"]
  node_rules["Rules parser<br/>[nlu_rules.py]"]
  node_realizer["Response realization<br/>[realizer.py]"]
end

subgraph group_platform["Providers and persistence"]
  node_providers["Provider interfaces<br/>[base.py]"]
  node_cartesia["Cartesia speech<br/>[cartesia.py]"]
  node_cloudflare["Cloudflare LLM<br/>[cloudflare_llm.py]"]
  node_repo["Repository<br/>[repository.py]"]
  node_database[("PostgreSQL<br/>[tables.py]")]
  node_audit["Audit and metrics<br/>[audit.py]"]
end

subgraph group_quality["Evaluation and training"]
  node_evaluation["Evaluation suite<br/>[runner.py]"]
  node_training["NLU training data<br/>[build_dataset.py]"]
end

node_operator(("Operator"))
node_callee(("Caller"))
node_twilio["Twilio PSTN<br/>[twilio.py]"]

node_operator -->|"starts calls"| node_console
node_console -->|"requests calls"| node_proxy
node_console -->|"uses backend"| node_api
node_api -->|"opens sessions"| node_sessionopen
node_telephony -->|"opens calls"| node_sessionopen
node_browserws -->|"opens sessions"| node_sessionopen
node_sessionopen -->|"loads and records"| node_repo
node_sessionopen -->|"builds session"| node_runtime
node_runtime -->|"creates session"| node_voice
node_voice -.->|"processes turns"| node_audio
node_callee -->|"speaks"| node_voice
node_voice -->|"interprets text"| node_understanding
node_understanding -->|"parses utterance"| node_rules
node_understanding -.->|"requests interpretation"| node_cloudflare
node_understanding -->|"uses phase context"| node_turnctx
node_voice -->|"applies outcome"| node_controller
node_controller -->|"checks proposals"| node_policy
node_controller -->|"constrains actions"| node_turnctx
node_controller -->|"plans replies"| node_realizer
node_voice -->|"realizes response"| node_realizer
node_voice -.->|"streams speech"| node_cartesia
node_voice -.->|"sends call audio"| node_twilio
node_telephony -->|"controls calls"| node_twilio
node_audit -->|"records events"| node_repo
node_repo -->|"reads and writes"| node_database
node_api -->|"serves session data"| node_repo
node_auditui -.->|"views audit"| node_api
node_evaluation -->|"benchmarks NLU"| node_understanding
node_training -.->|"formats model data"| node_cloudflare

click node_console "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/frontend/app/telephony/page.tsx"
click node_proxy "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/frontend/app/api/operator/calls/route.ts"
click node_auditui "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/frontend/components/audit/SessionDetailView.tsx"
click node_api "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/api/routes.py"
click node_telephony "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/api/telephony.py"
click node_browserws "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/api/ws_browser.py"
click node_sessionopen "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/api/session_service.py"
click node_runtime "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/runtime.py"
click node_voice "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/voice/session.py"
click node_audio "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/voice/audio.py"
click node_controller "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/controller.py"
click node_policy "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/policy.py"
click node_turnctx "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/turn_context.py"
click node_understanding "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/understanding.py"
click node_rules "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/nlu_rules.py"
click node_realizer "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/realizer.py"
click node_providers "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/providers/base.py"
click node_cartesia "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/providers/cartesia.py"
click node_cloudflare "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/providers/cloudflare_llm.py"
click node_twilio "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/providers/twilio.py"
click node_repo "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/persistence/repository.py"
click node_database "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/persistence/tables.py"
click node_audit "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/audit.py"
click node_evaluation "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/evaluation/runner.py"
click node_training "https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/training/build_dataset.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_console,node_proxy,node_auditui toneBlue
class node_api,node_telephony,node_browserws,node_sessionopen,node_runtime,node_voice,node_audio toneAmber
class node_controller,node_policy,node_turnctx,node_understanding,node_rules,node_realizer toneMint
class node_providers,node_cartesia,node_cloudflare,node_repo,node_database,node_audit toneRose
class node_evaluation,node_training,node_operator,node_callee toneIndigo
class node_twilio toneTeal
```

## Components

### Operator console

- [Web console](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/frontend/app/telephony/page.tsx): `frontend/app/telephony/page.tsx`
- [Operator routes](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/frontend/app/api/operator/calls/route.ts): `frontend/app/api/operator/calls/route.ts`
- [Session audit UI](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/frontend/components/audit/SessionDetailView.tsx): `frontend/components/audit/SessionDetailView.tsx`

### Conversation runtime

- [REST routes](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`
- [Telephony webhooks](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/api/telephony.py): `backend/app/api/telephony.py`
- [Browser voice socket](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/api/ws_browser.py): `backend/app/api/ws_browser.py`
- [Session service](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/api/session_service.py): `backend/app/api/session_service.py`
- [Runtime assembly](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/runtime.py): `backend/app/runtime.py`
- [Voice session](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/voice/session.py): `backend/app/voice/session.py`
- [Audio and turns](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/voice/audio.py): `backend/app/voice/audio.py`

### Collections domain

- [Conversation controller](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/controller.py): `backend/app/domain/controller.py`
- [Policy rules](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/policy.py): `backend/app/domain/policy.py`
- [Phase action contract](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/turn_context.py): `backend/app/domain/turn_context.py`
- [Utterance understanding](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/understanding.py): `backend/app/domain/understanding.py`
- [Rules parser](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/nlu_rules.py): `backend/app/domain/nlu_rules.py`
- [Response realization](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/realizer.py): `backend/app/domain/realizer.py`

### Providers and persistence

- [Provider interfaces](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/providers/base.py): `backend/app/providers/base.py`
- [Cartesia speech](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/providers/cartesia.py): `backend/app/providers/cartesia.py`
- [Cloudflare LLM](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/providers/cloudflare_llm.py): `backend/app/providers/cloudflare_llm.py`
- [Repository](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/persistence/repository.py): `backend/app/persistence/repository.py`
- [PostgreSQL](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/persistence/tables.py): `backend/app/persistence/tables.py`
- [Audit and metrics](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/domain/audit.py): `backend/app/domain/audit.py`

### Evaluation and training

- [Evaluation suite](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/evaluation/runner.py): `backend/app/evaluation/runner.py`
- [NLU training data](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/training/build_dataset.py): `backend/app/training/build_dataset.py`

### Other components

- **Operator**
- **Caller**
- [Twilio PSTN](https://github.com/shelunagori/ai-voice-calling-collections-agent/blob/main/backend/app/providers/twilio.py): `backend/app/providers/twilio.py`

## Connections

- Operator → Web console: starts calls
- Web console → Operator routes: requests calls
- Web console → REST routes: uses backend
- REST routes → Session service: opens sessions (evidence: `backend/app/api/routes.py`)
- Telephony webhooks → Session service: opens calls
- Browser voice socket → Session service: opens sessions
- Session service → Repository: loads and records (evidence: `backend/app/api/session_service.py`)
- Session service → Runtime assembly: builds session (evidence: `backend/app/api/session_service.py`)
- Runtime assembly → Voice session: creates session (evidence: `backend/app/runtime.py`)
- Voice session → Audio and turns: processes turns
- Caller → Voice session: speaks
- Voice session → Utterance understanding: interprets text (evidence: `backend/app/voice/session.py`)
- Utterance understanding → Rules parser: parses utterance (evidence: `backend/app/domain/understanding.py`)
- Utterance understanding → Cloudflare LLM: requests interpretation
- Utterance understanding → Phase action contract: uses phase context (evidence: `backend/app/domain/understanding.py`)
- Voice session → Conversation controller: applies outcome (evidence: `backend/app/voice/session.py`)
- Conversation controller → Policy rules: checks proposals (evidence: `backend/app/domain/controller.py`)
- Conversation controller → Phase action contract: constrains actions (evidence: `backend/app/domain/controller.py`)
- Conversation controller → Response realization: plans replies (evidence: `backend/app/voice/session.py`)
- Voice session → Response realization: realizes response (evidence: `backend/app/voice/session.py`)
- Voice session → Cartesia speech: streams speech
- Voice session → Twilio PSTN: sends call audio
- Telephony webhooks → Twilio PSTN: controls calls
- Audit and metrics → Repository: records events (evidence: `backend/app/api/session_service.py`)
- Repository → PostgreSQL: reads and writes (evidence: `backend/app/persistence/repository.py`)
- REST routes → Repository: serves session data (evidence: `backend/app/api/routes.py`)
- Session audit UI → REST routes: views audit
- Evaluation suite → Utterance understanding: benchmarks NLU
- NLU training data → Cloudflare LLM: formats model data (evidence: `backend/app/providers/cloudflare_llm.py`)
