# priyank-mali/medical-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/priyank-mali/medical-chatbot
- Repository: https://github.com/priyank-mali/medical-chatbot

## Overview

##### Project type and purpose
- This is a Python-based question-answering “medical chatbot” service. It ingests PDF medical books, transforms them into embeddings stored in a local Chroma vector database, then answers user queries by retrieving relevant passages and calling an LLM (e.g. OpenAI).
- It is not a full MVC web app with a separate frontend codebase; it’s primarily a backend/chat microservice exposed via `app.py` (likely a FastAPI or Flask app), with helper modules for vectorization (`vector.py`) and the chat logic (`chatbot.py`), plus a Dockerfile for containerization.

##### File structure
- Top-level scripts
– `app.py`: entry point exposing HTTP endpoints (the “presentation layer”).
– `chatbot.py`: core logic for orchestrating retrieval + LLM calls (the “domain/service layer”).
– `vector.py`: embedding utilities for text/document vectorization.
- Data folders
– `medical_books/`: raw PDF sources.
– `medical_chromadb/`: persisted ChromaDB folder (SQLite file + binary index files).
- Infra/config
– `Dockerfile`: container definition.
– `requirements.txt`: Python dependencies (e.g. Chroma, OpenAI SDK, FastAPI/Flask).

##### Key insights from README
- Minimal README, but artifact names and file structure clearly point to a retrieval-augmented generation (RAG) pipeline specialized for medical text.

a. Main components
1. User Interface / Client (CLI or HTTP client)
2. API Layer (`app.py`)
3. Chatbot Service (`chatbot.py`)
4. Embedding Service (`vector.py`)
5. Vector Store (ChromaDB directory + SQLite)
6. External LLM Service (OpenAI)
7. Data Store (raw PDFs in `medical_books/`)
8. Container Environment (Docker)

b. Relationships & data flow
- User → HTTP POST `/chat` → API Layer (app.py)
- API Layer calls Chatbot Service
- Chatbot Service invokes Embedding Service to embed the query
- Embedding Service queries Vector Store for top-K passages
- Chatbot Service composes prompt with retrieved passages
- Chatbot Service calls External LLM API → receives answer
- API Layer returns answer to User

c. Architectural patterns / design principles
- Layered architecture: Presentation (app.py) → Domain/Service (chatbot.py) → Data/Storage (ChromaDB)
- Separation of concerns: embedding logic isolated in `vector.py`; business rules in `chatbot.py`; transport in `app.py`
- Containerized deployment for reproducibility (Dockerfile)

d. Key technologies & libraries
- Python 3.x, FastAPI or Flask
- ChromaDB (vector database, SQLite backend)
- OpenAI (LLM API)
- Docker

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Docker container boundary
    subgraph "Docker Container"
        direction TB
        API["API Layer<br/>(app.py)"]:::internal
        Chatbot["Chatbot Service<br/>(chatbot.py)"]:::internal
        Embedding["Embedding Service<br/>(vector.py)"]:::internal
        VS["Vector Store<br/>(ChromaDB + SQLite)"]:::data
        DS["Data Store<br/>(Raw PDF Medical Books)"]:::data
        Config["Dependencies<br/>(requirements.txt)"]:::internal
        ContainerEnv["Container Env<br/>(Dockerfile)"]:::internal
    end

    User["User (HTTP Client)"]:::external
    LLM["External LLM API<br/>(OpenAI)"]:::external

    User -->|POST /chat| API
    API -->|query| Chatbot
    Chatbot -->|embed query| Embedding
    Embedding -->|embedding vector| VS
    VS -->|retrieved passages| Chatbot
    Chatbot -->|compose prompt| LLM
    Chatbot -.->|LLM call| LLM
    LLM -.->|LLM response| Chatbot
    Chatbot -->|answer| API
    API -->|HTTP response| User

    click API "https://github.com/priyank-mali/medical-chatbot/blob/main/app.py"
    click Chatbot "https://github.com/priyank-mali/medical-chatbot/blob/main/chatbot.py"
    click Embedding "https://github.com/priyank-mali/medical-chatbot/blob/main/vector.py"
    click VS "https://github.com/priyank-mali/medical-chatbot/tree/main/medical_chromadb/"
    click DS "https://github.com/priyank-mali/medical-chatbot/tree/main/medical_books/"
    click ContainerEnv "https://github.com/priyank-mali/medical-chatbot/tree/main/Dockerfile"
    click Config "https://github.com/priyank-mali/medical-chatbot/blob/main/requirements.txt"

    classDef internal fill:#cce5ff,stroke:#000,stroke-width:1px
    classDef data fill:#d4edda,stroke:#000,stroke-width:1px
    classDef external fill:#fff3cd,stroke:#000,stroke-width:1px
```
