# mauroproto/vocero architecture

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

- Interactive diagram: https://gitdiagram.com/mauroproto/vocero
- Repository: https://github.com/mauroproto/vocero

## Overview

#### Purpose and Runtime
Vocero is a Python 3.12/FastAPI backend that turns WhatsApp text or voice-note requests into autonomous provider phone calls and reports booking outcomes. The application entry point is `app/main.py`; configuration and environment boundaries are centralized in `app/config.py`. It runs directly under Uvicorn or in Docker via `Dockerfile` and `docker-compose.yml`.

#### Ingress: WhatsApp Request Handling
Meta WhatsApp webhooks enter through `app/api/whatsapp.py`, which verifies webhook subscriptions and receives inbound messages. This is the primary user-facing ingress. Message content is normalized into the request workflow; voice media is streamed/downloaded through `app/api/media_stream.py` and transcribed by `app/services/transcription.py`.

#### Conversation Understanding and State
`app/services/intent.py` uses OpenAI GPT to extract a structured appointment request defined in `app/schemas/intent.py`: service/provider need, location, scheduling preferences, and likely language/context. `app/services/state.py` owns the conversation-state boundary between possibly incomplete WhatsApp interactions and a request ready for call orchestration.

#### Provider Discovery and Selection
When the user has not specified a provider, `app/services/places.py` queries Google Places for candidates. `app/services/contact.py` supplies contact-oriented handling. Candidate outcomes from simultaneous calls are compared in `app/services/ranking.py`, separating search and result-selection policy from telephony execution.

#### Outbound Voice-Agent Call Orchestration
`app/services/elevenlabs_call.py` coordinates the outbound path: it registers a call with ElevenLabs Conversational AI, receives TwiML, and asks Twilio to originate the PSTN call. Twilio connects directly to the ElevenLabs voice-agent WebSocket; FastAPI is orchestration and tool infrastructure rather than an audio bridge. The relevant integration boundary is `app/services/twilio.py`.

#### Mid-Call Tool Boundary
During a live call, ElevenLabs invokes server tools exposed by `app/api/tools.py`. Tool contracts in `app/schemas/tools.py` support availability reporting, preference validation, booking confirmation, and no-availability outcomes. These endpoints let the phone agent make bounded, structured decisions against request state instead of owning backend persistence or messaging logic.

#### Completion, Notifications, and Persistence
Twilio lifecycle callbacks arrive at `app/api/callbacks.py`; post-call processing summarizes the transcript via OpenAI and determines the final user-facing outcome. `app/services/messages.py` renders/sends progress and completion messages through Meta WhatsApp. Confirmed appointments receive a Google Calendar link from `app/services/calendar.py`. PostgreSQL persistence is represented by `app/db/session.py` and domain models including `app/models/appointment.py`, `app/models/call_log.py`, and `app/models/appointment_request.py`.

#### External Services and Control Flow
Primary control flow is: Meta WhatsApp → FastAPI webhook → transcription (if needed) → OpenAI intent extraction/state completion → Google Places discovery (optional) → ElevenLabs registration + Twilio call → ElevenLabs tool callbacks → Twilio completion callback → OpenAI summary/ranking → WhatsApp notification and calendar link. Material external dependencies are Meta Cloud API, ElevenLabs Agents/Scribe, Twilio Voice, OpenAI GPT, Google Places, Google Calendar-link generation, and Docker-hosted PostgreSQL.

