# heeetz/twitch-bot architecture

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

- Interactive diagram: https://gitdiagram.com/heeetz/twitch-bot
- Repository: https://github.com/heeetz/twitch-bot

## Overview

Twitch Bot is a single-channel chat bot paired with a pywebview desktop control panel. The primary workflow receives Twitch chat, records presence and applies filters, then dispatches built-in or custom commands through permission and cooldown checks to domain services and chat output. The desktop workflow configures those runtime controls through a Python bridge. README capabilities are represented, including weather, followage, Gemini memory, filters, settings, logs, and tray controls; some subsystem links rely on README documentation because their implementation was not sampled.

Main entry points: [`app/webview_host.py`](https://github.com/heeetz/twitch-bot/blob/main/app/webview_host.py) (Desktop host and API), [`app/commands/registry.py`](https://github.com/heeetz/twitch-bot/blob/main/app/commands/registry.py) (Command dispatch), [`app/twitch/client.py`](https://github.com/heeetz/twitch-bot/blob/main/app/twitch/client.py) (Twitch connection), [`app/services/gemini_ai_service.py`](https://github.com/heeetz/twitch-bot/blob/main/app/services/gemini_ai_service.py) (Gemini responses)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat["Twitch chat runtime"]
  node_twitch["Twitch connection<br/>[client.py]"]
  node_events["Chat event types<br/>[events.py]"]
  node_dispatcher["Command dispatch<br/>[registry.py]"]
  node_permissions["Role permissions<br/>[permissions.py]"]
  node_cooldowns["Cooldown tracking<br/>[cooldown.py]"]
  node_commands["Built-in commands<br/>[registry.py]"]
  node_custom["Custom commands<br/>[custom_commands.py]"]
  node_ai_command["Ask command<br/>[ai.py]"]
end

subgraph group_services["Domain services"]
  node_presence[("Seen-user records<br/>[repository.py]")]
  node_filters["Message filters<br/>[filter_manager.py]"]
  node_weather["Weather lookup<br/>[weather.py]"]
  node_followage["Followage lookup<br/>[twitch.py]"]
  node_ai_policy["AI request policy"]
  node_gemini["Gemini responses"]
  node_memory[("Conversation memory<br/>[memory.py]")]
end

subgraph group_state["Settings and persistence"]
  node_database[("SQLite data<br/>[database.py]")]
  node_runtime["Runtime controls<br/>[runtime_state.py]"]
  node_config["App configuration<br/>[settings.py]"]
  node_personalities["AI personalities<br/>[personalities.py]"]
  node_command_settings["Command overrides"]
  node_filter_settings["Filter settings<br/>[filter_settings.py]"]
end

subgraph group_desktop["Desktop control panel"]
  node_host["Desktop host and API<br/>[webview_host.py]"]
  node_frontend["Control panel<br/>[App.tsx]"]
  node_bridge["Python API client<br/>[bridge.ts]"]
  node_logs["Recent log buffer<br/>[logging.py]"]
  node_tray["System tray<br/>[system_tray.py]"]
end

node_twitch_user(("Chat participants"))
node_twitch_api["Twitch API"]
node_open_meteo["Open-Meteo"]
node_google["Google Gen AI"]

node_twitch_user -->|"sends chat"| node_twitch
node_twitch -->|"receives events"| node_events
node_twitch -->|"records users"| node_presence
node_twitch -->|"dispatches chat"| node_dispatcher
node_dispatcher -.->|"applies filters"| node_filters
node_dispatcher -->|"checks roles"| node_permissions
node_dispatcher -->|"checks cooldowns"| node_cooldowns
node_dispatcher -->|"dispatches built-ins"| node_commands
node_dispatcher -->|"dispatches custom"| node_custom
node_commands -.->|"looks up weather"| node_weather
node_commands -.->|"looks up followage"| node_followage
node_commands -.->|"includes ask"| node_ai_command
node_ai_command -->|"checks requests"| node_ai_policy
node_ai_command -.->|"requests response"| node_gemini
node_gemini -.->|"uses memory"| node_memory
node_gemini -->|"builds instructions"| node_personalities
node_gemini -.->|"calls provider"| node_google
node_weather -.->|"queries weather"| node_open_meteo
node_followage -.->|"queries follows"| node_twitch_api
node_database -->|"stores records"| node_presence
node_host -->|"controls lifecycle"| node_twitch
node_host -->|"hosts interface"| node_frontend
node_frontend -->|"calls API"| node_bridge
node_bridge -->|"invokes Python API"| node_host
node_host -.->|"updates controls"| node_runtime
node_runtime -->|"loads overrides"| node_command_settings
node_host -.->|"manages settings"| node_config
node_host -.->|"manages filters"| node_filter_settings
node_host -->|"reads recent logs"| node_logs
node_frontend -->|"shows live logs"| node_logs
node_host -->|"coordinates tray"| node_tray

click node_twitch "https://github.com/heeetz/twitch-bot/blob/main/app/twitch/client.py"
click node_events "https://github.com/heeetz/twitch-bot/blob/main/app/twitch/events.py"
click node_presence "https://github.com/heeetz/twitch-bot/blob/main/app/database/repository.py"
click node_filters "https://github.com/heeetz/twitch-bot/blob/main/app/services/filter_manager.py"
click node_dispatcher "https://github.com/heeetz/twitch-bot/blob/main/app/commands/registry.py"
click node_permissions "https://github.com/heeetz/twitch-bot/blob/main/app/twitch/permissions.py"
click node_cooldowns "https://github.com/heeetz/twitch-bot/blob/main/app/utils/cooldown.py"
click node_commands "https://github.com/heeetz/twitch-bot/blob/main/app/commands/registry.py"
click node_custom "https://github.com/heeetz/twitch-bot/blob/main/app/custom_commands.py"
click node_weather "https://github.com/heeetz/twitch-bot/blob/main/app/services/weather.py"
click node_followage "https://github.com/heeetz/twitch-bot/blob/main/app/services/twitch.py"
click node_ai_command "https://github.com/heeetz/twitch-bot/blob/main/app/commands/ai.py"
click node_ai_policy "https://github.com/heeetz/twitch-bot/blob/main/app/services/ai_request_policy.py"
click node_gemini "https://github.com/heeetz/twitch-bot/blob/main/app/services/gemini_ai_service.py"
click node_memory "https://github.com/heeetz/twitch-bot/blob/main/app/services/memory.py"
click node_database "https://github.com/heeetz/twitch-bot/blob/main/app/database/database.py"
click node_runtime "https://github.com/heeetz/twitch-bot/blob/main/app/runtime_state.py"
click node_config "https://github.com/heeetz/twitch-bot/blob/main/app/config/settings.py"
click node_personalities "https://github.com/heeetz/twitch-bot/blob/main/app/config/personalities.py"
click node_command_settings "https://github.com/heeetz/twitch-bot/blob/main/app/command_settings.py"
click node_filter_settings "https://github.com/heeetz/twitch-bot/blob/main/app/filter_settings.py"
click node_host "https://github.com/heeetz/twitch-bot/blob/main/app/webview_host.py"
click node_frontend "https://github.com/heeetz/twitch-bot/blob/main/frontend/src/App.tsx"
click node_bridge "https://github.com/heeetz/twitch-bot/blob/main/frontend/src/bridge.ts"
click node_logs "https://github.com/heeetz/twitch-bot/blob/main/app/utils/logging.py"
click node_tray "https://github.com/heeetz/twitch-bot/blob/main/app/system_tray.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_twitch,node_events,node_dispatcher,node_permissions,node_cooldowns,node_commands,node_custom,node_ai_command toneBlue
class node_presence,node_filters,node_weather,node_followage,node_ai_policy,node_gemini,node_memory toneAmber
class node_database,node_runtime,node_config,node_personalities,node_command_settings,node_filter_settings,node_twitch_api toneMint
class node_host,node_frontend,node_bridge,node_logs,node_tray toneRose
class node_twitch_user,node_open_meteo,node_google toneIndigo
```

## Components

### Twitch chat runtime

- [Twitch connection](https://github.com/heeetz/twitch-bot/blob/main/app/twitch/client.py): `app/twitch/client.py`
- [Chat event types](https://github.com/heeetz/twitch-bot/blob/main/app/twitch/events.py): `app/twitch/events.py`
- [Command dispatch](https://github.com/heeetz/twitch-bot/blob/main/app/commands/registry.py): `app/commands/registry.py`
- [Role permissions](https://github.com/heeetz/twitch-bot/blob/main/app/twitch/permissions.py): `app/twitch/permissions.py`
- [Cooldown tracking](https://github.com/heeetz/twitch-bot/blob/main/app/utils/cooldown.py): `app/utils/cooldown.py`
- [Built-in commands](https://github.com/heeetz/twitch-bot/blob/main/app/commands/registry.py): `app/commands/registry.py`
- [Custom commands](https://github.com/heeetz/twitch-bot/blob/main/app/custom_commands.py): `app/custom_commands.py`
- [Ask command](https://github.com/heeetz/twitch-bot/blob/main/app/commands/ai.py): `app/commands/ai.py`

### Domain services

- [Seen-user records](https://github.com/heeetz/twitch-bot/blob/main/app/database/repository.py): `app/database/repository.py`
- [Message filters](https://github.com/heeetz/twitch-bot/blob/main/app/services/filter_manager.py): `app/services/filter_manager.py`
- [Weather lookup](https://github.com/heeetz/twitch-bot/blob/main/app/services/weather.py): `app/services/weather.py`
- [Followage lookup](https://github.com/heeetz/twitch-bot/blob/main/app/services/twitch.py): `app/services/twitch.py`
- [AI request policy](https://github.com/heeetz/twitch-bot/blob/main/app/services/ai_request_policy.py): `app/services/ai_request_policy.py`
- [Gemini responses](https://github.com/heeetz/twitch-bot/blob/main/app/services/gemini_ai_service.py): `app/services/gemini_ai_service.py`
- [Conversation memory](https://github.com/heeetz/twitch-bot/blob/main/app/services/memory.py): `app/services/memory.py`

### Settings and persistence

- [SQLite data](https://github.com/heeetz/twitch-bot/blob/main/app/database/database.py): `app/database/database.py`
- [Runtime controls](https://github.com/heeetz/twitch-bot/blob/main/app/runtime_state.py): `app/runtime_state.py`
- [App configuration](https://github.com/heeetz/twitch-bot/blob/main/app/config/settings.py): `app/config/settings.py`
- [AI personalities](https://github.com/heeetz/twitch-bot/blob/main/app/config/personalities.py): `app/config/personalities.py`
- [Command overrides](https://github.com/heeetz/twitch-bot/blob/main/app/command_settings.py): `app/command_settings.py`
- [Filter settings](https://github.com/heeetz/twitch-bot/blob/main/app/filter_settings.py): `app/filter_settings.py`

### Desktop control panel

- [Desktop host and API](https://github.com/heeetz/twitch-bot/blob/main/app/webview_host.py): `app/webview_host.py`
- [Control panel](https://github.com/heeetz/twitch-bot/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Python API client](https://github.com/heeetz/twitch-bot/blob/main/frontend/src/bridge.ts): `frontend/src/bridge.ts`
- [Recent log buffer](https://github.com/heeetz/twitch-bot/blob/main/app/utils/logging.py): `app/utils/logging.py`
- [System tray](https://github.com/heeetz/twitch-bot/blob/main/app/system_tray.py): `app/system_tray.py`

### Other components

- **Chat participants**
- **Twitch API**
- **Open-Meteo**
- **Google Gen AI**

## Connections

- Chat participants → Twitch connection: sends chat
- Twitch connection → Chat event types: receives events (evidence: `app/twitch/client.py`)
- Twitch connection → Seen-user records: records users (evidence: `app/twitch/client.py`)
- Twitch connection → Command dispatch: dispatches chat (evidence: `app/twitch/client.py`)
- Command dispatch → Message filters: applies filters
- Command dispatch → Role permissions: checks roles (evidence: `app/commands/registry.py`)
- Command dispatch → Cooldown tracking: checks cooldowns (evidence: `app/commands/registry.py`)
- Command dispatch → Built-in commands: dispatches built-ins (evidence: `app/commands/registry.py`)
- Command dispatch → Custom commands: dispatches custom (evidence: `app/commands/registry.py`)
- Built-in commands → Weather lookup: looks up weather
- Built-in commands → Followage lookup: looks up followage
- Built-in commands → Ask command: includes ask (evidence: `app/commands/ai.py`)
- Ask command → AI request policy: checks requests (evidence: `app/commands/ai.py`)
- Ask command → Gemini responses: requests response
- Gemini responses → Conversation memory: uses memory
- Gemini responses → AI personalities: builds instructions (evidence: `app/services/gemini_ai_service.py`)
- Gemini responses → Google Gen AI: calls provider
- Weather lookup → Open-Meteo: queries weather
- Followage lookup → Twitch API: queries follows
- SQLite data → Seen-user records: stores records (evidence: `app/database/database.py`)
- Desktop host and API → Twitch connection: controls lifecycle (evidence: `app/webview_host.py`)
- Desktop host and API → Control panel: hosts interface
- Control panel → Python API client: calls API (evidence: `frontend/src/App.tsx`)
- Python API client → Desktop host and API: invokes Python API
- Desktop host and API → Runtime controls: updates controls
- Runtime controls → Command overrides: loads overrides (evidence: `app/runtime_state.py`)
- Desktop host and API → App configuration: manages settings (evidence: `app/webview_host.py`)
- Desktop host and API → Filter settings: manages filters (evidence: `app/webview_host.py`)
- Desktop host and API → Recent log buffer: reads recent logs (evidence: `app/webview_host.py`)
- Control panel → Recent log buffer: shows live logs (evidence: `frontend/src/App.tsx`)
- Desktop host and API → System tray: coordinates tray (evidence: `app/webview_host.py`)
