# nirwan-teji/swasthiq-front-desk-agent architecture

> Architecture diagram of the GitHub repository nirwan-teji/swasthiq-front-desk-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nirwan-teji/swasthiq-front-desk-agent
- Repository: https://github.com/nirwan-teji/swasthiq-front-desk-agent

## Overview

SwasthiQ is a safety-first clinic front-desk agent for appointment booking, rescheduling, cancellation, and human escalation, with a staff dashboard for reviewing handoffs and conversation outcomes. Callers submit a dated, multi-turn conversation through the API; the agent screens for safety, uses an LLM and clinic tools for routine requests, then returns a grounded result. The API captures successful runs for the dashboard, where staff can inspect conversations and resolve escalations. Edges follow excerpts, the SOURCE INDEX, or README; unsampled implementation details are not inferred.

Main entry points: [`backend/app/agent/orchestrator.py`](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/orchestrator.py) (Conversation orchestrator), [`frontend/src/App.tsx`](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/App.tsx) (Dashboard app), [`frontend/src/api/client.ts`](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/api/client.ts) (API client), [`backend/app/api/routes_agent.py`](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/api/routes_agent.py) (Agent endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Staff dashboard"]
  node_dashboard["Dashboard app<br/>[App.tsx]"]
  node_api_client["API client<br/>[client.ts]"]
  node_simulation["Run simulation"]
  node_queue_page["Handoff queue<br/>[HandoffQueue.tsx]"]
  node_handoff_table["Handoff table<br/>[HandoffTable.tsx]"]
  node_detail_page["Conversation detail"]
  node_transcript["Transcript view<br/>[TranscriptView.tsx]"]
  node_outcome["Outcome panel<br/>[OutcomePanel.tsx]"]
end

subgraph group_api["Backend API"]
  node_api_app["FastAPI app<br/>[main.py]"]
  node_agent_route["Agent endpoint<br/>[routes_agent.py]"]
  node_queue_routes["Dashboard endpoints<br/>[routes_queue.py]"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
end

subgraph group_agent["Conversation agent"]
  node_orchestrator["Conversation orchestrator<br/>[orchestrator.py]"]
  node_safety["Safety guard<br/>[safety_guard.py]"]
  node_date_resolver["Relative date engine<br/>[date_resolver.py]"]
  node_prompt["Clinic instructions<br/>[prompt.py]"]
  node_llm["LLM client<br/>[llm_client.py]"]
end

subgraph group_clinic["Clinic operations"]
  node_clinic_state[("Clinic state and tools<br/>[database.py]")]
  node_clinic_data["Clinic data<br/>[clinic.json]"]
end

node_caller(("Caller"))
node_staff(("Clinic staff"))
node_providers{{"Groq and Gemini"}}

node_caller -->|"enters turns"| node_simulation
node_simulation -->|"runs simulation"| node_api_client
node_api_client -->|"posts run"| node_agent_route
node_agent_route -->|"validates payload"| node_schemas
node_agent_route -->|"runs conversation"| node_orchestrator
node_orchestrator -->|"screens turns"| node_safety
node_orchestrator -->|"resolves dates"| node_date_resolver
node_orchestrator -->|"uses instructions"| node_prompt
node_orchestrator -->|"requests completion"| node_llm
node_llm -.->|"calls provider"| node_providers
node_orchestrator -->|"dispatches tools"| node_clinic_state
node_clinic_state -->|"loads clinic data"| node_clinic_data
node_api_app -->|"registers route"| node_agent_route
node_api_app -->|"registers routes"| node_queue_routes
node_api_app -->|"stores run result"| node_queue_routes
node_api_client -->|"fetches and resolves"| node_queue_routes
node_dashboard -->|"loads dashboard data"| node_api_client
node_dashboard -->|"shows queue"| node_queue_page
node_dashboard -->|"shows conversation"| node_detail_page
node_queue_page -->|"renders table"| node_handoff_table
node_detail_page -->|"renders transcript"| node_transcript
node_detail_page -->|"renders outcome"| node_outcome
node_staff -->|"reviews handoffs"| node_dashboard
node_queue_routes -->|"serves run records"| node_dashboard

click node_dashboard "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/App.tsx"
click node_api_client "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/api/client.ts"
click node_simulation "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/components/RunSimulationModal.tsx"
click node_queue_page "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/pages/HandoffQueue.tsx"
click node_handoff_table "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/components/HandoffTable.tsx"
click node_detail_page "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/pages/ConversationDetail.tsx"
click node_transcript "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/components/TranscriptView.tsx"
click node_outcome "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/components/OutcomePanel.tsx"
click node_api_app "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/main.py"
click node_agent_route "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/api/routes_agent.py"
click node_queue_routes "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/api/routes_queue.py"
click node_schemas "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/schemas.py"
click node_orchestrator "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/orchestrator.py"
click node_safety "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/safety_guard.py"
click node_date_resolver "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/date_resolver.py"
click node_prompt "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/prompt.py"
click node_llm "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/llm_client.py"
click node_clinic_state "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/database.py"
click node_clinic_data "https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/clinic.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_dashboard,node_api_client,node_simulation,node_queue_page,node_handoff_table,node_detail_page,node_transcript,node_outcome toneBlue
class node_api_app,node_agent_route,node_queue_routes,node_schemas toneAmber
class node_orchestrator,node_safety,node_date_resolver,node_prompt,node_llm toneMint
class node_clinic_state,node_clinic_data toneRose
class node_caller,node_staff,node_providers toneIndigo
```

## Components

### Staff dashboard

- [Dashboard app](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [API client](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/api/client.ts): `frontend/src/api/client.ts`
- [Run simulation](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/components/RunSimulationModal.tsx): `frontend/src/components/RunSimulationModal.tsx`
- [Handoff queue](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/pages/HandoffQueue.tsx): `frontend/src/pages/HandoffQueue.tsx`
- [Handoff table](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/components/HandoffTable.tsx): `frontend/src/components/HandoffTable.tsx`
- [Conversation detail](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/pages/ConversationDetail.tsx): `frontend/src/pages/ConversationDetail.tsx`
- [Transcript view](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/components/TranscriptView.tsx): `frontend/src/components/TranscriptView.tsx`
- [Outcome panel](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/frontend/src/components/OutcomePanel.tsx): `frontend/src/components/OutcomePanel.tsx`

### Backend API

- [FastAPI app](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/main.py): `backend/app/main.py`
- [Agent endpoint](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/api/routes_agent.py): `backend/app/api/routes_agent.py`
- [Dashboard endpoints](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/api/routes_queue.py): `backend/app/api/routes_queue.py`
- [Request and response schemas](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/schemas.py): `backend/app/schemas.py`

### Conversation agent

- [Conversation orchestrator](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/orchestrator.py): `backend/app/agent/orchestrator.py`
- [Safety guard](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/safety_guard.py): `backend/app/agent/safety_guard.py`
- [Relative date engine](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/date_resolver.py): `backend/app/agent/date_resolver.py`
- [Clinic instructions](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/prompt.py): `backend/app/agent/prompt.py`
- [LLM client](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/agent/llm_client.py): `backend/app/agent/llm_client.py`

### Clinic operations

- [Clinic state and tools](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/backend/app/database.py): `backend/app/database.py`
- [Clinic data](https://github.com/nirwan-teji/swasthiq-front-desk-agent/blob/main/clinic.json): `clinic.json`

### Other components

- **Caller**
- **Clinic staff**
- **Groq and Gemini**

## Connections

- Caller → Run simulation: enters turns (evidence: `frontend/src/components/RunSimulationModal.tsx`)
- Run simulation → API client: runs simulation (evidence: `frontend/src/components/RunSimulationModal.tsx`)
- API client → Agent endpoint: posts run (evidence: `frontend/src/api/client.ts`)
- Agent endpoint → Request and response schemas: validates payload (evidence: `backend/app/api/routes_agent.py`)
- Agent endpoint → Conversation orchestrator: runs conversation (evidence: `backend/app/api/routes_agent.py`)
- Conversation orchestrator → Safety guard: screens turns (evidence: `backend/app/agent/orchestrator.py`)
- Conversation orchestrator → Relative date engine: resolves dates (evidence: `backend/app/agent/orchestrator.py`)
- Conversation orchestrator → Clinic instructions: uses instructions (evidence: `backend/app/agent/orchestrator.py`)
- Conversation orchestrator → LLM client: requests completion (evidence: `backend/app/agent/orchestrator.py`)
- LLM client → Groq and Gemini: calls provider (evidence: `backend/app/agent/llm_client.py`)
- Conversation orchestrator → Clinic state and tools: dispatches tools (evidence: `backend/app/agent/orchestrator.py`)
- Clinic state and tools → Clinic data: loads clinic data (evidence: `README.md`)
- FastAPI app → Agent endpoint: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Dashboard endpoints: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → Dashboard endpoints: stores run result (evidence: `backend/app/main.py`)
- API client → Dashboard endpoints: fetches and resolves (evidence: `frontend/src/api/client.ts`)
- Dashboard app → API client: loads dashboard data (evidence: `frontend/src/App.tsx`)
- Dashboard app → Handoff queue: shows queue (evidence: `frontend/src/App.tsx`)
- Dashboard app → Conversation detail: shows conversation (evidence: `frontend/src/App.tsx`)
- Handoff queue → Handoff table: renders table (evidence: `frontend/src/pages/HandoffQueue.tsx`)
- Conversation detail → Transcript view: renders transcript (evidence: `frontend/src/pages/ConversationDetail.tsx`)
- Conversation detail → Outcome panel: renders outcome (evidence: `frontend/src/pages/ConversationDetail.tsx`)
- Clinic staff → Dashboard app: reviews handoffs (evidence: `README.md`)
- Dashboard endpoints → Dashboard app: serves run records (evidence: `backend/app/api/routes_queue.py`)
