# drdevastating/rag-based-medical-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/drdevastating/rag-based-medical-chatbot
- Repository: https://github.com/drdevastating/rag-based-medical-chatbot

## Overview

HaleAI is a medical-question answering application: a React interface sends requests to a FastAPI service, which delegates question processing to a RAG chatbot and returns answers with cited sources. The backend prepares PDF references as chunks and embeddings, retrieves candidates from a vector store, reranks them, and asks Gemini to generate a response. The UI also includes health status, analytics, source display, and a medical disclaimer. README documentation is not informative; some frontend request wiring and storage internals were not shown, so those connections are omitted.

Main entry points: [`backend/chatbot.py`](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/chatbot.py) (Query orchestrator), [`backend/data_processor.py`](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/data_processor.py) (PDF chunks and embeddings), [`frontend/src/App.jsx`](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/frontend/src/App.jsx) (Chat and dashboard), [`backend/llm_handler.py`](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/llm_handler.py) (Gemini response generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_webapp["Chat and dashboard<br/>[App.jsx]"]
end

subgraph group_service["API service"]
  node_api["FastAPI endpoints<br/>[backend_server.py]"]
  node_health["Health and metrics<br/>[backend_server.py]"]
end

subgraph group_rag["Medical RAG"]
  node_chatbot["Query orchestrator<br/>[chatbot.py]"]
  node_reranking["Reranking and context selection<br/>[rag_processor.py]"]
  node_generation["Gemini response generation<br/>[llm_handler.py]"]
end

subgraph group_knowledge["Knowledge base"]
  node_pdfs["Medical PDF corpus"]
  node_processing["PDF chunks and embeddings<br/>[data_processor.py]"]
  node_vectors[("Vector retrieval<br/>[vector_store.py]")]
end

node_user(("Medical user"))
node_gemini{{"Google Gemini"}}

node_user -->|"asks question"| node_webapp
node_webapp -->|"checks health"| node_health
node_api -->|"delegates queries"| node_chatbot
node_chatbot -->|"initializes"| node_processing
node_chatbot -->|"retrieves candidates"| node_vectors
node_chatbot -->|"reranks candidates"| node_reranking
node_chatbot -->|"generates answer"| node_generation
node_pdfs -.->|"provides PDFs"| node_processing
node_processing -.->|"supplies embeddings"| node_vectors
node_generation -.->|"calls model"| node_gemini

click node_webapp "https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/frontend/src/App.jsx"
click node_api "https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/backend_server.py"
click node_health "https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/backend_server.py"
click node_chatbot "https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/chatbot.py"
click node_pdfs "https://github.com/drdevastating/rag-based-medical-chatbot/tree/main/backend/data"
click node_processing "https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/data_processor.py"
click node_vectors "https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/vector_store.py"
click node_reranking "https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/rag_processor.py"
click node_generation "https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/llm_handler.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_webapp,node_user toneBlue
class node_api,node_health toneAmber
class node_chatbot,node_reranking,node_generation toneMint
class node_pdfs,node_processing,node_vectors toneRose
class node_gemini toneIndigo
```

## Components

### Web client

- [Chat and dashboard](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`

### API service

- [FastAPI endpoints](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/backend_server.py): `backend/backend_server.py`
- [Health and metrics](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/backend_server.py): `backend/backend_server.py`

### Medical RAG

- [Query orchestrator](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/chatbot.py): `backend/chatbot.py`
- [Reranking and context selection](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/rag_processor.py): `backend/rag_processor.py`
- [Gemini response generation](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/llm_handler.py): `backend/llm_handler.py`

### Knowledge base

- [Medical PDF corpus](https://github.com/drdevastating/rag-based-medical-chatbot/tree/main/backend/data): `backend/data`
- [PDF chunks and embeddings](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/data_processor.py): `backend/data_processor.py`
- [Vector retrieval](https://github.com/drdevastating/rag-based-medical-chatbot/blob/main/backend/vector_store.py): `backend/vector_store.py`

### Other components

- **Medical user**
- **Google Gemini**

## Connections

- Medical user → Chat and dashboard: asks question (evidence: `frontend/src/App.jsx`)
- Chat and dashboard → Health and metrics: checks health (evidence: `frontend/src/App.jsx`)
- FastAPI endpoints → Query orchestrator: delegates queries (evidence: `backend/backend_server.py`)
- Query orchestrator → PDF chunks and embeddings: initializes (evidence: `backend/chatbot.py`)
- Query orchestrator → Vector retrieval: retrieves candidates (evidence: `backend/chatbot.py`)
- Query orchestrator → Reranking and context selection: reranks candidates (evidence: `backend/chatbot.py`)
- Query orchestrator → Gemini response generation: generates answer (evidence: `backend/chatbot.py`)
- Medical PDF corpus → PDF chunks and embeddings: provides PDFs
- PDF chunks and embeddings → Vector retrieval: supplies embeddings
- Gemini response generation → Google Gemini: calls model