Main entry points: [`app/services/ranking.py`](https://github.com/mauroproto/vocero/blob/main/app/services/ranking.py) (Outcome ranking), [`app/services/state.py`](https://github.com/mauroproto/vocero/blob/main/app/services/state.py) (Conversation state), [`app/services/intent.py`](https://github.com/mauroproto/vocero/blob/main/app/services/intent.py) (Intent extraction), [`app/api/whatsapp.py`](https://github.com/mauroproto/vocero/blob/main/app/api/whatsapp.py) (WhatsApp webhook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["FastAPI ingress"]
  node_app["Vocero API<br/>FastAPI application<br/>[main.py]"]
  node_config["Configuration<br/>environment boundary<br/>[config.py]"]
  node_whatsapp_webhook["WhatsApp webhook<br/>inbound API<br/>[whatsapp.py]"]
  node_media_stream["Voice media stream<br/>media API<br/>[media_stream.py]"]
  node_tools_api["Agent tools<br/>tool API<br/>[tools.py]"]
  node_callbacks["Twilio callbacks<br/>lifecycle API<br/>[callbacks.py]"]
end

subgraph group_workflow["Request workflow"]
  node_transcription["Transcription<br/>speech service<br/>[transcription.py]"]
  node_intent["Intent extraction<br/>LLM service<br/>[intent.py]"]
  node_request_state["Conversation state<br/>workflow state<br/>[state.py]"]
  node_places["Provider discovery<br/>places service<br/>[places.py]"]
  node_ranking["Outcome ranking<br/>selection policy<br/>[ranking.py]"]
  node_notifications["WhatsApp messaging<br/>notification service<br/>[messages.py]"]
  node_calendar["Calendar link<br/>booking service<br/>[calendar.py]"]
end

subgraph group_calling["Call execution"]
  node_call_orchestrator["Call orchestrator<br/>voice orchestration<br/>[elevenlabs_call.py]"]
  node_twilio_integration["Twilio integration<br/>telephony boundary<br/>[twilio.py]"]
end

subgraph group_external["External services"]
  node_meta["Meta Cloud API<br/>WhatsApp platform"]
  node_openai["OpenAI GPT<br/>LLM provider"]
  node_google_places["Google Places<br/>places provider"]
  node_elevenlabs["ElevenLabs Agents<br/>voice agent platform"]
  node_twilio["Twilio Voice<br/>PSTN provider"]
  node_google_calendar["Google Calendar<br/>calendar platform"]
end

subgraph group_data["Persistence"]
  node_postgres[("PostgreSQL<br/>application database<br/>[session.py]")]
end

node_meta -->|"inbound messages"| node_whatsapp_webhook
node_whatsapp_webhook -->|"voice notes"| node_media_stream
node_media_stream -->|"audio"| node_transcription
node_whatsapp_webhook -->|"text request"| node_intent
node_transcription -->|"transcript"| node_intent
node_intent -->|"extract request"| node_openai
node_intent -->|"structured request"| node_request_state
node_request_state -->|"persist state"| node_postgres
node_request_state -.->|"provider unspecified"| node_places
node_places -->|"search candidates"| node_google_places
node_request_state -->|"ready request"| node_call_orchestrator
node_call_orchestrator -->|"register agent call"| node_elevenlabs
node_call_orchestrator -->|"originate call"| node_twilio_integration
node_twilio_integration -->|"PSTN call"| node_twilio
node_twilio -->|"audio WebSocket"| node_elevenlabs
node_elevenlabs -->|"tool invocations"| node_tools_api
node_tools_api -->|"validate and update"| node_request_state
node_twilio -->|"call lifecycle"| node_callbacks
node_callbacks -->|"completed call"| node_ranking
node_ranking -->|"summarize outcome"| node_openai
node_ranking -->|"store outcome"| node_postgres
node_ranking -.->|"confirmed booking"| node_calendar
node_calendar -->|"calendar link"| node_google_calendar
node_ranking -->|"final outcome"| node_notifications
node_notifications -->|"progress and completion"| node_meta

click node_app "https://github.com/mauroproto/vocero/blob/main/app/main.py"
click node_config "https://github.com/mauroproto/vocero/blob/main/app/config.py"
click node_whatsapp_webhook "https://github.com/mauroproto/vocero/blob/main/app/api/whatsapp.py"
click node_media_stream "https://github.com/mauroproto/vocero/blob/main/app/api/media_stream.py"
click node_tools_api "https://github.com/mauroproto/vocero/blob/main/app/api/tools.py"
click node_callbacks "https://github.com/mauroproto/vocero/blob/main/app/api/callbacks.py"
click node_transcription "https://github.com/mauroproto/vocero/blob/main/app/services/transcription.py"
click node_intent "https://github.com/mauroproto/vocero/blob/main/app/services/intent.py"
click node_request_state "https://github.com/mauroproto/vocero/blob/main/app/services/state.py"
click node_places "https://github.com/mauroproto/vocero/blob/main/app/services/places.py"
click node_ranking "https://github.com/mauroproto/vocero/blob/main/app/services/ranking.py"
click node_call_orchestrator "https://github.com/mauroproto/vocero/blob/main/app/services/elevenlabs_call.py"
click node_twilio_integration "https://github.com/mauroproto/vocero/blob/main/app/services/twilio.py"
click node_notifications "https://github.com/mauroproto/vocero/blob/main/app/services/messages.py"
click node_calendar "https://github.com/mauroproto/vocero/blob/main/app/services/calendar.py"
click node_postgres "https://github.com/mauroproto/vocero/blob/main/app/db/session.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_app,node_config,node_whatsapp_webhook,node_media_stream,node_tools_api,node_callbacks toneBlue
class node_transcription,node_intent,node_request_state,node_places,node_ranking,node_notifications,node_calendar toneAmber
class node_call_orchestrator,node_twilio_integration toneMint
class node_meta,node_openai,node_google_places,node_elevenlabs,node_twilio,node_google_calendar toneRose
class node_postgres toneIndigo
```

## Components

### FastAPI ingress

- [Vocero API](https://github.com/mauroproto/vocero/blob/main/app/main.py): FastAPI application · Application runtime and integration host. · `app/main.py`
- [Configuration](https://github.com/mauroproto/vocero/blob/main/app/config.py): environment boundary · `app/config.py`
- [WhatsApp webhook](https://github.com/mauroproto/vocero/blob/main/app/api/whatsapp.py): inbound API · `app/api/whatsapp.py`
- [Voice media stream](https://github.com/mauroproto/vocero/blob/main/app/api/media_stream.py): media API · `app/api/media_stream.py`
- [Agent tools](https://github.com/mauroproto/vocero/blob/main/app/api/tools.py): tool API · Bounded live-call operations against request state. · `app/api/tools.py`
- [Twilio callbacks](https://github.com/mauroproto/vocero/blob/main/app/api/callbacks.py): lifecycle API · `app/api/callbacks.py`

### Request workflow

- [Transcription](https://github.com/mauroproto/vocero/blob/main/app/services/transcription.py): speech service · `app/services/transcription.py`
- [Intent extraction](https://github.com/mauroproto/vocero/blob/main/app/services/intent.py): LLM service · `app/services/intent.py`
- [Conversation state](https://github.com/mauroproto/vocero/blob/main/app/services/state.py): workflow state · Holds incomplete conversations until ready for calling. · `app/services/state.py`
- [Provider discovery](https://github.com/mauroproto/vocero/blob/main/app/services/places.py): places service · `app/services/places.py`
- [Outcome ranking](https://github.com/mauroproto/vocero/blob/main/app/services/ranking.py): selection policy · `app/services/ranking.py`
- [WhatsApp messaging](https://github.com/mauroproto/vocero/blob/main/app/services/messages.py): notification service · `app/services/messages.py`
- [Calendar link](https://github.com/mauroproto/vocero/blob/main/app/services/calendar.py): booking service · `app/services/calendar.py`

### Call execution

- [Call orchestrator](https://github.com/mauroproto/vocero/blob/main/app/services/elevenlabs_call.py): voice orchestration · Registers the agent and initiates provider calls. · `app/services/elevenlabs_call.py`
- [Twilio integration](https://github.com/mauroproto/vocero/blob/main/app/services/twilio.py): telephony boundary · `app/services/twilio.py`

### External services

- **Meta Cloud API**: WhatsApp platform
- **OpenAI GPT**: LLM provider
- **Google Places**: places provider
- **ElevenLabs Agents**: voice agent platform · Hosts the agent and its direct audio WebSocket.
- **Twilio Voice**: PSTN provider
- **Google Calendar**: calendar platform

### Persistence

- [PostgreSQL](https://github.com/mauroproto/vocero/blob/main/app/db/session.py): application database · Stores requests, calls, and appointments. · `app/db/session.py`

## Connections

- Meta Cloud API → WhatsApp webhook: inbound messages
- WhatsApp webhook → Voice media stream: voice notes
- Voice media stream → Transcription: audio
- WhatsApp webhook → Intent extraction: text request
- Transcription → Intent extraction: transcript
- Intent extraction → OpenAI GPT: extract request
- Intent extraction → Conversation state: structured request
- Conversation state → PostgreSQL: persist state
- Conversation state → Provider discovery: provider unspecified
- Provider discovery → Google Places: search candidates
- Conversation state → Call orchestrator: ready request
- Call orchestrator → ElevenLabs Agents: register agent call
- Call orchestrator → Twilio integration: originate call
- Twilio integration → Twilio Voice: PSTN call
- Twilio Voice → ElevenLabs Agents: audio WebSocket · Twilio connects directly to the voice agent.
- ElevenLabs Agents → Agent tools: tool invocations
- Agent tools → Conversation state: validate and update
- Twilio Voice → Twilio callbacks: call lifecycle
- Twilio callbacks → Outcome ranking: completed call
- Outcome ranking → OpenAI GPT: summarize outcome
- Outcome ranking → PostgreSQL: store outcome
- Outcome ranking → Calendar link: confirmed booking
- Calendar link → Google Calendar: calendar link
- Outcome ranking → WhatsApp messaging: final outcome
- WhatsApp messaging → Meta Cloud API: progress and completion
