# swapnil04-debug/medical-rag-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/swapnil04-debug/medical-rag-chatbot
- Repository: https://github.com/swapnil04-debug/medical-rag-chatbot

## Overview

CareGuide is a Flask medical-information assistant. The main workflow is browser query → intent and query handling → knowledge retrieval → text answer, with session memory and a separate image-analysis route. The README documents these capabilities; the excerpts show parts of both Flask implementations, but do not expose every route or call, so documented relationships use README evidence and unsampled internals are not expanded.

Main entry points: [`app.py`](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py) (Request orchestration), [`templates/index.html`](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/templates/index.html) (Chat and history UI), [`data/HospInfo.csv`](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/data/HospInfo.csv) (Hospital and medicine data), [`data/faiss_index.bin`](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/data/faiss_index.bin) (FAISS index)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_web_ui["Chat and history UI<br/>[index.html]"]
  node_history_ui["History viewer<br/>[history.html]"]
end

subgraph group_backend["Flask Backend"]
  node_orchestrator["Request orchestration<br/>[app.py]"]
  node_intent["Intent gates<br/>[app.py]"]
  node_rewrite["Query preprocessing<br/>[app.py]"]
  node_memory[("Session memory and history<br/>[app.py]")]
  node_text_generation["Answer generation<br/>[app.py]"]
  node_image_analysis["Image analysis<br/>[app.py]"]
  node_alternate_app["Alternate Flask implementation<br/>[app1.py]"]
end

subgraph group_knowledge["Knowledge and Memory"]
  node_retrieval["RAG retrieval<br/>[app.py]"]
  node_embedder["Query embeddings<br/>[app.py]"]
  node_faiss[("FAISS index<br/>[faiss_index.bin]")]
  node_docstore[("Document store<br/>[doc_store.pkl]")]
  node_knowledge_sources["Hospital and medicine data<br/>[HospInfo.csv]"]
end

subgraph group_integrations["External Services"]
  node_text_llm{{"Groq text LLM"}}
  node_vision_llm{{"Groq vision LLM"}}
end

node_user(("Chat user"))

node_user -->|"uses"| node_web_ui
node_web_ui -->|"submits queries"| node_orchestrator
node_history_ui -->|"requests history"| node_orchestrator
node_orchestrator -->|"checks intent"| node_intent
node_orchestrator -->|"rewrites query"| node_rewrite
node_orchestrator -->|"retrieves context"| node_retrieval
node_retrieval -->|"embeds query"| node_embedder
node_retrieval -->|"searches index"| node_faiss
node_retrieval -->|"reads chunks"| node_docstore
node_knowledge_sources -->|"builds offline"| node_faiss
node_knowledge_sources -->|"builds offline"| node_docstore
node_orchestrator -->|"generates answer"| node_text_generation
node_text_generation -->|"prompts"| node_text_llm
node_orchestrator -->|"uses session state"| node_memory
node_orchestrator -->|"routes image"| node_image_analysis
node_image_analysis -->|"analyzes image"| node_vision_llm
node_orchestrator -->|"returns answer"| node_web_ui

click node_web_ui "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/templates/index.html"
click node_history_ui "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/templates/history.html"
click node_orchestrator "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py"
click node_intent "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py"
click node_rewrite "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py"
click node_retrieval "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py"
click node_embedder "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py"
click node_faiss "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/data/faiss_index.bin"
click node_docstore "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/data/doc_store.pkl"
click node_knowledge_sources "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/data/HospInfo.csv"
click node_memory "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py"
click node_text_generation "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py"
click node_image_analysis "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py"
click node_alternate_app "https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app1.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_web_ui,node_history_ui,node_user toneBlue
class node_orchestrator,node_intent,node_rewrite,node_memory,node_text_generation,node_image_analysis,node_alternate_app toneAmber
class node_retrieval,node_embedder,node_faiss,node_docstore,node_knowledge_sources toneMint
class node_text_llm,node_vision_llm toneRose
```

## Components

### Client

- [Chat and history UI](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/templates/index.html): `templates/index.html`
- [History viewer](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/templates/history.html): `templates/history.html`

### Flask Backend

- [Request orchestration](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py): `app.py`
- [Intent gates](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py): `app.py`
- [Query preprocessing](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py): `app.py`
- [Session memory and history](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py): `app.py`
- [Answer generation](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py): `app.py`
- [Image analysis](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py): `app.py`
- [Alternate Flask implementation](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app1.py): `app1.py`

### Knowledge and Memory

- [RAG retrieval](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py): `app.py`
- [Query embeddings](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/app.py): `app.py`
- [FAISS index](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/data/faiss_index.bin): `data/faiss_index.bin`
- [Document store](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/data/doc_store.pkl): `data/doc_store.pkl`
- [Hospital and medicine data](https://github.com/swapnil04-debug/medical-rag-chatbot/blob/main/data/HospInfo.csv): `data/HospInfo.csv`

### External Services

- **Groq text LLM**
- **Groq vision LLM**

### Other components

- **Chat user**

## Connections

- Chat user → Chat and history UI: uses (evidence: `README.md`)
- Chat and history UI → Request orchestration: submits queries (evidence: `README.md`)
- History viewer → Request orchestration: requests history (evidence: `README.md`)
- Request orchestration → Intent gates: checks intent (evidence: `README.md`)
- Request orchestration → Query preprocessing: rewrites query (evidence: `README.md`)
- Request orchestration → RAG retrieval: retrieves context (evidence: `README.md`)
- RAG retrieval → Query embeddings: embeds query (evidence: `app.py`)
- RAG retrieval → FAISS index: searches index (evidence: `README.md`)
- RAG retrieval → Document store: reads chunks (evidence: `README.md`)
- Hospital and medicine data → FAISS index: builds offline (evidence: `README.md`)
- Hospital and medicine data → Document store: builds offline (evidence: `README.md`)
- Request orchestration → Answer generation: generates answer (evidence: `README.md`)
- Answer generation → Groq text LLM: prompts (evidence: `README.md`)
- Request orchestration → Session memory and history: uses session state (evidence: `README.md`)
- Request orchestration → Image analysis: routes image (evidence: `README.md`)
- Image analysis → Groq vision LLM: analyzes image (evidence: `README.md`)
- Request orchestration → Chat and history UI: returns answer (evidence: `README.md`)
