# rithwikthirumalaraju14/medchatbot architecture

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

- Interactive diagram: https://gitdiagram.com/rithwikthirumalaraju14/medchatbot
- Repository: https://github.com/rithwikthirumalaraju14/medchatbot

## Overview

##### Main Components
- Web Interface & API: Represented primarily by app.py together with the Flask templates (in the templates folder) and static assets (in the static folder).
- Backend Processing Modules: Include the modules in src (prompt.py and helper.py) that generate prompts and perform processing.
- Persistent Context Storage: The client directory contains ChromaDB-related files (SQLite file and binary assets) that are used to store conversation context.
- External LLM Service: The integration with GROQ’s Llama-3.1-70B model, which is used for generating responses.
- Configuration & Dependencies: Files such as .env and requirements.txt should be noted to understand configuration and external dependencies.
- Utility Files: Additional files like store.py and trying_chat_templates.py can be indicated as support or layer components to facilitate data management or experimental UI components.
- Static Medical Data: The “data” folder (e.g., Medical_book.pdf) might be used as a reference or source of additional information.

##### Out the Interactions
- Web Routing & API: Show that the Flask server handles both HTML-based requests (rendering chat.html) and REST API calls (e.g., the “/get” endpoint).
- Chatbot Processing Flow:
◦ On receiving an input, the Flask app may call functions in the src directory (prompt.py and helper.py) to build the prompt.
◦ The prompt is sent to the GROQ Llama-3.1-70B external service (likely via LangChain integration).
◦ Concurrently, context data is retrieved from or stored into the ChromaDB system, which is represented by the files in the client directory.
- Response Flow: The generated response is then routed back from the external language model through the Flask app to the web client.

##### Architectural Patterns and Technologies
- MVC Pattern: Although it’s simple, note that Flask acts as the controller and view, while the src modules act as business logic layers.
- REST API and Web Frontend Separation: Clearly denote the two interaction types (web and API).
- External Service Integration: Show the linkage to the GROQ language model service, indicating that this is an external dependency.
- Persistent Storage: Emphasize how ChromaDB (with its client data) is crucial for maintaining conversation context.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    User["User / Web Browser"]:::frontend

    %% Web Layer
    Flask["Flask Web Server (app.py)"]:::backend
    WebTemplate["Web Templates (templates/chat.html)"]:::frontend
    StaticAssets["Static Assets (static/style.css)"]:::frontend

    %% Business Logic
    subgraph "Backend Processing Modules"
        Prompt["Prompt Module (src/prompt.py)"]:::business
        Helper["Helper Module (src/helper.py)"]:::business
    end

    %% External LLM Service
    LLM["GROQ Llama-3.1-70B Service (External LLM)"]:::external

    %% Persistence & Configuration
    subgraph "Persistence & Config"
        Storage["ChromaDB Storage (client)"]:::storage
        ConfigEnv["Configuration (.env)"]:::config
        Dependencies["Dependencies (requirements.txt)"]:::config
        StaticData["Medical Data (data/Medical_book.pdf)"]:::data
    end

    %% Utility Files
    subgraph "Utility Files"
        UtilityStore["Utility: store.py"]:::utility
        UtilityTemplates["Utility: trying_chat_templates.py"]:::utility
    end

    %% Data Flow
    User -->|"client_request"| Flask
    Flask -->|"render_view"| WebTemplate
    Flask -->|"deliver_assets"| StaticAssets
    Flask -->|"get_context"| Storage
    Storage -- "provide_context" --> Flask
    Flask -->|"build_prompt"| Prompt
    Prompt -->|"send_query"| LLM
    LLM -->|"receive_response"| Prompt
    Prompt -->|"return_chat_result"| Flask
    Flask -->|"return_response"| User

    %% Config & Utility Support
    ConfigEnv -->|"load_config"| Flask
    Dependencies -->|"load_dependencies"| Flask
    Flask ---|"support"| UtilityStore
    Flask ---|"support"| UtilityTemplates

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#F4A460,stroke:#000,stroke-width:2px;
    classDef business fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef external fill:#FF7F7F,stroke:#000,stroke-width:2px;
    classDef storage fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef config fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef utility fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef data fill:#FFB6C1,stroke:#000,stroke-width:2px;

    %% Click Events
    click Flask "https://github.com/rithwikthirumalaraju14/medchatbot/blob/main/app.py"
    click WebTemplate "https://github.com/rithwikthirumalaraju14/medchatbot/blob/main/templates/chat.html"
    click StaticAssets "https://github.com/rithwikthirumalaraju14/medchatbot/blob/main/static/style.css"
    click Prompt "https://github.com/rithwikthirumalaraju14/medchatbot/blob/main/src/prompt.py"
    click Helper "https://github.com/rithwikthirumalaraju14/medchatbot/blob/main/src/helper.py"
    click Storage "https://github.com/rithwikthirumalaraju14/medchatbot/tree/main/client"
    click ConfigEnv "https://github.com/rithwikthirumalaraju14/medchatbot/blob/main/.env"
    click Dependencies "https://github.com/rithwikthirumalaraju14/medchatbot/blob/main/requirements.txt"
    click UtilityStore "https://github.com/rithwikthirumalaraju14/medchatbot/blob/main/store.py"
    click UtilityTemplates "https://github.com/rithwikthirumalaraju14/medchatbot/blob/main/trying_chat_templates.py"
    click StaticData "https://github.com/rithwikthirumalaraju14/medchatbot/blob/main/data/Medical_book.pdf"
```
