# harshar-ctrl/bot_workshop architecture

> Architecture diagram of the GitHub repository harshar-ctrl/bot_workshop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harshar-ctrl/bot_workshop
- Repository: https://github.com/harshar-ctrl/bot_workshop

## Overview

This is a small teaching chatbot with two user-facing workflows: terminal input and a Gradio browser chat. Both load a Groq API key and system prompt from .env, construct conversation context, and request replies from Groq through the OpenAI-compatible client. The terminal version keeps history in a list and prints complete replies; the web version uses Gradio history and streams incremental replies. The graph reflects the sampled scripts and README; no separate persistence layer is present.

Main entry points: [`chatbot_web.py`](https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot_web.py) (Web context builder), [`chatbot.py`](https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot.py) (Groq API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_terminal["Terminal chat"]
  node_terminal_loop["Terminal loop<br/>[chatbot.py]"]
  node_terminal_history["Conversation history<br/>[chatbot.py]"]
end

subgraph group_web["Browser chat"]
  node_web_ui["Chat interface<br/>[chatbot_web.py]"]
  node_web_context["Web context builder<br/>[chatbot_web.py]"]
end

subgraph group_shared["Model access"]
  node_settings["Environment settings<br/>[chatbot.py]"]
  node_groq_client["Groq API client<br/>[chatbot.py]"]
end

node_person(("Chat user"))
node_groq_service["Groq service"]

node_person -->|"types messages"| node_terminal_loop
node_terminal_loop -->|"calls ask_ai"| node_terminal_history
node_terminal_history -->|"sends context"| node_groq_client
node_groq_client -->|"requests completion"| node_groq_service
node_groq_service -->|"returns reply"| node_groq_client
node_terminal_loop -->|"prints reply"| node_person
node_person -->|"chats in browser"| node_web_ui
node_web_ui -->|"calls respond"| node_web_context
node_web_context -->|"streams completion"| node_groq_service
node_groq_service -->|"returns chunks"| node_web_context
node_settings -->|"supplies key"| node_groq_client
node_web_context -->|"uses prompt"| node_settings

click node_terminal_loop "https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot.py"
click node_terminal_history "https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot.py"
click node_web_ui "https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot_web.py"
click node_web_context "https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot_web.py"
click node_settings "https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot.py"
click node_groq_client "https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_terminal_loop,node_terminal_history,node_person toneBlue
class node_web_ui,node_web_context toneAmber
class node_settings,node_groq_client toneMint
class node_groq_service toneIndigo
```

## Components

### Terminal chat

- [Terminal loop](https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot.py): `chatbot.py`
- [Conversation history](https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot.py): `chatbot.py`

### Browser chat

- [Chat interface](https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot_web.py): `chatbot_web.py`
- [Web context builder](https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot_web.py): `chatbot_web.py`

### Model access

- [Environment settings](https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot.py): `chatbot.py`
- [Groq API client](https://github.com/harshar-ctrl/bot_workshop/blob/main/chatbot.py): `chatbot.py`

### Other components

- **Chat user**
- **Groq service**

## Connections

- Chat user → Terminal loop: types messages (evidence: `README.md`)
- Terminal loop → Conversation history: calls ask_ai (evidence: `chatbot.py`)
- Conversation history → Groq API client: sends context (evidence: `chatbot.py`)
- Groq API client → Groq service: requests completion (evidence: `chatbot.py`)
- Groq service → Groq API client: returns reply (evidence: `chatbot.py`)
- Terminal loop → Chat user: prints reply (evidence: `chatbot.py`)
- Chat user → Chat interface: chats in browser (evidence: `README.md`)
- Chat interface → Web context builder: calls respond (evidence: `chatbot_web.py`)
- Web context builder → Groq service: streams completion (evidence: `chatbot_web.py`)
- Groq service → Web context builder: returns chunks (evidence: `chatbot_web.py`)
- Environment settings → Groq API client: supplies key (evidence: `chatbot.py`)
- Web context builder → Environment settings: uses prompt (evidence: `chatbot_web.py`)
