# lokeyadav/maya---collections-ai-voice-agent architecture

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

- Interactive diagram: https://gitdiagram.com/lokeyadav/maya---collections-ai-voice-agent
- Repository: https://github.com/lokeyadav/maya---collections-ai-voice-agent

## Overview

#### Purpose and Entry Points
This repository defines “Maya,” an outbound collections voice agent for Kapture Finance. The runtime starts in Vapi.ai: configure the assistant with `vapi/system_prompt.txt`, register tools from `vapi/tool_definitions.json`, and direct tool webhooks to the Express service in `mock-server/server.js` (`/webhook`, port 3000).

#### Voice-Orchestration Layer
Vapi coordinates telephony/WebRTC, turn-taking, tool calls, and audio delivery. Its provider pipeline is Deepgram Nova-2 for multilingual STT, OpenAI GPT-4o for dialogue reasoning, and ElevenLabs or Cartesia for TTS. This layer is externally configured rather than implemented in code; repository artifacts define its behavior:
- `vapi/system_prompt.txt`
- `vapi/tool_definitions.json`

#### Compliance-Governed Conversation State
The system prompt is the primary control plane. It requires identity authentication before disclosure of debt details, supports English by default with conditional Hindi/Hinglish responses, and governs disposition, payment, dispute, hardship, and opt-out behavior. The critical boundary is pre-verification: no loan/EMI/overdue information may be spoken until `verify_customer` succeeds.
- `vapi/system_prompt.txt`
- `vapi/tool_definitions.json`

#### Tool Contract and Backend Boundary
Five Vapi function schemas form the contract between LLM orchestration and backend actions: verification, promise-to-pay logging, payment-link sending, human escalation, and call disposition. Vapi invokes the public webhook; the backend must tolerate Vapi’s request envelope and return tool results.
- `vapi/tool_definitions.json`
- `mock-server/server.js`

#### Webhook Execution and Messaging Simulation
The Node.js/Express server is the only application runtime in the repo. It exposes both `/webhook` and `/`, applies an ngrok warning-bypass header, routes tool calls, and simulates CRM/workflow outcomes through logging. `send_payment_link` additionally calls a mock SMS/WhatsApp gateway with a fixed recipient and payment deep link, returning a delivery-style success response.
- `mock-server/server.js`
- `mock-server/package.json`
- `mock-server/.env.example`

#### Deployment and External Infrastructure
Local deployment runs Express on port 3000; ngrok, Render, or LocalTunnel exposes it to Vapi over HTTPS. Required external services are Vapi.ai, Deepgram, OpenAI, ElevenLabs/Cartesia, and a production replacement for the mock messaging/CRM integrations. Environment variables are intended to be supplied outside source control.
- `mock-server/server.js`
- `mock-server/.env.example`

#### Validation and Design Reference
The acceptance model centers on identity gating, compliant dispositions, PTP extraction, escalation, DNC behavior, and bilingual parsing. The test matrix encodes representative end-to-end paths, while the high-level design documents production expectations such as transcript compliance checks, LLM-based evaluation, and latency monitoring.
- `tests/test_cases.json`
- `docs/HLD_Document.md`

Main entry points: [`mock-server/server.js`](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js) (Vapi Webhook Adapter), [`vapi/system_prompt.txt`](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/vapi/system_prompt.txt) (Maya System Prompt), [`vapi/tool_definitions.json`](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/vapi/tool_definitions.json) (Tool Definitions), [`mock-server/.env.example`](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/.env.example) (Environment Variables)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vapi["Vapi Voice Orchestration"]
  node_vapi_platform{{"Vapi.ai<br/>voice orchestrator"}}
  node_system_prompt["Maya System Prompt<br/>conversation policy<br/>[system_prompt.txt]"]
  node_tool_contract["Tool Definitions<br/>function schemas"]
  node_speech_stack["STT / LLM / TTS<br/>AI providers"]
end

subgraph group_backend["Webhook Runtime"]
  node_express_server["Express Server<br/>Node.js runtime<br/>[server.js]"]
  node_webhook_adapter["Vapi Webhook Adapter<br/>request handler<br/>[server.js]"]
  node_tool_router["Tool Call Router<br/>action dispatcher<br/>[server.js]"]
  node_mock_crm["CRM / Workflow Simulation<br/>mock integration<br/>[server.js]"]
  node_messaging_gateway["Mock SMS / WhatsApp Gateway<br/>messaging integration<br/>[server.js]"]
  node_environment["Environment Variables<br/>deployment configuration<br/>[.env.example]"]
  node_package_runtime["Server Dependencies<br/>Node package manifest<br/>[package.json]"]
end

subgraph group_validation["Validation &amp; Design"]
  node_test_matrix["Acceptance Test Matrix<br/>end-to-end cases<br/>[test_cases.json]"]
  node_hld["High-Level Design<br/>production design<br/>[HLD_Document.md]"]
end

node_caller(("Borrower<br/>call participant"))
node_public_tunnel["HTTPS Tunnel or Hosting<br/>public endpoint"]
node_production_integrations["Production CRM &amp; Messaging<br/>external integrations"]

