# harshkumar133/ai_voice_agent architecture

> Architecture diagram of the GitHub repository harshkumar133/ai_voice_agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harshkumar133/ai_voice_agent
- Repository: https://github.com/harshkumar133/ai_voice_agent

## Overview

RenewSure is a browser-based, knowledge-grounded insurance renewal voice-agent assessment with localized Philippines/Indonesia modes and a human-operator assist dashboard. The main workflow is a customer call: the browser captures audio, obtains an ephemeral provider token, streams to a realtime voice service, and handles its tool calls for market-aware KB answers and mock service actions. The dashboard also detects language, surfaces nudges, and exports call evidence. The README documents these capabilities; sampled source confirms the audio, retrieval, detection, token, and nudge responsibilities. Some UI wiring and export implementation were not sampled, so uncertain internal links are omitted.

Main entry points: [`src/app.js`](https://github.com/harshkumar133/ai_voice_agent/blob/main/src/app.js) (Call and dashboard), [`src/audio.js`](https://github.com/harshkumar133/ai_voice_agent/blob/main/src/audio.js) (Browser audio), [`src/retrieval.js`](https://github.com/harshkumar133/ai_voice_agent/blob/main/src/retrieval.js) (Search and citations), [`api/gemini-token.js`](https://github.com/harshkumar133/ai_voice_agent/blob/main/api/gemini-token.js) (Gemini token route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_conversation["Voice conversation"]
  node_browser_app["Call and dashboard<br/>[app.js]"]
  node_audio_engine["Browser audio<br/>[audio.js]"]
  node_gemini_service["Gemini Live"]
  node_xai_service["xAI realtime"]
  node_scenario_data["Call scenarios<br/>[scenarios.json]"]
end

subgraph group_grounding["Knowledge and localization"]
  node_kb_records["Curated KB<br/>[kb-records.json]"]
  node_retrieval["Search and citations<br/>[retrieval.js]"]
  node_language_market["Language detection<br/>[language-market.js]"]
end

subgraph group_operations["Operator and operations"]
  node_lead_operations["Lead and mock actions<br/>[app.js]"]
  node_nudge_dashboard["Nudges and metrics<br/>[app.js]"]
  node_evidence_export["Call evidence export<br/>[app.js]"]
end

subgraph group_provider_access["Provider access"]
  node_health_route["Provider health<br/>[health.js]"]
  node_gemini_route["Gemini token route<br/>[gemini-token.js]"]
  node_gemini_token_core["Gemini token creation"]
  node_xai_route["xAI token route<br/>[xai-token.js]"]
  node_xai_token_core["xAI token creation"]
end

node_customer(("Customer"))
node_google_token_api["Google token API"]
node_xai_token_api["xAI token API"]

node_customer -->|"starts call"| node_browser_app
node_browser_app -->|"loads scenarios"| node_scenario_data
node_browser_app -->|"starts capture"| node_audio_engine
node_audio_engine -->|"sends PCM chunks"| node_browser_app
node_browser_app -->|"requests token"| node_gemini_route
node_browser_app -.->|"requests fallback token"| node_xai_route
node_gemini_route -->|"creates token"| node_gemini_token_core
node_gemini_token_core -->|"requests ephemeral token"| node_google_token_api
node_xai_route -->|"creates token"| node_xai_token_core
node_xai_token_core -->|"requests client secret"| node_xai_token_api
node_browser_app -->|"streams audio and tools"| node_gemini_service
node_browser_app -.->|"streams fallback audio"| node_xai_service
node_gemini_service -->|"returns voice and tool calls"| node_browser_app
node_xai_service -.->|"returns voice and tool calls"| node_browser_app
node_browser_app -->|"loads records"| node_kb_records
node_browser_app -->|"searches and evaluates"| node_retrieval
node_retrieval -->|"reads records"| node_kb_records
node_browser_app -->|"detects customer language"| node_language_market
node_browser_app -->|"logs mock actions"| node_lead_operations
node_browser_app -->|"records nudges and latency"| node_nudge_dashboard
node_browser_app -->|"assembles call evidence"| node_evidence_export
node_browser_app -->|"checks readiness"| node_health_route

click node_browser_app "https://github.com/harshkumar133/ai_voice_agent/blob/main/src/app.js"
click node_audio_engine "https://github.com/harshkumar133/ai_voice_agent/blob/main/src/audio.js"
click node_kb_records "https://github.com/harshkumar133/ai_voice_agent/blob/main/data/kb-records.json"
click node_retrieval "https://github.com/harshkumar133/ai_voice_agent/blob/main/src/retrieval.js"
click node_language_market "https://github.com/harshkumar133/ai_voice_agent/blob/main/src/language-market.js"
click node_scenario_data "https://github.com/harshkumar133/ai_voice_agent/blob/main/data/scenarios.json"
click node_lead_operations "https://github.com/harshkumar133/ai_voice_agent/blob/main/src/app.js"
click node_nudge_dashboard "https://github.com/harshkumar133/ai_voice_agent/blob/main/src/app.js"
click node_evidence_export "https://github.com/harshkumar133/ai_voice_agent/blob/main/src/app.js"
click node_health_route "https://github.com/harshkumar133/ai_voice_agent/blob/main/api/health.js"
click node_gemini_route "https://github.com/harshkumar133/ai_voice_agent/blob/main/api/gemini-token.js"
click node_gemini_token_core "https://github.com/harshkumar133/ai_voice_agent/blob/main/api/_gemini-token-core.mjs"
click node_xai_route "https://github.com/harshkumar133/ai_voice_agent/blob/main/api/xai-token.js"
click node_xai_token_core "https://github.com/harshkumar133/ai_voice_agent/blob/main/api/_xai-token-core.mjs"

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_browser_app,node_audio_engine,node_gemini_service,node_xai_service,node_scenario_data toneBlue
class node_kb_records,node_retrieval,node_language_market toneAmber
class node_lead_operations,node_nudge_dashboard,node_evidence_export,node_google_token_api,node_xai_token_api toneMint
class node_health_route,node_gemini_route,node_gemini_token_core,node_xai_route,node_xai_token_core toneRose
class node_customer toneIndigo
```

## Components

### Voice conversation

- [Call and dashboard](https://github.com/harshkumar133/ai_voice_agent/blob/main/src/app.js): `src/app.js`
- [Browser audio](https://github.com/harshkumar133/ai_voice_agent/blob/main/src/audio.js): `src/audio.js`
- **Gemini Live**
- **xAI realtime**
- [Call scenarios](https://github.com/harshkumar133/ai_voice_agent/blob/main/data/scenarios.json): `data/scenarios.json`

### Knowledge and localization

- [Curated KB](https://github.com/harshkumar133/ai_voice_agent/blob/main/data/kb-records.json): `data/kb-records.json`
- [Search and citations](https://github.com/harshkumar133/ai_voice_agent/blob/main/src/retrieval.js): `src/retrieval.js`
- [Language detection](https://github.com/harshkumar133/ai_voice_agent/blob/main/src/language-market.js): `src/language-market.js`

### Operator and operations

- [Lead and mock actions](https://github.com/harshkumar133/ai_voice_agent/blob/main/src/app.js): `src/app.js`
- [Nudges and metrics](https://github.com/harshkumar133/ai_voice_agent/blob/main/src/app.js): `src/app.js`
- [Call evidence export](https://github.com/harshkumar133/ai_voice_agent/blob/main/src/app.js): `src/app.js`

### Provider access

- [Provider health](https://github.com/harshkumar133/ai_voice_agent/blob/main/api/health.js): `api/health.js`
- [Gemini token route](https://github.com/harshkumar133/ai_voice_agent/blob/main/api/gemini-token.js): `api/gemini-token.js`
- [Gemini token creation](https://github.com/harshkumar133/ai_voice_agent/blob/main/api/_gemini-token-core.mjs): `api/_gemini-token-core.mjs`
- [xAI token route](https://github.com/harshkumar133/ai_voice_agent/blob/main/api/xai-token.js): `api/xai-token.js`
- [xAI token creation](https://github.com/harshkumar133/ai_voice_agent/blob/main/api/_xai-token-core.mjs): `api/_xai-token-core.mjs`

### Other components

- **Customer**
- **Google token API**
- **xAI token API**

## Connections

- Customer → Call and dashboard: starts call
- Call and dashboard → Call scenarios: loads scenarios
- Call and dashboard → Browser audio: starts capture
- Browser audio → Call and dashboard: sends PCM chunks
- Call and dashboard → Gemini token route: requests token
- Call and dashboard → xAI token route: requests fallback token
- Gemini token route → Gemini token creation: creates token
- Gemini token creation → Google token API: requests ephemeral token
- xAI token route → xAI token creation: creates token
- xAI token creation → xAI token API: requests client secret
- Call and dashboard → Gemini Live: streams audio and tools
- Call and dashboard → xAI realtime: streams fallback audio
- Gemini Live → Call and dashboard: returns voice and tool calls
- xAI realtime → Call and dashboard: returns voice and tool calls
- Call and dashboard → Curated KB: loads records
- Call and dashboard → Search and citations: searches and evaluates
- Search and citations → Curated KB: reads records
- Call and dashboard → Language detection: detects customer language
- Call and dashboard → Lead and mock actions: logs mock actions
- Call and dashboard → Nudges and metrics: records nudges and latency
- Call and dashboard → Call evidence export: assembles call evidence
- Call and dashboard → Provider health: checks readiness
