# sexlovr/discord-bot-fleet architecture

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

- Interactive diagram: https://gitdiagram.com/sexlovr/discord-bot-fleet
- Repository: https://github.com/sexlovr/discord-bot-fleet

## Overview

Discord Bot Fleet is a web control panel for configuring and operating multiple AI-powered Discord bots. The main workflow is panel/API requests to create or edit a bot, persist its configuration, start an isolated bot process, then handle Discord messages through an LLM and enabled tools. The graph also preserves live logs, channel discovery, encryption, and the separate Python REST-polling runtime represented in the source index. Relationships are limited to excerpted calls, source-index references, or README statements; unsampled details are not assumed.

Main entry points: [`src/server.ts`](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/server.ts) (HTTP and WS API), [`src/bot.ts`](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/bot.ts) (Node bot runtime), [`bot-python/bot.py`](https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/bot.py) (Python REST bot), [`src/manager.ts`](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/manager.ts) (Bot manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_panel["Panel and API"]
  node_webui["Web panel<br/>[app.js]"]
  node_server["HTTP and WS API<br/>[server.ts]"]
  node_channelpicker["Channel discovery<br/>[discord_helpers.ts]"]
end

subgraph group_operations["Fleet Operations"]
  node_manager["Bot manager<br/>[manager.ts]"]
  node_logger["Log streaming<br/>[logger.ts]"]
end

subgraph group_runtime["Bot Runtime"]
  node_nodebot["Node bot runtime<br/>[bot.ts]"]
  node_llm["LLM client<br/>[llm.ts]"]
  node_types["Bot configuration<br/>[types.ts]"]
  node_pythonbot["Python REST bot<br/>[bot.py]"]
  node_pythonrest["Discord REST client<br/>[discord_rest.py]"]
  node_pythonllm["Python LLM client<br/>[llm.py]"]
end

subgraph group_tools["Tools and Integrations"]
  node_registry["Tool registry<br/>[index.ts]"]
  node_websearch["Web search<br/>[web_search.ts]"]
  node_toolset["Other bot tools"]
  node_pythontools["Python tool registry<br/>[__init__.py]"]
end

subgraph group_state["Persistence and Security"]
  node_store[("Bot config store<br/>[store.ts]")]
  node_crypto["Token encryption<br/>[crypto.ts]"]
  node_logfiles[("Persistent logs<br/>[logger.ts]")]
  node_pythoncrypto["Python decryption<br/>[crypto.py]"]
  node_memory[("Per-bot memory<br/>[memory.ts]")]
end

node_admin(("Panel user"))
node_discord["Discord API"]
node_llmservice["LLM proxy"]

node_admin -->|"manages bots"| node_webui
node_webui -.->|"calls API"| node_server
node_server -->|"reads and writes"| node_store
node_server -->|"controls lifecycle"| node_manager
node_server -->|"validates tokens"| node_channelpicker
node_server -->|"tests proxy"| node_llm
node_server -->|"encrypts tokens"| node_crypto
node_server -->|"serves live logs"| node_logger
node_channelpicker -->|"fetches channels"| node_discord
node_manager -->|"loads config"| node_store
node_manager -->|"spawns process"| node_nodebot
node_manager -->|"pipes output"| node_logger
node_nodebot -->|"loads bot config"| node_store
node_nodebot -->|"requests responses"| node_llm
node_nodebot -->|"dispatches tools"| node_registry
node_nodebot -.->|"handles messages"| node_discord
node_llm -->|"sends chat requests"| node_llmservice
node_llm -->|"decrypts API key"| node_crypto
node_registry -->|"dispatches search"| node_websearch
node_registry -->|"dispatches tools"| node_toolset
node_toolset -->|"reads and writes"| node_memory
node_pythonbot -->|"requests responses"| node_pythonllm
node_pythonbot -->|"dispatches tools"| node_pythontools
node_pythonbot -.->|"polls and replies"| node_pythonrest
node_pythonllm -->|"decrypts API key"| node_pythoncrypto
node_pythonbot -->|"loads bot config"| node_store

click node_webui "https://github.com/sexlovr/discord-bot-fleet/blob/main/web/static/app.js"
click node_server "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/server.ts"
click node_channelpicker "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/discord_helpers.ts"
click node_manager "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/manager.ts"
click node_logger "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/logger.ts"
click node_nodebot "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/bot.ts"
click node_llm "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/llm.ts"
click node_types "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/types.ts"
click node_registry "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/tools/index.ts"
click node_websearch "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/tools/web_search.ts"
click node_toolset "https://github.com/sexlovr/discord-bot-fleet/tree/main/src/tools"
click node_store "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/store.ts"
click node_crypto "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/crypto.ts"
click node_logfiles "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/logger.ts"
click node_pythonbot "https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/bot.py"
click node_pythonrest "https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/discord_rest.py"
click node_pythonllm "https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/llm.py"
click node_pythontools "https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/tools/__init__.py"
click node_pythoncrypto "https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/crypto.py"
click node_memory "https://github.com/sexlovr/discord-bot-fleet/blob/main/src/tools/memory.ts"

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_webui,node_server,node_channelpicker,node_admin toneBlue
class node_manager,node_logger toneAmber
class node_nodebot,node_llm,node_types,node_pythonbot,node_pythonrest,node_pythonllm,node_discord toneMint
class node_registry,node_websearch,node_toolset,node_pythontools toneRose
class node_store,node_crypto,node_logfiles,node_pythoncrypto,node_memory,node_llmservice toneIndigo
```

## Components

### Panel and API

- [Web panel](https://github.com/sexlovr/discord-bot-fleet/blob/main/web/static/app.js): `web/static/app.js`
- [HTTP and WS API](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/server.ts): `src/server.ts`
- [Channel discovery](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/discord_helpers.ts): `src/discord_helpers.ts`

### Fleet Operations

- [Bot manager](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/manager.ts): `src/manager.ts`
- [Log streaming](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/logger.ts): `src/logger.ts`

### Bot Runtime

- [Node bot runtime](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/bot.ts): `src/bot.ts`
- [LLM client](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/llm.ts): `src/llm.ts`
- [Bot configuration](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/types.ts): `src/types.ts`
- [Python REST bot](https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/bot.py): `bot-python/bot.py`
- [Discord REST client](https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/discord_rest.py): `bot-python/discord_rest.py`
- [Python LLM client](https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/llm.py): `bot-python/llm.py`

### Tools and Integrations

- [Tool registry](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/tools/index.ts): `src/tools/index.ts`
- [Web search](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/tools/web_search.ts): `src/tools/web_search.ts`
- [Other bot tools](https://github.com/sexlovr/discord-bot-fleet/tree/main/src/tools): `src/tools`
- [Python tool registry](https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/tools/__init__.py): `bot-python/tools/__init__.py`

### Persistence and Security

- [Bot config store](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/store.ts): `src/store.ts`
- [Token encryption](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/crypto.ts): `src/crypto.ts`
- [Persistent logs](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/logger.ts): `src/logger.ts`
- [Python decryption](https://github.com/sexlovr/discord-bot-fleet/blob/main/bot-python/crypto.py): `bot-python/crypto.py`
- [Per-bot memory](https://github.com/sexlovr/discord-bot-fleet/blob/main/src/tools/memory.ts): `src/tools/memory.ts`

### Other components

- **Panel user**
- **Discord API**
- **LLM proxy**

## Connections

- Panel user → Web panel: manages bots (evidence: `README.md`)
- Web panel → HTTP and WS API: calls API
- HTTP and WS API → Bot config store: reads and writes (evidence: `src/server.ts`)
- HTTP and WS API → Bot manager: controls lifecycle (evidence: `src/server.ts`)
- HTTP and WS API → Channel discovery: validates tokens (evidence: `src/server.ts`)
- HTTP and WS API → LLM client: tests proxy (evidence: `src/server.ts`)
- HTTP and WS API → Token encryption: encrypts tokens (evidence: `src/server.ts`)
- HTTP and WS API → Log streaming: serves live logs (evidence: `README.md`)
- Channel discovery → Discord API: fetches channels (evidence: `README.md`)
- Bot manager → Bot config store: loads config (evidence: `src/manager.ts`)
- Bot manager → Node bot runtime: spawns process (evidence: `src/manager.ts`)
- Bot manager → Log streaming: pipes output (evidence: `src/manager.ts`)
- Node bot runtime → Bot config store: loads bot config (evidence: `src/bot.ts`)
- Node bot runtime → LLM client: requests responses (evidence: `src/bot.ts`)
- Node bot runtime → Tool registry: dispatches tools (evidence: `src/bot.ts`)
- Node bot runtime → Discord API: handles messages
- LLM client → LLM proxy: sends chat requests (evidence: `src/llm.ts`)
- LLM client → Token encryption: decrypts API key (evidence: `src/llm.ts`)
- Tool registry → Web search: dispatches search (evidence: `src/tools/index.ts`)
- Tool registry → Other bot tools: dispatches tools (evidence: `src/tools/index.ts`)
- Other bot tools → Per-bot memory: reads and writes (evidence: `README.md`)
- Python REST bot → Python LLM client: requests responses (evidence: `bot-python/bot.py`)
- Python REST bot → Python tool registry: dispatches tools (evidence: `bot-python/bot.py`)
- Python REST bot → Discord REST client: polls and replies (evidence: `bot-python/bot.py`)
- Python LLM client → Python decryption: decrypts API key (evidence: `bot-python/llm.py`)
- Python REST bot → Bot config store: loads bot config (evidence: `bot-python/bot.py`)
