# kattapoornachandu/medical-chat-bot architecture

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

- Interactive diagram: https://gitdiagram.com/kattapoornachandu/medical-chat-bot
- Repository: https://github.com/kattapoornachandu/medical-chat-bot

## Overview

##### Project type and purpose
- This is a Python-based “medical-chat-bot” prototype. It doesn’t have a separate frontend folder, so it appears to be a single-process application—likely a command-line or lightweight web service (app.py) that orchestrates conversational logic by calling an external LLM (e.g., OpenAI Chat API).
- The `research/` folder holds exploratory notebooks and tests, indicating that the core business logic lives under `app.py`, `template.py`, and the modules in `src/`.

##### File structure
– Top-level:
- app.py (application entrypoint, likely defines CLI or HTTP endpoints)
- template.py (prompt templates or message formatting)
- requirements.txt & setup.py (dependency management and packaging)
- src/
– helper.py (utility functions, I/O, parsing)
– prompt.py (builds or enriches prompts before sending them to the LLM)
- research/ (notebooks and trial scripts used during R&D, not part of the running service)
– No database folder or config files beyond requirements, suggesting no persistent store—state is ephemeral or file-based.

##### README
- It only names the project “medical-chat-bot,” confirming its domain: automated medical Q&A or triage via chat.

##### Main components
a. User Interface
- CLI client or Web client (browser or terminal)—where user enters medical queries
b. Application Server (app.py)
- Routes or command handlers
- Orchestrates calls to internal modules and external APIs
c. Business-Logic Modules
- prompt.py (constructs the chat prompt, inserts templates, handles system/user roles)
- helper.py (parsing user input, formatting LLM output, utility routines)
- template.py (predefined message skeletons for medical contexts)
d. External Service
- LLM Provider API (e.g., OpenAI Chat API)
e. Development/Research Layer (not in the production path)
- Jupyter notebooks (`research/trials.ipynb`) and test scripts

##### Relationships and interactions
– User submits a query → UI
– UI → Application Server (app.py)
– app.py → prompt.py (builds request payload)
– prompt.py + template.py → request is sent to External LLM API
– LLM API returns response → app.py
– app.py → helper.py (post-process, safety checks, format)
– helper.py → UI (display to user)
– research components run offline against src/ for prototyping only

##### Architectural patterns and principles
– Layered (UI → Controller/Orchestrator → Domain Logic → External Service)
– Single-process monolith (no microservices or database tier)
– Separation of concerns: templating, prompt construction, and utility functions decoupled into modules
– Dependency management via requirements.txt and setup.py for packaging

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interface Layer
    UI["User Interface<br/>(CLI or Web Client)"]:::ui

    %% Application Server Container
    subgraph "Application Server" 
        direction TB
        App["app.py<br/>(Entry & Orchestrator)"]:::internal
        Prompt["prompt.py"]:::internal
        Helper["helper.py"]:::internal
        Template["template.py"]:::internal
    end

    %% External Service
    LLM["LLM Provider API"]:::external

    %% Operations / Packaging
    subgraph "Operations"
        direction TB
        Requirements["requirements.txt"]:::artifact
        Setup["setup.py"]:::artifact
    end

    %% Research Layer (Offline)
    subgraph "Research Layer"
        direction TB
        style ResearchLayer stroke-dasharray: 5 5,stroke:gray
        Notebooks["research/trials.ipynb"]:::research
        Tests["research/trials.ipynbtest.py"]:::research
    end

    %% Flows
    UI -->|"CLI I/O or HTTP"| App
    App -->|"build prompt"| Prompt
    Prompt -->|"use templates"| Template
    Prompt -->|"send HTTP/REST request"| LLM
    LLM -->|"response"| App
    App -->|"post-process"| Helper
    Helper -->|"display result"| UI

    %% Offline flows
    Notebooks -.->|tests against modules| Prompt
    Tests -.->|tests against modules| Helper

    %% Click Events
    click App "https://github.com/kattapoornachandu/medical-chat-bot/blob/main/app.py"
    click Prompt "https://github.com/kattapoornachandu/medical-chat-bot/blob/main/src/prompt.py"
    click Helper "https://github.com/kattapoornachandu/medical-chat-bot/blob/main/src/helper.py"
    click Template "https://github.com/kattapoornachandu/medical-chat-bot/blob/main/template.py"
    click Requirements "https://github.com/kattapoornachandu/medical-chat-bot/blob/main/requirements.txt"
    click Setup "https://github.com/kattapoornachandu/medical-chat-bot/blob/main/setup.py"
    click Notebooks "https://github.com/kattapoornachandu/medical-chat-bot/blob/main/research/trials.ipynb"
    click Tests "https://github.com/kattapoornachandu/medical-chat-bot/blob/main/research/trials.ipynbtest.py"

    %% Styles
    classDef ui fill:#e0f7fa,stroke:#006064,color:#000;
    classDef internal fill:#e8f5e9,stroke:#2e7d32,color:#000;
    classDef external fill:#e3f2fd,stroke:#1565c0,color:#000;
    classDef artifact fill:#f3e5f5,stroke:#6a1b9a,color:#000;
    classDef research fill:#eceff1,stroke:#90a4ae,color:#000,stroke-dasharray: 2 2;
```
