# bweezen/healthbot architecture

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

- Interactive diagram: https://gitdiagram.com/bweezen/healthbot
- Repository: https://github.com/bweezen/healthbot

## Overview

##### Project type and purpose
- This is a lightweight Python-based health chatbot application. It uses NLP and machine-learning to identify diseases from user-provided symptoms.
- Key indicators: model.py (training pipeline), chatbot.py (inference logic), app.py (Streamlit front end), README mentions NLTK, FuzzyWuzzy, scikit, Streamlit.

##### File structure
- Top-level files:
- model.py – builds and serializes the disease-prediction model and symptom list (outputs disease_model.pkl, symptom_list.pkl into a models/ directory).
- chatbot.py – contains the inference/chat logic: loads the pickled model and symptom list, accepts user input, cleans text, matches symptoms, and predicts diseases.
- app.py – Streamlit front end serving the chat interface and visualization of results.
- README.md – usage instructions and tech stack.
- No additional directories, so models/ is implicit; you may want to explicitly add it to the file tree.

##### README for additional insights
- Workflow: train once with model.py, then serve via Streamlit using app.py.
- Main components: disease_model.pkl (primary model), symptom_list.pkl (data source for matching).
- Dependencies: Python, NLTK (tokenization), FuzzyWuzzy (fuzzy matching), scikit-learn (ML), Streamlit (UI).

##### Elements
- Clear labels for each component (e.g., “Model Trainer”, “Model Artifacts”, “Chatbot Engine”, “Streamlit UI”).
- From “Model Trainer” → “Model Artifacts”
- From “Streamlit UI” → “Chatbot Engine” → “Model Artifacts”
- From “Chatbot Engine” → “Streamlit UI” (predictions back to user).
- Training layer (e.g., blue)
- Inference layer (e.g., green)
- Presentation layer (e.g., orange)

##### Detailed breakdown for each component
- Model Trainer (model.py)
- Inputs: raw dataset (symptoms ↔ diseases)
- Processing: tokenization (NLTK), vectorization, model fitting (scikit-learn)
- Outputs: pickle files
- Model Artifacts (models/)
- disease_model.pkl – the trained classifier
- symptom_list.pkl – list of known symptoms
- Chatbot Engine (chatbot.py)
- Loads pickles, uses FuzzyWuzzy to match user symptom text to list, predicts disease with loaded model
- Streamlit UI (app.py)
- Accepts text input via web form
- Calls chatbot engine functions
- Displays predicted disease and confidence

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Training Layer
    subgraph "Training Layer"
        direction TB
        ModelTrainer("Model Trainer"):::training
        ModelArtifacts[(Model Artifacts)]:::artifact
    end

    %% Inference Layer
    subgraph "Inference Layer"
        direction TB
        StreamlitUI("Streamlit UI"):::presentation
        ChatbotEngine("Chatbot Engine"):::inference
    end

    %% End User
    User["End User"]

    %% Connections
    ModelTrainer -->|"serializes pickles"| ModelArtifacts
    StreamlitUI -->|"calls inference"| ChatbotEngine
    ChatbotEngine -->|"loads pickles"| ModelArtifacts
    ChatbotEngine -->|"returns predictions"| StreamlitUI
    User -->|"interacts via UI"| StreamlitUI
    StreamlitUI -->|"displays results"| User

    %% Click Events
    click ModelTrainer "https://github.com/bweezen/healthbot/blob/main/model.py"
    click ModelArtifacts "https://github.com/bweezen/healthbot/tree/main/models/"
    click ChatbotEngine "https://github.com/bweezen/healthbot/blob/main/chatbot.py"
    click StreamlitUI "https://github.com/bweezen/healthbot/blob/main/app.py"

    %% Styles
    classDef training fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef inference fill:#90EE90,stroke:#333,stroke-width:1px
    classDef presentation fill:#FFA500,stroke:#333,stroke-width:1px
    classDef artifact fill:#FFD700,stroke:#333,stroke-width:1px
```
