# genzpreparation/nexoagent architecture

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

- Interactive diagram: https://gitdiagram.com/genzpreparation/nexoagent
- Repository: https://github.com/genzpreparation/nexoagent

## Overview

NexoAgent is a multi-tenant voice-AI telecalling SaaS: workspace users or lead platforms initiate calls, campaigns, or account actions through a FastAPI API; calls are placed through telephony, recorded in a call ledger, and billed against prepaid wallet balances. The voice worker handles live conversations and WhatsApp actions; post-call intelligence and secure recordings support review. The README documents voice, compliance, and SaaS capabilities not all visible in the sampled excerpts, so those links are marked as documented or unverified rather than implying inspected implementation. Evidence is limited to the README, SOURCE INDEX, and excerpts provided.

Main entry points: [`backend/app/main.py`](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/main.py) (FastAPI application), [`backend/app/api/v1/calls.py`](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/calls.py) (Call dispatch and ledger), [`backend/app/api/v1/webhooks.py`](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/webhooks.py) (Telephony and lead webhooks), [`backend/app/services/wallet.py`](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/wallet.py) (Prepaid wallet)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and tenancy"]
  node_fastapi["FastAPI application<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_tenant_security["Tenant access<br/>[deps.py]"]
  node_security["JWT security<br/>[security.py]"]
  node_workspace["Workspace API<br/>[workspace.py]"]
  node_agents["Voice agent API<br/>[agents.py]"]
  node_api_keys["API key management<br/>[api_keys.py]"]
  node_integrations["Integrations API<br/>[integrations.py]"]
end

subgraph group_calling["Calling operations"]
  node_campaign_api["Campaign API<br/>[campaigns.py]"]
  node_campaign_engine["Campaign dispatcher<br/>[campaign.py]"]
  node_calls_api["Call dispatch and ledger<br/>[calls.py]"]
  node_telephony["Telephony service<br/>[telephony.py]"]
  node_webhooks["Telephony and lead webhooks<br/>[webhooks.py]"]
end

subgraph group_voice["Voice experience"]
  node_voice_worker["Live voice worker<br/>[agent.py]"]
  node_voice_tools["Conversation tools<br/>[tools.py]"]
  node_whatsapp_api["WhatsApp API<br/>[whatsapp.py]"]
  node_whatsapp_service["WhatsApp dispatch<br/>[whatsapp.py]"]
  node_intelligence["Call intelligence<br/>[intelligence.py]"]
end

subgraph group_finance["Billing and records"]
  node_wallet["Prepaid wallet<br/>[wallet.py]"]
  node_billing["Billing API<br/>[billing.py]"]
  node_payments["Razorpay integration"]
  node_recordings["Recording storage<br/>[storage.py]"]
  node_database[("Async database<br/>[database.py]")]
  node_platform_data["Platform records<br/>[call.py]"]
end

node_user(("Workspace user"))
node_lead_platform(("Lead platform"))
node_telecom{{"Telephony carrier"}}
node_voice_services{{"Voice AI providers"}}
node_whatsapp_provider{{"WhatsApp provider"}}
node_object_store[("S3 or R2")]
node_razorpay{{"Razorpay"}}

node_user -->|"uses API"| node_fastapi
node_lead_platform -->|"submits leads"| node_webhooks
node_fastapi -->|"registers routes"| node_auth
node_fastapi -->|"registers routes"| node_calls_api
node_fastapi -->|"registers routes"| node_campaign_api
node_fastapi -->|"registers routes"| node_webhooks
node_fastapi -->|"registers routes"| node_whatsapp_api
node_fastapi -->|"registers routes"| node_billing
node_fastapi -->|"registers routes"| node_agents
node_fastapi -->|"registers routes"| node_workspace
node_fastapi -->|"registers routes"| node_api_keys
node_fastapi -->|"registers routes"| node_integrations
node_auth -->|"hashes and signs"| node_security
node_auth -->|"reads and writes"| node_database
node_tenant_security -->|"decodes JWT"| node_security
node_tenant_security -->|"resolves tenant"| node_database
node_calls_api -->|"checks balance"| node_wallet
node_calls_api -->|"places call"| node_telephony
node_calls_api -->|"analyzes transcript"| node_intelligence
node_calls_api -->|"requests stream URL"| node_recordings
node_calls_api -->|"reads and writes"| node_database
node_campaign_api -->|"dispatches campaign"| node_campaign_engine
node_campaign_engine -->|"places calls"| node_telephony
node_campaign_api -->|"checks balance"| node_wallet
node_webhooks -->|"dials lead"| node_telephony
node_webhooks -->|"uses campaign logic"| node_campaign_engine
node_webhooks -->|"deducts usage"| node_wallet
node_webhooks -->|"persists call"| node_database
node_telecom -->|"sends call events"| node_webhooks
node_telephony -.->|"initiates calls"| node_telecom
node_voice_worker -->|"invokes tools"| node_voice_tools
node_voice_tools -->|"dispatches messages"| node_whatsapp_service
node_whatsapp_api -->|"sends messages"| node_whatsapp_service
node_whatsapp_service -.->|"sends WhatsApp"| node_whatsapp_provider
node_voice_worker -.->|"runs voice pipeline"| node_voice_services
node_billing -->|"credits wallet"| node_wallet
node_billing -->|"creates payments"| node_payments
node_payments -.->|"processes payments"| node_razorpay
node_wallet -->|"updates balances"| node_database
node_recordings -->|"signs object URLs"| node_object_store
node_calls_api -->|"reads call records"| node_platform_data

click node_fastapi "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/main.py"
click node_auth "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/auth.py"
click node_tenant_security "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/core/deps.py"
click node_security "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/core/security.py"
click node_workspace "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/workspace.py"
click node_agents "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/agents.py"
click node_api_keys "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/api_keys.py"
click node_integrations "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/integrations.py"
click node_campaign_api "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/campaigns.py"
click node_campaign_engine "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/campaign.py"
click node_calls_api "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/calls.py"
click node_telephony "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/telephony.py"
click node_webhooks "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/webhooks.py"
click node_voice_worker "https://github.com/genzpreparation/nexoagent/blob/main/backend/voice_agent/agent.py"
click node_voice_tools "https://github.com/genzpreparation/nexoagent/blob/main/backend/voice_agent/tools.py"
click node_whatsapp_api "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/whatsapp.py"
click node_whatsapp_service "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/whatsapp.py"
click node_intelligence "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/intelligence.py"
click node_wallet "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/wallet.py"
click node_billing "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/billing.py"
click node_payments "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/razorpay_service.py"
click node_recordings "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/storage.py"
click node_database "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/core/database.py"
click node_platform_data "https://github.com/genzpreparation/nexoagent/blob/main/backend/app/models/call.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_fastapi,node_auth,node_tenant_security,node_security,node_workspace,node_agents,node_api_keys,node_integrations,node_user toneBlue
class node_campaign_api,node_campaign_engine,node_calls_api,node_telephony,node_webhooks,node_object_store toneAmber
class node_voice_worker,node_voice_tools,node_whatsapp_api,node_whatsapp_service,node_intelligence toneMint
class node_wallet,node_billing,node_payments,node_recordings,node_database,node_platform_data toneRose
class node_lead_platform,node_telecom,node_voice_services,node_whatsapp_provider,node_razorpay toneIndigo
```

## Components

### API and tenancy

- [FastAPI application](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/auth.py): `backend/app/api/v1/auth.py`
- [Tenant access](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/core/deps.py): `backend/app/core/deps.py`
- [JWT security](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/core/security.py): `backend/app/core/security.py`
- [Workspace API](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/workspace.py): `backend/app/api/v1/workspace.py`
- [Voice agent API](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/agents.py): `backend/app/api/v1/agents.py`
- [API key management](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/api_keys.py): `backend/app/api/v1/api_keys.py`
- [Integrations API](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/integrations.py): `backend/app/api/v1/integrations.py`

### Calling operations

- [Campaign API](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/campaigns.py): `backend/app/api/v1/campaigns.py`
- [Campaign dispatcher](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/campaign.py): `backend/app/services/campaign.py`
- [Call dispatch and ledger](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/calls.py): `backend/app/api/v1/calls.py`
- [Telephony service](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/telephony.py): `backend/app/services/telephony.py`
- [Telephony and lead webhooks](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/webhooks.py): `backend/app/api/v1/webhooks.py`

### Voice experience

- [Live voice worker](https://github.com/genzpreparation/nexoagent/blob/main/backend/voice_agent/agent.py): `backend/voice_agent/agent.py`
- [Conversation tools](https://github.com/genzpreparation/nexoagent/blob/main/backend/voice_agent/tools.py): `backend/voice_agent/tools.py`
- [WhatsApp API](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/whatsapp.py): `backend/app/api/v1/whatsapp.py`
- [WhatsApp dispatch](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/whatsapp.py): `backend/app/services/whatsapp.py`
- [Call intelligence](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/intelligence.py): `backend/app/services/intelligence.py`

### Billing and records

- [Prepaid wallet](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/wallet.py): `backend/app/services/wallet.py`
- [Billing API](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/api/v1/billing.py): `backend/app/api/v1/billing.py`
- [Razorpay integration](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/razorpay_service.py): `backend/app/services/razorpay_service.py`
- [Recording storage](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/services/storage.py): `backend/app/services/storage.py`
- [Async database](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/core/database.py): `backend/app/core/database.py`
- [Platform records](https://github.com/genzpreparation/nexoagent/blob/main/backend/app/models/call.py): `backend/app/models/call.py`

### Other components

- **Workspace user**
- **Lead platform**
- **Telephony carrier**
- **Voice AI providers**
- **WhatsApp provider**
- **S3 or R2**
- **Razorpay**

## Connections

- Workspace user → FastAPI application: uses API (evidence: `backend/app/main.py`)
- Lead platform → Telephony and lead webhooks: submits leads (evidence: `backend/app/api/v1/webhooks.py`)
- FastAPI application → Authentication: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Call dispatch and ledger: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Campaign API: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Telephony and lead webhooks: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → WhatsApp API: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Billing API: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Voice agent API: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Workspace API: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → API key management: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Integrations API: registers routes (evidence: `backend/app/main.py`)
- Authentication → JWT security: hashes and signs (evidence: `backend/app/api/v1/auth.py`)
- Authentication → Async database: reads and writes (evidence: `backend/app/api/v1/auth.py`)
- Tenant access → JWT security: decodes JWT (evidence: `backend/app/core/deps.py`)
- Tenant access → Async database: resolves tenant (evidence: `backend/app/core/deps.py`)
- Call dispatch and ledger → Prepaid wallet: checks balance (evidence: `backend/app/api/v1/calls.py`)
- Call dispatch and ledger → Telephony service: places call (evidence: `backend/app/api/v1/calls.py`)
- Call dispatch and ledger → Call intelligence: analyzes transcript (evidence: `backend/app/api/v1/calls.py`)
- Call dispatch and ledger → Recording storage: requests stream URL (evidence: `backend/app/api/v1/calls.py`)
- Call dispatch and ledger → Async database: reads and writes (evidence: `backend/app/api/v1/calls.py`)
- Campaign API → Campaign dispatcher: dispatches campaign (evidence: `backend/app/api/v1/campaigns.py`)
- Campaign dispatcher → Telephony service: places calls (evidence: `backend/app/services/campaign.py`)
- Campaign API → Prepaid wallet: checks balance (evidence: `backend/app/api/v1/campaigns.py`)
- Telephony and lead webhooks → Telephony service: dials lead (evidence: `backend/app/api/v1/webhooks.py`)
- Telephony and lead webhooks → Campaign dispatcher: uses campaign logic (evidence: `backend/app/api/v1/webhooks.py`)
- Telephony and lead webhooks → Prepaid wallet: deducts usage (evidence: `backend/app/api/v1/webhooks.py`)
- Telephony and lead webhooks → Async database: persists call (evidence: `backend/app/api/v1/webhooks.py`)
- Telephony carrier → Telephony and lead webhooks: sends call events (evidence: `backend/app/api/v1/webhooks.py`)
- Telephony service → Telephony carrier: initiates calls
- Live voice worker → Conversation tools: invokes tools (evidence: `backend/voice_agent/agent.py`)
- Conversation tools → WhatsApp dispatch: dispatches messages (evidence: `backend/voice_agent/tools.py`)
- WhatsApp API → WhatsApp dispatch: sends messages (evidence: `backend/app/api/v1/whatsapp.py`)
- WhatsApp dispatch → WhatsApp provider: sends WhatsApp
- Live voice worker → Voice AI providers: runs voice pipeline
- Billing API → Prepaid wallet: credits wallet (evidence: `backend/app/api/v1/billing.py`)
- Billing API → Razorpay integration: creates payments (evidence: `backend/app/api/v1/billing.py`)
- Razorpay integration → Razorpay: processes payments
- Prepaid wallet → Async database: updates balances (evidence: `backend/app/services/wallet.py`)
- Recording storage → S3 or R2: signs object URLs (evidence: `backend/app/services/storage.py`)
- Call dispatch and ledger → Platform records: reads call records (evidence: `backend/app/api/v1/calls.py`)
