# timerainstarsky/yunzai architecture

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

- Interactive diagram: https://gitdiagram.com/timerainstarsky/yunzai
- Repository: https://github.com/timerainstarsky/yunzai

## Overview

TRSS-Yunzai is a multi-account messaging-bot application with adapters for multiple protocol endpoints and an extensible plugin system. Its principal workflow is an external messaging platform connecting through an adapter to the bot runtime, where events can be handled by loaded plugins and responses sent through the adapter. Configuration, Redis, and renderer subsystems support runtime operation and plugin features. Several wiring details are unsampled; dashed edges mark documented capability or unverified flow rather than confirmed calls.

Main entry points: [`lib/bot.js`](https://github.com/timerainstarsky/yunzai/blob/main/lib/bot.js) (Bot runtime), [`lib/plugins/loader.js`](https://github.com/timerainstarsky/yunzai/blob/main/lib/plugins/loader.js) (Plugin loader), [`lib/config/init.js`](https://github.com/timerainstarsky/yunzai/blob/main/lib/config/init.js) (Runtime initialization), [`lib/config/config.js`](https://github.com/timerainstarsky/yunzai/blob/main/lib/config/config.js) (Configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_app["Application entry<br/>[app.js]"]
  node_bot["Bot runtime<br/>[bot.js]"]
  node_listener["Event listener<br/>[listener.js]"]
  node_listener_loader["Listener loader<br/>[loader.js]"]
  node_event_handlers["Connection and online events"]
  node_util["Shared utilities<br/>[util.js]"]
end

subgraph group_adapters["Protocol adapters"]
  node_adapter_ws["WebSocket adapters"]
  node_milky["Milky adapter<br/>[Milky.js]"]
  node_onebot["OneBot v11 adapter<br/>[OneBotv11.js]"]
  node_comwechat["ComWeChat adapter<br/>[ComWeChat.js]"]
  node_gsuid["GSUIDCore adapter<br/>[GSUIDCore.js]"]
  node_opqbot["OPQBot adapter<br/>[OPQBot.js]"]
  node_satori["Satori adapter<br/>[Satori.js]"]
  node_stdin["Standard input adapter<br/>[stdin.js]"]
end

subgraph group_plugins["Plugin system"]
  node_plugin_loader["Plugin loader<br/>[loader.js]"]
  node_plugin["Plugin base<br/>[plugin.js]"]
  node_plugin_runtime["Plugin runtime<br/>[runtime.js]"]
  node_handler["Event handler registry<br/>[handler.js]"]
  node_system_plugins["System commands"]
  node_other_plugins["Maintenance commands"]
end

subgraph group_state["Configuration and state"]
  node_config["Configuration<br/>[config.js]"]
  node_init["Runtime initialization<br/>[init.js]"]
  node_logger["Logging<br/>[log.js]"]
  node_redis[("Redis client<br/>[redis.js]")]
end

subgraph group_rendering["Rendering"]
  node_renderer_loader["Renderer loader<br/>[loader.js]"]
  node_renderer["Renderer base<br/>[Renderer.js]"]
  node_puppeteer["Puppeteer renderer<br/>[puppeteer.js]"]
  node_shotium["Shotium renderer<br/>[shotium.js]"]
  node_puppeteer_helper["Puppeteer integration<br/>[puppeteer.js]"]
end

node_user(("Messaging user"))
node_platform(("Protocol platform"))

node_user -.->|"sends messages"| node_platform
node_platform -.->|"connects by protocol"| node_adapter_ws
node_app -->|"starts"| node_bot
node_bot -->|"initializes"| node_init
node_bot -->|"loads plugins"| node_plugin_loader
node_bot -->|"loads listeners"| node_listener_loader
node_bot -->|"uses utilities"| node_util
node_milky -->|"registers adapter"| node_bot
node_adapter_ws -.->|"delivers events"| node_bot
node_bot -.->|"sends responses"| node_adapter_ws
node_event_handlers -->|"uses listener"| node_listener
node_event_handlers -->|"uses listener"| node_listener
node_listener -->|"dispatches to"| node_plugin_loader
node_plugin_loader -->|"instantiates"| node_plugin
node_plugin_loader -->|"uses runtime"| node_plugin_runtime
node_plugin_loader -->|"uses handlers"| node_handler
node_plugin_runtime -->|"calls handlers"| node_handler
node_plugin_runtime -->|"uses"| node_puppeteer_helper
node_plugin_loader -.->|"loads plugin directory"| node_system_plugins
node_plugin_loader -.->|"loads plugin directory"| node_other_plugins
node_init -->|"initializes"| node_config
node_init -->|"sets up"| node_logger
node_init -->|"connects"| node_redis
node_config -->|"reconfigures"| node_logger
node_redis -->|"reads settings"| node_config
node_renderer_loader -->|"reads settings"| node_config
node_renderer_loader -->|"creates renderers"| node_renderer
node_puppeteer -->|"extends renderer"| node_renderer
node_shotium -->|"extends renderer"| node_renderer
node_puppeteer_helper -->|"loads renderers"| node_renderer_loader

click node_app "https://github.com/timerainstarsky/yunzai/blob/main/app.js"
click node_bot "https://github.com/timerainstarsky/yunzai/blob/main/lib/bot.js"
click node_listener "https://github.com/timerainstarsky/yunzai/blob/main/lib/listener/listener.js"
click node_listener_loader "https://github.com/timerainstarsky/yunzai/blob/main/lib/listener/loader.js"
click node_event_handlers "https://github.com/timerainstarsky/yunzai/tree/main/lib/events"
click node_util "https://github.com/timerainstarsky/yunzai/blob/main/lib/util.js"
click node_adapter_ws "https://github.com/timerainstarsky/yunzai/tree/main/plugins/adapter"
click node_milky "https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/Milky.js"
click node_onebot "https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/OneBotv11.js"
click node_comwechat "https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/ComWeChat.js"
click node_gsuid "https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/GSUIDCore.js"
click node_opqbot "https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/OPQBot.js"
click node_satori "https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/Satori.js"
click node_stdin "https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/stdin.js"
click node_plugin_loader "https://github.com/timerainstarsky/yunzai/blob/main/lib/plugins/loader.js"
click node_plugin "https://github.com/timerainstarsky/yunzai/blob/main/lib/plugins/plugin.js"
click node_plugin_runtime "https://github.com/timerainstarsky/yunzai/blob/main/lib/plugins/runtime.js"
click node_handler "https://github.com/timerainstarsky/yunzai/blob/main/lib/plugins/handler.js"
click node_system_plugins "https://github.com/timerainstarsky/yunzai/tree/main/plugins/system"
click node_other_plugins "https://github.com/timerainstarsky/yunzai/tree/main/plugins/other"
click node_config "https://github.com/timerainstarsky/yunzai/blob/main/lib/config/config.js"
click node_init "https://github.com/timerainstarsky/yunzai/blob/main/lib/config/init.js"
click node_logger "https://github.com/timerainstarsky/yunzai/blob/main/lib/config/log.js"
click node_redis "https://github.com/timerainstarsky/yunzai/blob/main/lib/config/redis.js"
click node_renderer_loader "https://github.com/timerainstarsky/yunzai/blob/main/lib/renderer/loader.js"
click node_renderer "https://github.com/timerainstarsky/yunzai/blob/main/lib/renderer/Renderer.js"
click node_puppeteer "https://github.com/timerainstarsky/yunzai/blob/main/renderers/puppeteer/lib/puppeteer.js"
click node_shotium "https://github.com/timerainstarsky/yunzai/blob/main/renderers/shotium/lib/shotium.js"
click node_puppeteer_helper "https://github.com/timerainstarsky/yunzai/blob/main/lib/puppeteer/puppeteer.js"

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_app,node_bot,node_listener,node_listener_loader,node_event_handlers,node_util,node_user toneBlue
class node_adapter_ws,node_milky,node_onebot,node_comwechat,node_gsuid,node_opqbot,node_satori,node_stdin toneAmber
class node_plugin_loader,node_plugin,node_plugin_runtime,node_handler,node_system_plugins,node_other_plugins toneMint
class node_config,node_init,node_logger,node_redis toneRose
class node_renderer_loader,node_renderer,node_puppeteer,node_shotium,node_puppeteer_helper,node_platform toneIndigo
```

## Components

### Bot runtime

- [Application entry](https://github.com/timerainstarsky/yunzai/blob/main/app.js): `app.js`
- [Bot runtime](https://github.com/timerainstarsky/yunzai/blob/main/lib/bot.js): `lib/bot.js`
- [Event listener](https://github.com/timerainstarsky/yunzai/blob/main/lib/listener/listener.js): `lib/listener/listener.js`
- [Listener loader](https://github.com/timerainstarsky/yunzai/blob/main/lib/listener/loader.js): `lib/listener/loader.js`
- [Connection and online events](https://github.com/timerainstarsky/yunzai/tree/main/lib/events): `lib/events`
- [Shared utilities](https://github.com/timerainstarsky/yunzai/blob/main/lib/util.js): `lib/util.js`

### Protocol adapters

- [WebSocket adapters](https://github.com/timerainstarsky/yunzai/tree/main/plugins/adapter): `plugins/adapter`
- [Milky adapter](https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/Milky.js): `plugins/adapter/Milky.js`
- [OneBot v11 adapter](https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/OneBotv11.js): `plugins/adapter/OneBotv11.js`
- [ComWeChat adapter](https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/ComWeChat.js): `plugins/adapter/ComWeChat.js`
- [GSUIDCore adapter](https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/GSUIDCore.js): `plugins/adapter/GSUIDCore.js`
- [OPQBot adapter](https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/OPQBot.js): `plugins/adapter/OPQBot.js`
- [Satori adapter](https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/Satori.js): `plugins/adapter/Satori.js`
- [Standard input adapter](https://github.com/timerainstarsky/yunzai/blob/main/plugins/adapter/stdin.js): `plugins/adapter/stdin.js`

### Plugin system

- [Plugin loader](https://github.com/timerainstarsky/yunzai/blob/main/lib/plugins/loader.js): `lib/plugins/loader.js`
- [Plugin base](https://github.com/timerainstarsky/yunzai/blob/main/lib/plugins/plugin.js): `lib/plugins/plugin.js`
- [Plugin runtime](https://github.com/timerainstarsky/yunzai/blob/main/lib/plugins/runtime.js): `lib/plugins/runtime.js`
- [Event handler registry](https://github.com/timerainstarsky/yunzai/blob/main/lib/plugins/handler.js): `lib/plugins/handler.js`
- [System commands](https://github.com/timerainstarsky/yunzai/tree/main/plugins/system): `plugins/system`
- [Maintenance commands](https://github.com/timerainstarsky/yunzai/tree/main/plugins/other): `plugins/other`

### Configuration and state

- [Configuration](https://github.com/timerainstarsky/yunzai/blob/main/lib/config/config.js): `lib/config/config.js`
- [Runtime initialization](https://github.com/timerainstarsky/yunzai/blob/main/lib/config/init.js): `lib/config/init.js`
- [Logging](https://github.com/timerainstarsky/yunzai/blob/main/lib/config/log.js): `lib/config/log.js`
- [Redis client](https://github.com/timerainstarsky/yunzai/blob/main/lib/config/redis.js): `lib/config/redis.js`

### Rendering

- [Renderer loader](https://github.com/timerainstarsky/yunzai/blob/main/lib/renderer/loader.js): `lib/renderer/loader.js`
- [Renderer base](https://github.com/timerainstarsky/yunzai/blob/main/lib/renderer/Renderer.js): `lib/renderer/Renderer.js`
- [Puppeteer renderer](https://github.com/timerainstarsky/yunzai/blob/main/renderers/puppeteer/lib/puppeteer.js): `renderers/puppeteer/lib/puppeteer.js`
- [Shotium renderer](https://github.com/timerainstarsky/yunzai/blob/main/renderers/shotium/lib/shotium.js): `renderers/shotium/lib/shotium.js`
- [Puppeteer integration](https://github.com/timerainstarsky/yunzai/blob/main/lib/puppeteer/puppeteer.js): `lib/puppeteer/puppeteer.js`

### Other components

- **Messaging user**
- **Protocol platform**

## Connections

- Messaging user → Protocol platform: sends messages
- Protocol platform → WebSocket adapters: connects by protocol
- Application entry → Bot runtime: starts (evidence: `app.js`)
- Bot runtime → Runtime initialization: initializes (evidence: `lib/bot.js`)
- Bot runtime → Plugin loader: loads plugins (evidence: `lib/bot.js`)
- Bot runtime → Listener loader: loads listeners (evidence: `lib/bot.js`)
- Bot runtime → Shared utilities: uses utilities (evidence: `lib/bot.js`)
- Milky adapter → Bot runtime: registers adapter (evidence: `plugins/adapter/Milky.js`)
- WebSocket adapters → Bot runtime: delivers events
- Bot runtime → WebSocket adapters: sends responses
- Connection and online events → Event listener: uses listener (evidence: `lib/events/connect.js`)
- Connection and online events → Event listener: uses listener (evidence: `lib/events/online.js`)
- Event listener → Plugin loader: dispatches to (evidence: `lib/listener/listener.js`)
- Plugin loader → Plugin base: instantiates (evidence: `lib/plugins/loader.js`)
- Plugin loader → Plugin runtime: uses runtime (evidence: `lib/plugins/loader.js`)
- Plugin loader → Event handler registry: uses handlers (evidence: `lib/plugins/loader.js`)
- Plugin runtime → Event handler registry: calls handlers (evidence: `lib/plugins/runtime.js`)
- Plugin runtime → Puppeteer integration: uses (evidence: `lib/plugins/runtime.js`)
- Plugin loader → System commands: loads plugin directory (evidence: `plugins/system/status.js`)
- Plugin loader → Maintenance commands: loads plugin directory (evidence: `plugins/other/restart.js`)
- Runtime initialization → Configuration: initializes (evidence: `lib/config/init.js`)
- Runtime initialization → Logging: sets up (evidence: `lib/config/init.js`)
- Runtime initialization → Redis client: connects (evidence: `lib/config/init.js`)
- Configuration → Logging: reconfigures (evidence: `lib/config/config.js`)
- Redis client → Configuration: reads settings (evidence: `lib/config/redis.js`)
- Renderer loader → Configuration: reads settings (evidence: `lib/renderer/loader.js`)
- Renderer loader → Renderer base: creates renderers (evidence: `lib/renderer/loader.js`)
- Puppeteer renderer → Renderer base: extends renderer (evidence: `renderers/puppeteer/lib/puppeteer.js`)
- Shotium renderer → Renderer base: extends renderer (evidence: `renderers/shotium/lib/shotium.js`)
- Puppeteer integration → Renderer loader: loads renderers (evidence: `lib/puppeteer/puppeteer.js`)
