# waleed719/fitness-chatbot architecture

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

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

## Overview

##### Project type and purpose
- This is a monolithic, single‐page web application built with Python and Streamlit.
- Purpose: provide an interactive AI Fitness Chatbot UI that accepts user questions, looks up predefined FAQs, or forwards questions to Google’s Gemini LLM via an HTTP API, then displays the response.
- It runs as one process (the Streamlit app) and has no internal database—knowledge comes either from a built-in dictionary or from the external LLM service.

##### File structure
- Top‐level artifacts:
- streamlit_app.py (main application entry point)
- requirements.txt & runtime.txt (dependency list and runtime spec for deployment e.g., Heroku)
- Procfile (Heroku or similar process launcher)
- .devcontainer/devcontainer.json (VS Code dev‐container configuration)
- .gitignore (source control)
- No “frontend” vs “backend” folders—the Streamlit script combines UI rendering and business logic.
- No database or persistence layers to represent.
- Configuration/environment management via python-dotenv (expects a .env file with GEMINI_API_KEY).

##### README for additional insights
- Confirms the use of:
- Streamlit for UI
- httpx for asynchronous HTTP calls to the Google Gemini API
- python-dotenv for loading secrets
- No mention of other microservices, queues, or caching layers.
- Deployment targets: Streamlit Community Cloud or a generic VM (Heroku example given).

##### Core components
a. User Client (Web Browser)
b. Streamlit App Server
– UI Component (Streamlit widgets & pages)
– Business Logic Component (input routing, FAQ lookup, LLM orchestration)
– Environment Loader (python-dotenv reading GEMINI_API_KEY)
c. Local FAQ Data Store (in‐memory Python dictionary)
d. External Service: Google Gemini LLM API
e. Deployment Environment (Heroku Dyno or Streamlit Cloud / VM / Container)

##### Relationships and data flows
1. User enters a question in the browser UI.
2. Streamlit server receives the request and passes it to the business logic layer.
3. Business logic checks the FAQ dictionary:
– If a match → returns static answer.
– Else → issues an HTTP request (via httpx, using the GEMINI_API_KEY) to the Gemini API.
4. Gemini API returns a generated response → business logic processes it → UI renders the answer back to the user.
5. All components run within the same process/container; secrets are injected at startup by python-dotenv.

##### Architectural patterns & principles
- Monolithic single‐process architecture—no microservices or database tiers.
- Separation of concerns within the script: UI vs business logic vs external API integration.
- Safe defaults: system prompts and disclaimers encoded in the logic.
- Externalization of secrets via .env.

##### Essential elements
- Clear component labels (e.g., “Streamlit App Server”, “Google Gemini API”).
- A border or grouping to denote the single deployment unit (the Streamlit process/Heroku dyno).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Browser
    Browser["User Browser"]:::ui

    %% Streamlit App Process Container
    subgraph "Streamlit App Process (Heroku Dyno / Container)"
        direction TB
        UIComponent["Streamlit UI Components"]:::ui
        BusinessLogic["Business Logic Layer"]:::logic
        FAQ["Local FAQ Data Store (in-memory dict)"]:::logic
        EnvLoader["Environment Loader (.env via python-dotenv)"]:::logic
    end

    %% External Service
    External["Google Gemini API"]:::external

    %% Development & Deployment Config
    Procfile["Procfile"]:::infra
    Runtime["runtime.txt"]:::infra
    DevContainer["Dev Container (.devcontainer)"]:::infra

    %% Flow of Requests and Data
    Browser -->|"HTTPS"| UIComponent
    UIComponent -->|"User question"| BusinessLogic
    BusinessLogic -->|"Lookup in FAQ dict"| FAQ
    BusinessLogic -->|"HTTP POST /generate"| External
    External -->|"Response JSON"| BusinessLogic
    BusinessLogic -->|"Render response"| UIComponent
    EnvLoader -->|".env → ENV"| BusinessLogic

    %% Config & Infrastructure Relationships
    Procfile -->|“launches process”| UIComponent
    Runtime -->|“runtime spec”| UIComponent
    DevContainer -->|“local dev env”| UIComponent

    %% Click Events
    click UIComponent "https://github.com/waleed719/fitness-chatbot/blob/main/streamlit_app.py"
    click BusinessLogic "https://github.com/waleed719/fitness-chatbot/blob/main/streamlit_app.py"
    click FAQ "https://github.com/waleed719/fitness-chatbot/blob/main/streamlit_app.py"
    click EnvLoader "https://github.com/waleed719/fitness-chatbot/blob/main/streamlit_app.py"
    click EnvLoader "https://github.com/waleed719/fitness-chatbot/blob/main/requirements.txt"
    click External "https://github.com/waleed719/fitness-chatbot/blob/main/streamlit_app.py"
    click External "https://github.com/waleed719/fitness-chatbot/blob/main/requirements.txt"
    click Procfile "https://github.com/waleed719/fitness-chatbot/tree/main/Procfile"
    click Runtime "https://github.com/waleed719/fitness-chatbot/blob/main/runtime.txt"
    click DevContainer "https://github.com/waleed719/fitness-chatbot/blob/main/.devcontainer/devcontainer.json"

    %% Styles
    classDef ui fill:#add8e6,stroke:#333,stroke-width:1px
    classDef logic fill:#90ee90,stroke:#333,stroke-width:1px
    classDef external fill:#ffa500,stroke:#333,stroke-width:1px
    classDef infra fill:#d3d3d3,stroke:#333,stroke-width:1px
```
