# shahzain-ali/whatsapp-ai-receptionist architecture

> Architecture diagram of the GitHub repository shahzain-ali/whatsapp-ai-receptionist, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shahzain-ali/whatsapp-ai-receptionist
- Repository: https://github.com/shahzain-ali/whatsapp-ai-receptionist

## Overview

WhatsApp Digital FTE is a clinic receptionist that answers patient questions from a business profile and handles appointment booking against Google Sheets. The main workflow is patient message → webhook routing → per-phone ADK session → agent reply → WhatsApp delivery. Booking checks live availability, prevents duplicate bookings, and either confirms directly or routes the request through owner approval. The graph also includes the prompt and knowledge layers. Relationships follow the README and shown source; unshown internals are omitted rather than inferred.

Main entry points: [`whatsapp_webhook/main.py`](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_webhook/main.py) (FastAPI webhook), [`whatsapp_fte/webhook_agent.py`](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/webhook_agent.py) (Customer agent), [`whatsapp_fte/whatsapp_client.py`](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/whatsapp_client.py) (Message delivery), [`whatsapp_fte/sheets_client.py`](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/sheets_client.py) (Sheets client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_channel["WhatsApp channel"]
  node_meta["WhatsApp Cloud API"]
  node_webhook["FastAPI webhook<br/>[main.py]"]
  node_wa_client["Message delivery<br/>[whatsapp_client.py]"]
end

subgraph group_conversation["Agent conversation"]
  node_bridge["Session bridge<br/>[agent_bridge.py]"]
  node_agent["Customer agent<br/>[webhook_agent.py]"]
  node_model["OpenAI model"]
  node_prompt_loader["Prompt loader<br/>[prompt_loader.py]"]
  node_prompt["Customer prompt<br/>[customer_agent.txt]"]
  node_knowledge["Knowledge context<br/>[knowledge_base.py]"]
  node_profile["Clinic profile"]
end

subgraph group_booking["Booking backend"]
  node_booking_tools["Booking tools<br/>[webhook_agent.py]"]
  node_availability["Slot logic<br/>[availability.py]"]
  node_sheets_client["Sheets client<br/>[sheets_client.py]"]
  node_sheets[("Google Sheets")]
end

subgraph group_approval["Owner approval"]
  node_pending[("Pending bookings<br/>[booking_store.py]")]
end

node_patient(("Patient"))
node_owner(("Clinic owner"))

node_patient -->|"sends messages"| node_meta
node_meta -->|"posts messages"| node_webhook
node_webhook -->|"routes customer"| node_bridge
node_bridge -->|"runs agent"| node_agent
node_agent -->|"reasons with"| node_model
node_agent -->|"loads instruction"| node_prompt_loader
node_prompt_loader -->|"reads prompt"| node_prompt
node_agent -->|"builds context"| node_knowledge
node_knowledge -->|"reads profile"| node_profile
node_agent -->|"registers tools"| node_booking_tools
node_booking_tools -->|"checks slots"| node_availability
node_booking_tools -->|"reads and writes"| node_sheets_client
node_booking_tools -->|"records pending"| node_pending
node_availability -.->|"uses sheet data"| node_sheets_client
node_sheets_client -->|"reads and appends"| node_sheets
node_booking_tools -->|"notifies owner"| node_wa_client
node_webhook -->|"resolves request"| node_pending
node_webhook -->|"persists approval"| node_sheets_client
node_webhook -->|"sends reply"| node_wa_client
node_wa_client -->|"sends text"| node_meta
node_meta -->|"delivers reply"| node_patient
node_wa_client -->|"sends approval request"| node_owner
node_owner -->|"replies YES or NO"| node_meta

click node_webhook "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_webhook/main.py"
click node_wa_client "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/whatsapp_client.py"
click node_bridge "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_webhook/agent_bridge.py"
click node_agent "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/webhook_agent.py"
click node_prompt_loader "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/prompt_loader.py"
click node_prompt "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/prompts/customer_agent.txt"
click node_knowledge "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/knowledge_base.py"
click node_profile "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/business_profile.json"
click node_booking_tools "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/webhook_agent.py"
click node_availability "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/availability.py"
click node_sheets_client "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/sheets_client.py"
click node_pending "https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/booking_store.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_meta,node_webhook,node_wa_client toneBlue
class node_bridge,node_agent,node_model,node_prompt_loader,node_prompt,node_knowledge,node_profile toneAmber
class node_booking_tools,node_availability,node_sheets_client,node_sheets toneMint
class node_pending toneRose
class node_patient,node_owner toneIndigo
```

## Components

### WhatsApp channel

- **WhatsApp Cloud API**
- [FastAPI webhook](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_webhook/main.py): `whatsapp_webhook/main.py`
- [Message delivery](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/whatsapp_client.py): `whatsapp_fte/whatsapp_client.py`

### Agent conversation

- [Session bridge](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_webhook/agent_bridge.py): `whatsapp_webhook/agent_bridge.py`
- [Customer agent](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/webhook_agent.py): `whatsapp_fte/webhook_agent.py`
- **OpenAI model**
- [Prompt loader](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/prompt_loader.py): `whatsapp_fte/prompt_loader.py`
- [Customer prompt](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/prompts/customer_agent.txt): `whatsapp_fte/prompts/customer_agent.txt`
- [Knowledge context](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/knowledge_base.py): `whatsapp_fte/knowledge_base.py`
- [Clinic profile](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/business_profile.json): `whatsapp_fte/business_profile.json`

### Booking backend

- [Booking tools](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/webhook_agent.py): `whatsapp_fte/webhook_agent.py`
- [Slot logic](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/availability.py): `whatsapp_fte/availability.py`
- [Sheets client](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/sheets_client.py): `whatsapp_fte/sheets_client.py`
- **Google Sheets**

### Owner approval

- [Pending bookings](https://github.com/shahzain-ali/whatsapp-ai-receptionist/blob/main/whatsapp_fte/booking_store.py): `whatsapp_fte/booking_store.py`

### Other components

- **Patient**
- **Clinic owner**

## Connections

- Patient → WhatsApp Cloud API: sends messages (evidence: `README.md`)
- WhatsApp Cloud API → FastAPI webhook: posts messages (evidence: `README.md`)
- FastAPI webhook → Session bridge: routes customer (evidence: `whatsapp_webhook/main.py`)
- Session bridge → Customer agent: runs agent (evidence: `whatsapp_webhook/agent_bridge.py`)
- Customer agent → OpenAI model: reasons with (evidence: `README.md`)
- Customer agent → Prompt loader: loads instruction (evidence: `whatsapp_fte/webhook_agent.py`)
- Prompt loader → Customer prompt: reads prompt (evidence: `whatsapp_fte/prompt_loader.py`)
- Customer agent → Knowledge context: builds context (evidence: `whatsapp_fte/webhook_agent.py`)
- Knowledge context → Clinic profile: reads profile (evidence: `whatsapp_fte/knowledge_base.py`)
- Customer agent → Booking tools: registers tools (evidence: `whatsapp_fte/webhook_agent.py`)
- Booking tools → Slot logic: checks slots (evidence: `whatsapp_fte/webhook_agent.py`)
- Booking tools → Sheets client: reads and writes (evidence: `whatsapp_fte/webhook_agent.py`)
- Booking tools → Pending bookings: records pending (evidence: `whatsapp_fte/webhook_agent.py`)
- Slot logic → Sheets client: uses sheet data
- Sheets client → Google Sheets: reads and appends (evidence: `whatsapp_fte/sheets_client.py`)
- Booking tools → Message delivery: notifies owner (evidence: `whatsapp_fte/webhook_agent.py`)
- FastAPI webhook → Pending bookings: resolves request (evidence: `whatsapp_webhook/main.py`)
- FastAPI webhook → Sheets client: persists approval (evidence: `whatsapp_webhook/main.py`)
- FastAPI webhook → Message delivery: sends reply (evidence: `whatsapp_webhook/main.py`)
- Message delivery → WhatsApp Cloud API: sends text (evidence: `README.md`)
- WhatsApp Cloud API → Patient: delivers reply (evidence: `README.md`)
- Message delivery → Clinic owner: sends approval request
- Clinic owner → WhatsApp Cloud API: replies YES or NO (evidence: `README.md`)
