# yar-malik/saudi-retail-voice-agent architecture

> Architecture diagram of the GitHub repository yar-malik/saudi-retail-voice-agent, 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/yar-malik/saudi-retail-voice-agent
- Repository: https://github.com/yar-malik/saudi-retail-voice-agent

## Overview

This is a self-hostable Saudi retail voice-agent example, with scripted order, return, and win-back conversations plus recorded reference scenarios. The phone workflow starts at Twilio’s webhook: the server creates an agent, returns spoken turns, receives speech results, and serves synthesized audio clips. The internal engine selects and advances a flow, invoking registered tools or replaying recorded results. README capabilities include direct Node and Python speech examples and configurable speech recognition; their implementation details were not sampled, so those links are documented rather than inferred from source.

Main entry points: [`server.py`](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/server.py) (Phone webhook), [`flows.json`](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json) (Flow scenarios), [`agent.py`](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/agent.py) (Conversation engine), [`tools.py`](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/tools.py) (Tool registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Conversation runtime"]
  node_server["Phone webhook<br/>[server.py]"]
  node_agent["Conversation engine<br/>[agent.py]"]
  node_tools["Tool registry<br/>[tools.py]"]
end

subgraph group_voice["Speech services"]
  node_stt["Speech recognition<br/>[stt.py]"]
  node_voho["Speech client<br/>[voho.py]"]
end

subgraph group_scenarios["Retail scenarios"]
  node_flows["Flow scenarios<br/>[flows.json]"]
  node_order["Order status<br/>[flows.json]"]
  node_returns["Returns exchange<br/>[flows.json]"]
  node_winback["Cart win-back<br/>[flows.json]"]
  node_reference_scenarios["Reference workflows<br/>[flows.json]"]
end

subgraph group_examples["Direct examples"]
  node_node_example["Node speech example<br/>[index.mjs]"]
  node_python_example["Python speech example<br/>[main.py]"]
end

node_caller(("Caller"))
node_twilio{{"Twilio"}}
node_voho_api{{"Voho Speech API"}}
node_openai{{"OpenAI Whisper"}}
node_custom_stt{{"Custom recognizer"}}
node_retail_systems{{"Retail systems"}}

node_caller -->|"calls"| node_twilio
node_twilio -->|"posts speech"| node_server
node_server -->|"starts and replies"| node_agent
node_server -->|"lists stubs"| node_tools
node_server -->|"synthesizes clips"| node_voho
node_agent -->|"loads scenarios"| node_flows
node_agent -->|"runs tools"| node_tools
node_server -->|"returns TwiML"| node_twilio
node_twilio -->|"posts transcript"| node_server
node_server -->|"serves audio"| node_caller
node_voho -->|"requests speech"| node_voho_api
node_stt -->|"transcribes audio"| node_openai
node_stt -->|"sends audio"| node_custom_stt
node_node_example -->|"requests speech"| node_voho_api
node_python_example -->|"requests speech"| node_voho_api
node_tools -.->|"integrates systems"| node_retail_systems
node_flows -->|"defines"| node_order
node_flows -->|"defines"| node_returns
node_flows -->|"defines"| node_winback
node_flows -->|"records"| node_reference_scenarios

click node_server "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/server.py"
click node_agent "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/agent.py"
click node_tools "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/tools.py"
click node_flows "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json"
click node_stt "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/stt.py"
click node_voho "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/voho.py"
click node_node_example "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/examples/node/index.mjs"
click node_python_example "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/examples/python/main.py"
click node_order "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json"
click node_returns "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json"
click node_winback "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json"
click node_reference_scenarios "https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json"

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_server,node_agent,node_tools toneBlue
class node_stt,node_voho toneAmber
class node_flows,node_order,node_returns,node_winback,node_reference_scenarios,node_voho_api toneMint
class node_node_example,node_python_example toneRose
class node_caller,node_twilio,node_openai,node_custom_stt,node_retail_systems toneIndigo
```

## Components

### Conversation runtime

- [Phone webhook](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/server.py): `server.py`
- [Conversation engine](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/agent.py): `agent.py`
- [Tool registry](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/tools.py): `tools.py`

### Speech services

- [Speech recognition](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/stt.py): `stt.py`
- [Speech client](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/voho.py): `voho.py`

### Retail scenarios

- [Flow scenarios](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json): `flows.json`
- [Order status](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json): `flows.json`
- [Returns exchange](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json): `flows.json`
- [Cart win-back](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json): `flows.json`
- [Reference workflows](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/flows.json): `flows.json`

### Direct examples

- [Node speech example](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/examples/node/index.mjs): `examples/node/index.mjs`
- [Python speech example](https://github.com/yar-malik/saudi-retail-voice-agent/blob/main/examples/python/main.py): `examples/python/main.py`

### Other components

- **Caller**
- **Twilio**
- **Voho Speech API**
- **OpenAI Whisper**
- **Custom recognizer**
- **Retail systems**

## Connections

- Caller → Twilio: calls (evidence: `README.md`)
- Twilio → Phone webhook: posts speech (evidence: `README.md`)
- Phone webhook → Conversation engine: starts and replies (evidence: `server.py`)
- Phone webhook → Tool registry: lists stubs (evidence: `server.py`)
- Phone webhook → Speech client: synthesizes clips (evidence: `server.py`)
- Conversation engine → Flow scenarios: loads scenarios (evidence: `agent.py`)
- Conversation engine → Tool registry: runs tools (evidence: `agent.py`)
- Phone webhook → Twilio: returns TwiML (evidence: `README.md`)
- Twilio → Phone webhook: posts transcript (evidence: `README.md`)
- Phone webhook → Caller: serves audio (evidence: `server.py`)
- Speech client → Voho Speech API: requests speech (evidence: `voho.py`)
- Speech recognition → OpenAI Whisper: transcribes audio (evidence: `stt.py`)
- Speech recognition → Custom recognizer: sends audio (evidence: `stt.py`)
- Node speech example → Voho Speech API: requests speech (evidence: `README.md`)
- Python speech example → Voho Speech API: requests speech (evidence: `README.md`)
- Tool registry → Retail systems: integrates systems (evidence: `README.md`)
- Flow scenarios → Order status: defines (evidence: `README.md`)
- Flow scenarios → Returns exchange: defines (evidence: `README.md`)
- Flow scenarios → Cart win-back: defines (evidence: `README.md`)
- Flow scenarios → Reference workflows: records (evidence: `README.md`)
