# krishnakantdev/chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/krishnakantdev/chatbot
- Repository: https://github.com/krishnakantdev/chatbot

## Overview

This repository is a pharmaceutical-document RAG chatbot with Streamlit and FastAPI entry points. Both initialize a shared QA chain from a local drug-manual PDF, then pass user questions to it and return generated answers. The RAG module loads and chunks the manual, creates a FAISS index using Hugging Face embeddings, and configures retrieval with a Groq chat model. The graph reflects calls and configuration visible in the excerpts; the internal runtime behavior of the LangChain retrieval chain is represented only where its configuration is explicit.

Main entry points: [`rag.py`](https://github.com/krishnakantdev/chatbot/blob/main/rag.py) (QA chain builder), [`app.py`](https://github.com/krishnakantdev/chatbot/blob/main/app.py) (Streamlit chat), [`api.py`](https://github.com/krishnakantdev/chatbot/blob/main/api.py) (FastAPI endpoint), [`data/drug_manual.pdf`](https://github.com/krishnakantdev/chatbot/blob/main/data/drug_manual.pdf) (Drug manual)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_streamlit["Streamlit chat<br/>[app.py]"]
  node_fastapi["FastAPI endpoint<br/>[api.py]"]
end

subgraph group_rag["RAG Pipeline"]
  node_qa["QA chain builder<br/>[rag.py]"]
  node_loader["PDF loader<br/>[rag.py]"]
  node_manual["Drug manual<br/>[drug_manual.pdf]"]
  node_splitter["Chunk splitter<br/>[rag.py]"]
  node_vector[("FAISS index<br/>[rag.py]")]
  node_embeddings["Hugging Face embeddings<br/>[rag.py]"]
  node_retriever["Document retriever<br/>[rag.py]"]
  node_chain["Retrieval QA<br/>[rag.py]"]
  node_groq["Groq chat model<br/>[rag.py]"]
end

node_user(("Chat user"))

node_user -->|"asks"| node_streamlit
node_streamlit -->|"builds chain"| node_qa
node_streamlit -->|"submits question"| node_chain
node_qa -->|"loads documents"| node_loader
node_loader -->|"reads PDF"| node_manual
node_qa -->|"splits documents"| node_splitter
node_qa -->|"creates index"| node_vector
node_vector -->|"embeds chunks"| node_embeddings
node_qa -->|"configures retrieval"| node_retriever
node_retriever -->|"searches index"| node_vector
node_qa -->|"configures model"| node_groq
node_qa -->|"builds chain"| node_chain
node_chain -->|"uses retriever"| node_retriever
node_chain -->|"uses model"| node_groq
node_user -->|"asks"| node_fastapi
node_fastapi -->|"builds chain"| node_qa
node_fastapi -->|"submits question"| node_chain

click node_streamlit "https://github.com/krishnakantdev/chatbot/blob/main/app.py"
click node_fastapi "https://github.com/krishnakantdev/chatbot/blob/main/api.py"
click node_qa "https://github.com/krishnakantdev/chatbot/blob/main/rag.py"
click node_loader "https://github.com/krishnakantdev/chatbot/blob/main/rag.py"
click node_manual "https://github.com/krishnakantdev/chatbot/blob/main/data/drug_manual.pdf"
click node_splitter "https://github.com/krishnakantdev/chatbot/blob/main/rag.py"
click node_vector "https://github.com/krishnakantdev/chatbot/blob/main/rag.py"
click node_embeddings "https://github.com/krishnakantdev/chatbot/blob/main/rag.py"
click node_retriever "https://github.com/krishnakantdev/chatbot/blob/main/rag.py"
click node_chain "https://github.com/krishnakantdev/chatbot/blob/main/rag.py"
click node_groq "https://github.com/krishnakantdev/chatbot/blob/main/rag.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_fastapi,node_user toneBlue
class node_qa,node_loader,node_manual,node_splitter,node_vector,node_embeddings,node_retriever,node_chain,node_groq toneAmber
```

## Components

### User Interfaces

- [Streamlit chat](https://github.com/krishnakantdev/chatbot/blob/main/app.py): `app.py`
- [FastAPI endpoint](https://github.com/krishnakantdev/chatbot/blob/main/api.py): `api.py`

### RAG Pipeline

- [QA chain builder](https://github.com/krishnakantdev/chatbot/blob/main/rag.py): `rag.py`
- [PDF loader](https://github.com/krishnakantdev/chatbot/blob/main/rag.py): `rag.py`
- [Drug manual](https://github.com/krishnakantdev/chatbot/blob/main/data/drug_manual.pdf): `data/drug_manual.pdf`
- [Chunk splitter](https://github.com/krishnakantdev/chatbot/blob/main/rag.py): `rag.py`
- [FAISS index](https://github.com/krishnakantdev/chatbot/blob/main/rag.py): `rag.py`
- [Hugging Face embeddings](https://github.com/krishnakantdev/chatbot/blob/main/rag.py): `rag.py`
- [Document retriever](https://github.com/krishnakantdev/chatbot/blob/main/rag.py): `rag.py`
- [Retrieval QA](https://github.com/krishnakantdev/chatbot/blob/main/rag.py): `rag.py`
- [Groq chat model](https://github.com/krishnakantdev/chatbot/blob/main/rag.py): `rag.py`

### Other components

- **Chat user**

## Connections

- Chat user → Streamlit chat: asks (evidence: `app.py`)
- Streamlit chat → QA chain builder: builds chain (evidence: `app.py`)
- Streamlit chat → Retrieval QA: submits question (evidence: `app.py`)
- QA chain builder → PDF loader: loads documents (evidence: `rag.py`)
- PDF loader → Drug manual: reads PDF (evidence: `rag.py`)
- QA chain builder → Chunk splitter: splits documents (evidence: `rag.py`)
- QA chain builder → FAISS index: creates index (evidence: `rag.py`)
- FAISS index → Hugging Face embeddings: embeds chunks (evidence: `rag.py`)
- QA chain builder → Document retriever: configures retrieval (evidence: `rag.py`)
- Document retriever → FAISS index: searches index (evidence: `rag.py`)
- QA chain builder → Groq chat model: configures model (evidence: `rag.py`)
- QA chain builder → Retrieval QA: builds chain (evidence: `rag.py`)
- Retrieval QA → Document retriever: uses retriever (evidence: `rag.py`)
- Retrieval QA → Groq chat model: uses model (evidence: `rag.py`)
- Chat user → FastAPI endpoint: asks (evidence: `api.py`)
- FastAPI endpoint → QA chain builder: builds chain (evidence: `api.py`)
- FastAPI endpoint → Retrieval QA: submits question (evidence: `api.py`)
