# moamedmer68-commits/clinic-ai-customer-service architecture

> Architecture diagram of the GitHub repository moamedmer68-commits/clinic-ai-customer-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/moamedmer68-commits/clinic-ai-customer-service
- Repository: https://github.com/moamedmer68-commits/clinic-ai-customer-service

## Overview

Clinic AI Customer Service is a prototype chat service for clinic FAQs and appointment operations. Patients use the Streamlit client or call the authenticated FastAPI endpoint; the API manages session-scoped conversation state and invokes the LangGraph agent. The agent routes FAQ requests to grounded retrieval, appointment requests to structured availability and mutation tools, and sensitive or unresolved cases to a local human-handoff queue. Appointment changes require a separate exact confirmation before execution. Source excerpts establish the principal API, routing, storage and helper relationships; unsampled subsystem links are omitted where the caller is not shown.

Main entry points: [`main.py`](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/main.py) (FastAPI endpoints), [`agent.py`](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/agent.py) (LangGraph agent), [`streamlit_ui.py`](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/streamlit_ui.py) (Streamlit chat), [`knowledge_base.py`](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/knowledge_base.py) (FAQ retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Patient interface"]
  node_streamlit["Streamlit chat<br/>[streamlit_ui.py]"]
  node_ui_helpers["UI helpers<br/>[ui_helpers.py]"]
end

subgraph group_service["API and conversation"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_request_models["Request models<br/>[models.py]"]
  node_memory[("Conversation checkpoint<br/>[main.py]")]
  node_thread_key["Thread key<br/>[session.py]"]
end

subgraph group_agent["Agent routing"]
  node_agent["LangGraph agent<br/>[agent.py]"]
  node_prompts["Routing prompts<br/>[prompt.py]"]
  node_llm["OpenAI chat model<br/>[llms.py]"]
end

subgraph group_faq["FAQ retrieval"]
  node_faq["FAQ retrieval<br/>[knowledge_base.py]"]
  node_faq_data["Approved FAQ content<br/>[clinic_faq.json]"]
  node_faq_index[("Persistent FAQ index<br/>[knowledge_base.py]")]
end

subgraph group_operations["Appointments and support"]
  node_appointment_tools["Appointment tools<br/>[toolkits.py]"]
  node_appointment_csv[("Appointment state")]
  node_pending[("Pending action gate<br/>[pending_actions.py]")]
  node_handoff[("Human handoff queue<br/>[handoff.py]")]
end

node_patient(("Patient"))

node_patient -->|"chats through"| node_streamlit
node_streamlit -->|"submits requests"| node_api
node_streamlit -->|"uses helpers"| node_ui_helpers
node_patient -->|"calls directly"| node_api
node_api -->|"validates requests"| node_request_models
node_api -->|"derives thread key"| node_thread_key
node_api -->|"checkpoints conversation"| node_memory
node_api -->|"invokes workflow"| node_agent
node_agent -->|"uses routing prompt"| node_prompts
node_agent -->|"invokes model"| node_llm
node_agent -->|"retrieves FAQ answers"| node_faq
node_faq -->|"reads configured content"| node_faq_data
node_faq -->|"persists vector index"| node_faq_index
node_agent -->|"dispatches appointment tools"| node_appointment_tools
node_appointment_tools -->|"reads and updates"| node_appointment_csv
node_agent -->|"prepares mutations"| node_pending
node_api -->|"executes confirmed action"| node_pending
node_agent -->|"creates escalations"| node_handoff
node_api -->|"returns case status"| node_handoff

click node_streamlit "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/streamlit_ui.py"
click node_ui_helpers "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/ui_helpers.py"
click node_api "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/main.py"
click node_request_models "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/data_models/models.py"
click node_memory "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/main.py"
click node_thread_key "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/utils/session.py"
click node_agent "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/agent.py"
click node_prompts "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/prompt_library/prompt.py"
click node_llm "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/utils/llms.py"
click node_faq "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/knowledge_base.py"
click node_faq_data "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/data/clinic_faq.json"
click node_faq_index "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/knowledge_base.py"
click node_appointment_tools "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/toolkit/toolkits.py"
click node_appointment_csv "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/data/doctor_availability.csv"
click node_pending "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/support/pending_actions.py"
click node_handoff "https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/support/handoff.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_streamlit,node_ui_helpers toneBlue
class node_api,node_request_models,node_memory,node_thread_key toneAmber
class node_agent,node_prompts,node_llm toneMint
class node_faq,node_faq_data,node_faq_index toneRose
class node_appointment_tools,node_appointment_csv,node_pending,node_handoff,node_patient toneIndigo
```

## Components

### Patient interface

- [Streamlit chat](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/streamlit_ui.py): `streamlit_ui.py`
- [UI helpers](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/ui_helpers.py): `ui_helpers.py`

### API and conversation

- [FastAPI endpoints](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/main.py): `main.py`
- [Request models](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/data_models/models.py): `data_models/models.py`
- [Conversation checkpoint](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/main.py): `main.py`
- [Thread key](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/utils/session.py): `utils/session.py`

### Agent routing

- [LangGraph agent](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/agent.py): `agent.py`
- [Routing prompts](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/prompt_library/prompt.py): `prompt_library/prompt.py`
- [OpenAI chat model](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/utils/llms.py): `utils/llms.py`

### FAQ retrieval

- [FAQ retrieval](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/knowledge_base.py): `knowledge_base.py`
- [Approved FAQ content](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/data/clinic_faq.json): `data/clinic_faq.json`
- [Persistent FAQ index](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/knowledge_base.py): `knowledge_base.py`

### Appointments and support

- [Appointment tools](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/toolkit/toolkits.py): `toolkit/toolkits.py`
- [Appointment state](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/data/doctor_availability.csv): `data/doctor_availability.csv`
- [Pending action gate](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/support/pending_actions.py): `support/pending_actions.py`
- [Human handoff queue](https://github.com/moamedmer68-commits/clinic-ai-customer-service/blob/main/support/handoff.py): `support/handoff.py`

### Other components

- **Patient**

## Connections

- Patient → Streamlit chat: chats through (evidence: `README.md`)
- Streamlit chat → FastAPI endpoints: submits requests (evidence: `README.md`)
- Streamlit chat → UI helpers: uses helpers (evidence: `streamlit_ui.py`)
- Patient → FastAPI endpoints: calls directly (evidence: `README.md`)
- FastAPI endpoints → Request models: validates requests (evidence: `main.py`)
- FastAPI endpoints → Thread key: derives thread key (evidence: `main.py`)
- FastAPI endpoints → Conversation checkpoint: checkpoints conversation (evidence: `main.py`)
- FastAPI endpoints → LangGraph agent: invokes workflow (evidence: `main.py`)
- LangGraph agent → Routing prompts: uses routing prompt (evidence: `agent.py`)
- LangGraph agent → OpenAI chat model: invokes model (evidence: `agent.py`)
- LangGraph agent → FAQ retrieval: retrieves FAQ answers (evidence: `agent.py`)
- FAQ retrieval → Approved FAQ content: reads configured content (evidence: `README.md`)
- FAQ retrieval → Persistent FAQ index: persists vector index (evidence: `README.md`)
- LangGraph agent → Appointment tools: dispatches appointment tools (evidence: `agent.py`)
- Appointment tools → Appointment state: reads and updates (evidence: `toolkit/toolkits.py`)
- LangGraph agent → Pending action gate: prepares mutations (evidence: `agent.py`)
- FastAPI endpoints → Pending action gate: executes confirmed action (evidence: `README.md`)
- LangGraph agent → Human handoff queue: creates escalations (evidence: `agent.py`)
- FastAPI endpoints → Human handoff queue: returns case status (evidence: `README.md`)