node_caller -->|"voice call"| node_vapi_platform
node_system_prompt -->|"controls dialogue"| node_vapi_platform
node_tool_contract -->|"registers tools"| node_vapi_platform
node_speech_stack -->|"speech and reasoning"| node_vapi_platform
node_vapi_platform -->|"tool webhook"| node_public_tunnel
node_public_tunnel -->|"HTTPS to port 3000"| node_express_server
node_express_server -->|"/webhook"| node_webhook_adapter
node_webhook_adapter -->|"parsed tool call"| node_tool_router
node_tool_router -->|"verify, PTP, escalate, dispose"| node_mock_crm
node_tool_router -->|"send_payment_link"| node_messaging_gateway
node_mock_crm -->|"tool result"| node_webhook_adapter
node_messaging_gateway -->|"delivery result"| node_webhook_adapter
node_webhook_adapter -->|"tool response"| node_vapi_platform
node_environment -.->|"runtime settings"| node_express_server
node_package_runtime -.->|"dependencies"| node_express_server
node_mock_crm -.->|"production replacement"| node_production_integrations
node_messaging_gateway -.->|"production replacement"| node_production_integrations
node_test_matrix -.->|"validates policy paths"| node_system_prompt
node_hld -.->|"production expectations"| node_vapi_platform

click node_system_prompt "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/vapi/system_prompt.txt"
click node_tool_contract "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/vapi/tool_definitions.json"
click node_express_server "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js"
click node_webhook_adapter "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js"
click node_tool_router "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js"
click node_mock_crm "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js"
click node_messaging_gateway "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js"
click node_environment "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/.env.example"
click node_package_runtime "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/package.json"
click node_test_matrix "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/tests/test_cases.json"
click node_hld "https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/docs/HLD_Document.md"

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_vapi_platform,node_system_prompt,node_tool_contract,node_speech_stack toneBlue
class node_express_server,node_webhook_adapter,node_tool_router,node_mock_crm,node_messaging_gateway,node_environment,node_package_runtime toneAmber
class node_test_matrix,node_hld toneMint
class node_caller,node_public_tunnel,node_production_integrations toneNeutral
```

## Components

### Vapi Voice Orchestration

- **Vapi.ai**: voice orchestrator · Coordinates calls, turns, tools, and audio.
- [Maya System Prompt](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/vapi/system_prompt.txt): conversation policy · Enforces verification before debt disclosure and compliant call handling. · `vapi/system_prompt.txt`
- [Tool Definitions](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/vapi/tool_definitions.json): function schemas · Defines verification, PTP, payment, escalation, and disposition tools. · `vapi/tool_definitions.json`
- **STT / LLM / TTS**: AI providers · Deepgram, GPT-4o, and ElevenLabs or Cartesia provide the voice pipeline.

### Webhook Runtime

- [Express Server](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js): Node.js runtime · Runs on port 3000 and exposes root plus webhook endpoints. · `mock-server/server.js`
- [Vapi Webhook Adapter](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js): request handler · Accepts Vapi envelopes and returns tool results. · `mock-server/server.js`
- [Tool Call Router](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js): action dispatcher · Routes the five function calls to simulated backend actions. · `mock-server/server.js`
- [CRM / Workflow Simulation](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js): mock integration · Logs verification, PTP, escalation, and disposition outcomes. · `mock-server/server.js`
- [Mock SMS / WhatsApp Gateway](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/server.js): messaging integration · Sends the fixed-recipient payment deep link simulation. · `mock-server/server.js`
- [Environment Variables](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/.env.example): deployment configuration · Externalizes runtime and integration settings. · `mock-server/.env.example`
- [Server Dependencies](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/mock-server/package.json): Node package manifest · `mock-server/package.json`

### Validation & Design

- [Acceptance Test Matrix](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/tests/test_cases.json): end-to-end cases · Covers identity gating, PTP, escalation, DNC, and bilingual paths. · `tests/test_cases.json`
- [High-Level Design](https://github.com/lokeyadav/maya---collections-ai-voice-agent/blob/main/docs/HLD_Document.md): production design · Defines compliance evaluation and latency-monitoring expectations. · `docs/HLD_Document.md`

### Other components

- **Borrower**: call participant
- **HTTPS Tunnel or Hosting**: public endpoint · ngrok, Render, or LocalTunnel exposes the local webhook.
- **Production CRM & Messaging**: external integrations · Replaces simulated CRM and messaging behavior in production.

## Connections

- Borrower → Vapi.ai: voice call
- Maya System Prompt → Vapi.ai: controls dialogue
- Tool Definitions → Vapi.ai: registers tools
- STT / LLM / TTS → Vapi.ai: speech and reasoning
- Vapi.ai → HTTPS Tunnel or Hosting: tool webhook
- HTTPS Tunnel or Hosting → Express Server: HTTPS to port 3000
- Express Server → Vapi Webhook Adapter: /webhook
- Vapi Webhook Adapter → Tool Call Router: parsed tool call
- Tool Call Router → CRM / Workflow Simulation: verify, PTP, escalate, dispose
- Tool Call Router → Mock SMS / WhatsApp Gateway: send_payment_link
- CRM / Workflow Simulation → Vapi Webhook Adapter: tool result
- Mock SMS / WhatsApp Gateway → Vapi Webhook Adapter: delivery result
- Vapi Webhook Adapter → Vapi.ai: tool response
- Environment Variables → Express Server: runtime settings
- Server Dependencies → Express Server: dependencies
- CRM / Workflow Simulation → Production CRM & Messaging: production replacement
- Mock SMS / WhatsApp Gateway → Production CRM & Messaging: production replacement
- Acceptance Test Matrix → Maya System Prompt: validates policy paths
- High-Level Design → Vapi.ai: production expectations
