# diogobrazil/bot-clinica-vida architecture

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

- Interactive diagram: https://gitdiagram.com/diogobrazil/bot-clinica-vida
- Repository: https://github.com/diogobrazil/bot-clinica-vida

## Overview

VIDA Bot is a clinic appointment and information service delivered through WhatsApp, with a staff web panel for conversation handoff and clinic administration. The main user flow is an incoming WhatsApp message through the webhook into the bot FSM, followed by a response through the WhatsApp sender; the README identifies the bot as deterministic and FSM-based. The panel separately supports staff conversations and management of scheduling and clinic data. Several important modules are unsampled, so those branches are shown only where the README or SOURCE INDEX supports the relationship.

Main entry points: [`app/whatsapp/webhook.py`](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/whatsapp/webhook.py) (Message webhook), [`app/bot/fsm.py`](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/bot/fsm.py) (Conversation FSM), [`app/bot/webhook_handlers.py`](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/bot/webhook_handlers.py) (Webhook workflows), [`panel/src/api/client.ts`](https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/api/client.ts) (HTTP API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_whatsapp["WhatsApp channel"]
  node_webhook["Message webhook<br/>[webhook.py]"]
  node_templates["Message templates"]
  node_sender["WhatsApp sender<br/>[sender.py]"]
end

subgraph group_bot["Bot and domain"]
  node_fsm["Conversation FSM<br/>[fsm.py]"]
  node_bot_handlers["Bot handlers<br/>[handlers.py]"]
  node_business_hours["Business hours<br/>[business_hours.py]"]
  node_scheduling["Scheduling services<br/>[scheduling.py]"]
  node_llm["FAQ and LLM<br/>[llm.py]"]
  node_handoff["Human handoff<br/>[handoff.py]"]
  node_webhook_handlers["Webhook workflows"]
end

subgraph group_data["Persistence and API"]
  node_main["FastAPI entry<br/>[main.py]"]
  node_models["Clinic data models"]
  node_session_repo["Session repository<br/>[session_repo.py]"]
  node_message_repo["Message repository<br/>[message_repo.py]"]
  node_postgres[("PostgreSQL")]
  node_api["Clinic and staff API"]
  node_ws["Panel WebSocket<br/>[ws.py]"]
end

subgraph group_panel["Staff panel"]
  node_panel_app["Panel routes<br/>[App.tsx]"]
  node_auth["Panel authentication<br/>[useAuth.tsx]"]
  node_panel_client["HTTP API client<br/>[client.ts]"]
  node_schedule_page["Schedule management<br/>[Schedule.tsx]"]
  node_chat["Conversation console<br/>[ChatWindow.tsx]"]
end

node_patient(("Patient"))
node_meta{{"WhatsApp Cloud API"}}
node_staff(("Clinic staff"))

node_patient -->|"sends messages"| node_meta
node_meta -->|"delivers webhook"| node_webhook
node_main -->|"mounts route"| node_webhook
node_webhook -->|"processes message"| node_fsm
node_webhook -->|"checks hours"| node_business_hours
node_webhook -->|"routes handoff"| node_handoff
node_webhook -->|"delegates workflow"| node_webhook_handlers
node_webhook -->|"loads session"| node_session_repo
node_webhook -->|"records messages"| node_message_repo
node_webhook_handlers -->|"sends replies"| node_sender
node_webhook_handlers -->|"broadcasts updates"| node_ws
node_webhook_handlers -->|"formats replies"| node_templates
node_fsm -.->|"dispatches state"| node_bot_handlers
node_fsm -.->|"runs booking flow"| node_scheduling
node_fsm -.->|"resolves questions"| node_llm
node_sender -->|"posts messages"| node_meta
node_main -->|"mounts routers"| node_api
node_staff -->|"uses panel"| node_panel_app
node_panel_app -->|"checks identity"| node_auth
node_auth -->|"calls auth API"| node_panel_client
node_panel_app -->|"routes schedule"| node_schedule_page
node_schedule_page -->|"requests schedule data"| node_panel_client
node_panel_client -->|"calls HTTP endpoints"| node_api
node_panel_client -.->|"loads conversations"| node_chat
node_chat -.->|"receives live updates"| node_ws
node_session_repo -->|"persists sessions"| node_models
node_message_repo -->|"stores message records"| node_models
node_models -.->|"maps clinic data"| node_postgres
node_api -.->|"manages clinic records"| node_models

click node_main "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/main.py"
click node_webhook "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/whatsapp/webhook.py"
click node_fsm "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/bot/fsm.py"
click node_bot_handlers "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/bot/handlers.py"
click node_business_hours "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/domain/services/business_hours.py"
click node_scheduling "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/domain/services/scheduling.py"
click node_llm "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/domain/services/llm.py"
click node_handoff "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/bot/handoff.py"
click node_webhook_handlers "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/bot/webhook_handlers.py"
click node_templates "https://github.com/diogobrazil/bot-clinica-vida/tree/main/app/whatsapp/templates"
click node_sender "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/whatsapp/sender.py"
click node_models "https://github.com/diogobrazil/bot-clinica-vida/tree/main/app/domain/models"
click node_session_repo "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/infra/repositories/session_repo.py"
click node_message_repo "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/infra/repositories/message_repo.py"
click node_api "https://github.com/diogobrazil/bot-clinica-vida/tree/main/app/api"
click node_panel_app "https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/App.tsx"
click node_auth "https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/hooks/useAuth.tsx"
click node_panel_client "https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/api/client.ts"
click node_schedule_page "https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/pages/Schedule.tsx"
click node_chat "https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/components/ChatWindow.tsx"
click node_ws "https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/api/ws.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_webhook,node_templates,node_sender toneBlue
class node_fsm,node_bot_handlers,node_business_hours,node_scheduling,node_llm,node_handoff,node_webhook_handlers toneAmber
class node_main,node_models,node_session_repo,node_message_repo,node_postgres,node_api,node_ws,node_meta toneMint
class node_panel_app,node_auth,node_panel_client,node_schedule_page,node_chat toneRose
class node_patient,node_staff toneIndigo
```

## Components

### WhatsApp channel

- [Message webhook](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/whatsapp/webhook.py): `app/whatsapp/webhook.py`
- [Message templates](https://github.com/diogobrazil/bot-clinica-vida/tree/main/app/whatsapp/templates): `app/whatsapp/templates`
- [WhatsApp sender](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/whatsapp/sender.py): `app/whatsapp/sender.py`

### Bot and domain

- [Conversation FSM](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/bot/fsm.py): `app/bot/fsm.py`
- [Bot handlers](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/bot/handlers.py): `app/bot/handlers.py`
- [Business hours](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/domain/services/business_hours.py): `app/domain/services/business_hours.py`
- [Scheduling services](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/domain/services/scheduling.py): `app/domain/services/scheduling.py`
- [FAQ and LLM](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/domain/services/llm.py): `app/domain/services/llm.py`
- [Human handoff](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/bot/handoff.py): `app/bot/handoff.py`
- [Webhook workflows](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/bot/webhook_handlers.py): `app/bot/webhook_handlers.py`

### Persistence and API

- [FastAPI entry](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/main.py): `app/main.py`
- [Clinic data models](https://github.com/diogobrazil/bot-clinica-vida/tree/main/app/domain/models): `app/domain/models`
- [Session repository](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/infra/repositories/session_repo.py): `app/infra/repositories/session_repo.py`
- [Message repository](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/infra/repositories/message_repo.py): `app/infra/repositories/message_repo.py`
- **PostgreSQL**
- [Clinic and staff API](https://github.com/diogobrazil/bot-clinica-vida/tree/main/app/api): `app/api`
- [Panel WebSocket](https://github.com/diogobrazil/bot-clinica-vida/blob/main/app/api/ws.py): `app/api/ws.py`

### Staff panel

- [Panel routes](https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/App.tsx): `panel/src/App.tsx`
- [Panel authentication](https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/hooks/useAuth.tsx): `panel/src/hooks/useAuth.tsx`
- [HTTP API client](https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/api/client.ts): `panel/src/api/client.ts`
- [Schedule management](https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/pages/Schedule.tsx): `panel/src/pages/Schedule.tsx`
- [Conversation console](https://github.com/diogobrazil/bot-clinica-vida/blob/main/panel/src/components/ChatWindow.tsx): `panel/src/components/ChatWindow.tsx`

### Other components

- **Patient**
- **WhatsApp Cloud API**
- **Clinic staff**

## Connections

- Patient → WhatsApp Cloud API: sends messages (evidence: `README.md`)
- WhatsApp Cloud API → Message webhook: delivers webhook (evidence: `README.md`)
- FastAPI entry → Message webhook: mounts route (evidence: `app/main.py`)
- Message webhook → Conversation FSM: processes message (evidence: `app/whatsapp/webhook.py`)
- Message webhook → Business hours: checks hours (evidence: `app/whatsapp/webhook.py`)
- Message webhook → Human handoff: routes handoff (evidence: `app/whatsapp/webhook.py`)
- Message webhook → Webhook workflows: delegates workflow (evidence: `app/whatsapp/webhook.py`)
- Message webhook → Session repository: loads session (evidence: `app/whatsapp/webhook.py`)
- Message webhook → Message repository: records messages (evidence: `app/whatsapp/webhook.py`)
- Webhook workflows → WhatsApp sender: sends replies (evidence: `app/bot/webhook_handlers.py`)
- Webhook workflows → Panel WebSocket: broadcasts updates (evidence: `app/bot/webhook_handlers.py`)
- Webhook workflows → Message templates: formats replies (evidence: `app/bot/webhook_handlers.py`)
- Conversation FSM → Bot handlers: dispatches state
- Conversation FSM → Scheduling services: runs booking flow
- Conversation FSM → FAQ and LLM: resolves questions
- WhatsApp sender → WhatsApp Cloud API: posts messages (evidence: `app/whatsapp/sender.py`)
- FastAPI entry → Clinic and staff API: mounts routers (evidence: `app/main.py`)
- Clinic staff → Panel routes: uses panel (evidence: `panel/src/App.tsx`)
- Panel routes → Panel authentication: checks identity (evidence: `panel/src/App.tsx`)
- Panel authentication → HTTP API client: calls auth API (evidence: `panel/src/hooks/useAuth.tsx`)
- Panel routes → Schedule management: routes schedule (evidence: `panel/src/App.tsx`)
- Schedule management → HTTP API client: requests schedule data (evidence: `panel/src/pages/Schedule.tsx`)
- HTTP API client → Clinic and staff API: calls HTTP endpoints (evidence: `panel/src/api/client.ts`)
- HTTP API client → Conversation console: loads conversations
- Conversation console → Panel WebSocket: receives live updates
- Session repository → Clinic data models: persists sessions (evidence: `app/infra/repositories/session_repo.py`)
- Message repository → Clinic data models: stores message records (evidence: `app/infra/repositories/message_repo.py`)
- Clinic data models → PostgreSQL: maps clinic data
- Clinic and staff API → Clinic data models: manages clinic records (evidence: `app/api/auth_deps.py`)
