# entbappy/medical-agentic-chatbot architecture

> Architecture diagram of the GitHub repository entbappy/medical-agentic-chatbot, 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/entbappy/medical-agentic-chatbot
- Repository: https://github.com/entbappy/medical-agentic-chatbot

## Overview

MedGuide AI is an educational medical assistant exposed through a FastAPI service and vanilla-JavaScript UI. Users can submit questions, optional images, and conversation history; the chat endpoint obtains image observations, runs a retrieval-and-routing agent, and returns an answer with sources. Separate user capabilities provide speech transcription and spoken answers. A documented ingestion workflow chunks the historical PDF and indexes embeddings for retrieval. The graph follows relationships visible in excerpts or the README; unsampled template and knowledge details are represented only where documented.

Main entry points: [`app/main.py`](https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/main.py) (FastAPI endpoints), [`app/agent.py`](https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/agent.py) (LangGraph agent), [`ingest.py`](https://github.com/entbappy/medical-agentic-chatbot/blob/main/ingest.py) (PDF ingestion), [`static/app.js`](https://github.com/entbappy/medical-agentic-chatbot/blob/main/static/app.js) (Chat UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_browser["Chat UI<br/>[app.js]"]
  node_page["Web page<br/>[index.html]"]
  node_speech["Speech controls<br/>[app.js]"]
end

subgraph group_api["API service"]
  node_service["FastAPI endpoints<br/>[main.py]"]
  node_settings["Configuration<br/>[config.py]"]
end

subgraph group_agent["Answer workflow"]
  node_agent_graph["LangGraph agent<br/>[agent.py]"]
  node_memory[("Conversation checkpoint<br/>[agent.py]")]
end

subgraph group_knowledge["Knowledge base"]
  node_retrieval["PDF retrieval<br/>[knowledge.py]"]
  node_indexer["PDF ingestion<br/>[ingest.py]"]
  node_pdf["Medical reference PDF<br/>[Medical_book.pdf]"]
  node_pinecone[("Pinecone index")]
end

subgraph group_media["Media services"]
  node_openai["OpenAI API"]
  node_tavily["Tavily search"]
end

node_user(("User"))

node_user -->|"uses"| node_browser
node_browser -.->|"renders in"| node_page
node_browser -->|"calls chat"| node_service
node_service -->|"checks settings"| node_settings
node_service -->|"invokes"| node_agent_graph
node_service -->|"requests image observations"| node_openai
node_service -->|"sets thread ID"| node_memory
node_agent_graph -->|"searches knowledge"| node_retrieval
node_agent_graph -->|"searches when routed"| node_tavily
node_agent_graph -->|"generates answer"| node_openai
node_agent_graph -->|"persists state"| node_memory
node_retrieval -->|"queries index"| node_pinecone
node_retrieval -->|"embeds query"| node_openai
node_indexer -->|"reads pages"| node_pdf
node_indexer -->|"uses embedding helpers"| node_retrieval
node_indexer -->|"upserts vectors"| node_pinecone
node_indexer -->|"embeds chunks"| node_openai
node_browser -->|"offers voice controls"| node_speech
node_speech -->|"calls speech endpoints"| node_service
node_service -->|"transcribes and synthesizes"| node_openai

click node_browser "https://github.com/entbappy/medical-agentic-chatbot/blob/main/static/app.js"
click node_page "https://github.com/entbappy/medical-agentic-chatbot/blob/main/templates/index.html"
click node_service "https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/main.py"
click node_settings "https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/config.py"
click node_agent_graph "https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/agent.py"
click node_retrieval "https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/knowledge.py"
click node_indexer "https://github.com/entbappy/medical-agentic-chatbot/blob/main/ingest.py"
click node_pdf "https://github.com/entbappy/medical-agentic-chatbot/blob/main/data/Medical_book.pdf"
click node_memory "https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/agent.py"
click node_speech "https://github.com/entbappy/medical-agentic-chatbot/blob/main/static/app.js"

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_browser,node_page,node_speech,node_user toneBlue
class node_service,node_settings toneAmber
class node_agent_graph,node_memory toneMint
class node_retrieval,node_indexer,node_pdf,node_pinecone toneRose
class node_openai,node_tavily toneIndigo
```

## Components

### Web experience

- [Chat UI](https://github.com/entbappy/medical-agentic-chatbot/blob/main/static/app.js): `static/app.js`
- [Web page](https://github.com/entbappy/medical-agentic-chatbot/blob/main/templates/index.html): `templates/index.html`
- [Speech controls](https://github.com/entbappy/medical-agentic-chatbot/blob/main/static/app.js): `static/app.js`

### API service

- [FastAPI endpoints](https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/main.py): `app/main.py`
- [Configuration](https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/config.py): `app/config.py`

### Answer workflow

- [LangGraph agent](https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/agent.py): `app/agent.py`
- [Conversation checkpoint](https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/agent.py): `app/agent.py`

### Knowledge base

- [PDF retrieval](https://github.com/entbappy/medical-agentic-chatbot/blob/main/app/knowledge.py): `app/knowledge.py`
- [PDF ingestion](https://github.com/entbappy/medical-agentic-chatbot/blob/main/ingest.py): `ingest.py`
- [Medical reference PDF](https://github.com/entbappy/medical-agentic-chatbot/blob/main/data/Medical_book.pdf): `data/Medical_book.pdf`
- **Pinecone index**

### Media services

- **OpenAI API**
- **Tavily search**

### Other components

- **User**

## Connections

- User → Chat UI: uses (evidence: `README.md`)
- Chat UI → Web page: renders in
- Chat UI → FastAPI endpoints: calls chat (evidence: `static/app.js`)
- FastAPI endpoints → Configuration: checks settings (evidence: `app/main.py`)
- FastAPI endpoints → LangGraph agent: invokes (evidence: `app/main.py`)
- FastAPI endpoints → OpenAI API: requests image observations (evidence: `app/main.py`)
- FastAPI endpoints → Conversation checkpoint: sets thread ID (evidence: `app/main.py`)
- LangGraph agent → PDF retrieval: searches knowledge (evidence: `app/agent.py`)
- LangGraph agent → Tavily search: searches when routed (evidence: `app/agent.py`)
- LangGraph agent → OpenAI API: generates answer (evidence: `README.md`)
- LangGraph agent → Conversation checkpoint: persists state (evidence: `app/agent.py`)
- PDF retrieval → Pinecone index: queries index (evidence: `app/knowledge.py`)
- PDF retrieval → OpenAI API: embeds query (evidence: `app/knowledge.py`)
- PDF ingestion → Medical reference PDF: reads pages (evidence: `ingest.py`)
- PDF ingestion → PDF retrieval: uses embedding helpers (evidence: `ingest.py`)
- PDF ingestion → Pinecone index: upserts vectors (evidence: `ingest.py`)
- PDF ingestion → OpenAI API: embeds chunks (evidence: `ingest.py`)
- Chat UI → Speech controls: offers voice controls (evidence: `static/app.js`)
- Speech controls → FastAPI endpoints: calls speech endpoints (evidence: `static/app.js`)
- FastAPI endpoints → OpenAI API: transcribes and synthesizes (evidence: `app/main.py`)
