# yuanxiaona9/harunabot2 architecture

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

- Interactive diagram: https://gitdiagram.com/yuanxiaona9/harunabot2
- Repository: https://github.com/yuanxiaona9/harunabot2

## Overview

This is an asynchronous QQ bot that receives OneBot events over WebSocket, parses and routes messages to registered command or notice handlers, and sends replies through the OneBot HTTP API. A major domain workflow manages game-center records and reports or queries headcounts, using PostgreSQL and a name cache. Other handlers provide image/emoji, games, help, plus-one, and group-notice behavior. The excerpts show key routing, initialization, database, and reply paths; links for unsampled handler behavior are limited to registration references in the SOURCE INDEX.

Main entry points: [`src/msg_sys/handler_regin.rs`](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/handler_regin.rs) (Handler registration), [`src/msg_sys/func_mod/postgres_db.rs`](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_mod/postgres_db.rs) (PostgreSQL connection), [`src/msg_sys/msg_reply.rs`](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/msg_reply.rs) (Reply composition), [`src/qq_link.rs`](https://github.com/yuanxiaona9/harunabot2/blob/master/src/qq_link.rs) (QQ transport)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and routing"]
  node_main["Application startup<br/>[main.rs]"]
  node_link["QQ transport<br/>[qq_link.rs]"]
  node_runtime_loop["Message loop<br/>[msg_sys.rs]"]
  node_analysis["Event analysis<br/>[msg_analysis.rs]"]
  node_registry["Handler registration<br/>[handler_regin.rs]"]
  node_initialization["Handler initialization<br/>[handler_init.rs]"]
  node_reply["Reply composition<br/>[msg_reply.rs]"]
end

subgraph group_game["Game-center domain"]
  node_manager["Game-center commands"]
  node_manage_ops["Record management"]
  node_query_gc["Group center listing<br/>[gcm_query_gc.rs]"]
  node_report["Headcount reports<br/>[gc_query_report.rs]"]
  node_report_query["Headcount query<br/>[gcqr_query.rs]"]
end

subgraph group_features["Bot features"]
  node_media["Emoji and images<br/>[emoji_photo.rs]"]
  node_speech["Emoji speech<br/>[emoji_say.rs]"]
  node_games["Games<br/>[ttt.rs]"]
  node_other_commands["Help and play<br/>[help.rs]"]
  node_plusone["Plus-one command<br/>[plusone.rs]"]
  node_notices["Group notices<br/>[group_increase.rs]"]
end

subgraph group_integrations["State and integrations"]
  node_config["Feature configuration<br/>[func_config.rs]"]
  node_db[("PostgreSQL connection<br/>[postgres_db.rs]")]
  node_gc_cache["Game-center name cache<br/>[gc_name.rs]"]
  node_plusone_state["Plus-one state<br/>[plusone_data.rs]"]
end

node_user(("QQ users"))
node_onebot["OneBot service"]

node_user -->|"sends events"| node_onebot
node_onebot -->|"streams events"| node_link
node_main -->|"starts transport"| node_link
node_main -->|"starts processing"| node_runtime_loop
node_link -->|"forwards events"| node_runtime_loop
node_runtime_loop -->|"dispatches events"| node_analysis
node_analysis -->|"reads handlers"| node_registry
node_registry -->|"supplies handlers"| node_initialization
node_initialization -->|"registers handlers"| node_registry
node_main -->|"loads configuration"| node_config
node_analysis -->|"sends error replies"| node_reply
node_reply -->|"uses HTTP client"| node_link
node_link -->|"posts replies"| node_onebot
node_registry -->|"registers"| node_manager
node_registry -->|"registers"| node_report
node_registry -->|"registers"| node_media
node_registry -->|"registers"| node_speech
node_registry -->|"registers"| node_games
node_registry -->|"registers"| node_other_commands
node_registry -->|"registers"| node_plusone
node_registry -->|"registers"| node_notices
node_manager -->|"dispatches subcommands"| node_manage_ops
node_manager -->|"dispatches subcommand"| node_query_gc
node_report -->|"dispatches subcommands"| node_report_query
node_manager -->|"initializes tables"| node_db
node_manage_ops -->|"uses database"| node_db
node_manage_ops -->|"uses name cache"| node_gc_cache
node_query_gc -->|"queries records"| node_db
node_report -->|"checks database readiness"| node_db
node_report -->|"checks cache readiness"| node_gc_cache
node_report_query -->|"queries headcounts"| node_db
node_report_query -->|"resolves center name"| node_gc_cache
node_gc_cache -->|"loads names"| node_db
node_db -->|"reads connection settings"| node_config
node_plusone -->|"uses state"| node_plusone_state
node_media -->|"composes messages"| node_reply
node_speech -->|"composes messages"| node_reply
node_other_commands -->|"sends replies"| node_reply
node_notices -->|"sends notice replies"| node_reply

click node_main "https://github.com/yuanxiaona9/harunabot2/blob/master/src/main.rs"
click node_link "https://github.com/yuanxiaona9/harunabot2/blob/master/src/qq_link.rs"
click node_runtime_loop "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/msg_sys.rs"
click node_analysis "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/msg_analysis.rs"
click node_registry "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/handler_regin.rs"
click node_initialization "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/handler_init.rs"
click node_reply "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/msg_reply.rs"
click node_config "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_config.rs"
click node_db "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_mod/postgres_db.rs"
click node_gc_cache "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_mod/gc_name.rs"
click node_plusone_state "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_mod/plusone_data.rs"
click node_manager "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/game_center_manage.rs"
click node_manage_ops "https://github.com/yuanxiaona9/harunabot2/tree/master/src/msg_sys/func_msg/game_center_manage"
click node_query_gc "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/game_center_manage/gcm_query_gc.rs"
click node_report "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/gc_query_report.rs"
click node_report_query "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/gc_query_report/gcqr_query.rs"
click node_media "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/emoji_photo.rs"
click node_speech "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/emoji_say.rs"
click node_games "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/ttt.rs"
click node_other_commands "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/help.rs"
click node_plusone "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/plusone.rs"
click node_notices "https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_notice/group_increase.rs"

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_main,node_link,node_runtime_loop,node_analysis,node_registry,node_initialization,node_reply,node_user toneBlue
class node_manager,node_manage_ops,node_query_gc,node_report,node_report_query toneAmber
class node_media,node_speech,node_games,node_other_commands,node_plusone,node_notices toneMint
class node_config,node_db,node_gc_cache,node_plusone_state toneRose
class node_onebot toneIndigo
```

## Components

### Runtime and routing

- [Application startup](https://github.com/yuanxiaona9/harunabot2/blob/master/src/main.rs): `src/main.rs`
- [QQ transport](https://github.com/yuanxiaona9/harunabot2/blob/master/src/qq_link.rs): `src/qq_link.rs`
- [Message loop](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/msg_sys.rs): `src/msg_sys/msg_sys.rs`
- [Event analysis](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/msg_analysis.rs): `src/msg_sys/msg_analysis.rs`
- [Handler registration](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/handler_regin.rs): `src/msg_sys/handler_regin.rs`
- [Handler initialization](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/handler_init.rs): `src/msg_sys/handler_init.rs`
- [Reply composition](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/msg_reply.rs): `src/msg_sys/msg_reply.rs`

### Game-center domain

- [Game-center commands](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/game_center_manage.rs): `src/msg_sys/func_msg/game_center_manage.rs`
- [Record management](https://github.com/yuanxiaona9/harunabot2/tree/master/src/msg_sys/func_msg/game_center_manage): `src/msg_sys/func_msg/game_center_manage`
- [Group center listing](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/game_center_manage/gcm_query_gc.rs): `src/msg_sys/func_msg/game_center_manage/gcm_query_gc.rs`
- [Headcount reports](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/gc_query_report.rs): `src/msg_sys/func_msg/gc_query_report.rs`
- [Headcount query](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/gc_query_report/gcqr_query.rs): `src/msg_sys/func_msg/gc_query_report/gcqr_query.rs`

### Bot features

- [Emoji and images](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/emoji_photo.rs): `src/msg_sys/func_msg/emoji_photo.rs`
- [Emoji speech](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/emoji_say.rs): `src/msg_sys/func_msg/emoji_say.rs`
- [Games](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/ttt.rs): `src/msg_sys/func_msg/ttt.rs`
- [Help and play](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/help.rs): `src/msg_sys/func_msg/help.rs`
- [Plus-one command](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_msg/plusone.rs): `src/msg_sys/func_msg/plusone.rs`
- [Group notices](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_notice/group_increase.rs): `src/msg_sys/func_notice/group_increase.rs`

### State and integrations

- [Feature configuration](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_config.rs): `src/msg_sys/func_config.rs`
- [PostgreSQL connection](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_mod/postgres_db.rs): `src/msg_sys/func_mod/postgres_db.rs`
- [Game-center name cache](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_mod/gc_name.rs): `src/msg_sys/func_mod/gc_name.rs`
- [Plus-one state](https://github.com/yuanxiaona9/harunabot2/blob/master/src/msg_sys/func_mod/plusone_data.rs): `src/msg_sys/func_mod/plusone_data.rs`

### Other components

- **QQ users**
- **OneBot service**

## Connections

- QQ users → OneBot service: sends events
- OneBot service → QQ transport: streams events (evidence: `src/qq_link.rs`)
- Application startup → QQ transport: starts transport (evidence: `src/main.rs`)
- Application startup → Message loop: starts processing (evidence: `src/main.rs`)
- QQ transport → Message loop: forwards events (evidence: `src/main.rs`)
- Message loop → Event analysis: dispatches events (evidence: `src/msg_sys/msg_sys.rs`)
- Event analysis → Handler registration: reads handlers (evidence: `src/msg_sys/msg_analysis.rs`)
- Handler registration → Handler initialization: supplies handlers (evidence: `src/msg_sys/handler_init.rs`)
- Handler initialization → Handler registration: registers handlers (evidence: `src/msg_sys/handler_regin.rs`)
- Application startup → Feature configuration: loads configuration (evidence: `src/main.rs`)
- Event analysis → Reply composition: sends error replies (evidence: `src/msg_sys/msg_analysis.rs`)
- Reply composition → QQ transport: uses HTTP client (evidence: `src/msg_sys/msg_reply.rs`)
- QQ transport → OneBot service: posts replies (evidence: `src/qq_link.rs`)
- Handler registration → Game-center commands: registers (evidence: `src/msg_sys/handler_regin.rs`)
- Handler registration → Headcount reports: registers (evidence: `src/msg_sys/handler_regin.rs`)
- Handler registration → Emoji and images: registers (evidence: `src/msg_sys/handler_regin.rs`)
- Handler registration → Emoji speech: registers (evidence: `src/msg_sys/handler_regin.rs`)
- Handler registration → Games: registers (evidence: `src/msg_sys/handler_regin.rs`)
- Handler registration → Help and play: registers (evidence: `src/msg_sys/handler_regin.rs`)
- Handler registration → Plus-one command: registers (evidence: `src/msg_sys/handler_regin.rs`)
- Handler registration → Group notices: registers (evidence: `src/msg_sys/handler_regin.rs`)
- Game-center commands → Record management: dispatches subcommands (evidence: `src/msg_sys/func_msg/game_center_manage.rs`)
- Game-center commands → Group center listing: dispatches subcommand (evidence: `src/msg_sys/func_msg/game_center_manage.rs`)
- Headcount reports → Headcount query: dispatches subcommands (evidence: `src/msg_sys/func_msg/gc_query_report.rs`)
- Game-center commands → PostgreSQL connection: initializes tables (evidence: `src/msg_sys/func_msg/game_center_manage.rs`)
- Record management → PostgreSQL connection: uses database (evidence: `src/msg_sys/func_msg/game_center_manage/gcm_add_name.rs`)
- Record management → Game-center name cache: uses name cache (evidence: `src/msg_sys/func_msg/game_center_manage/gcm_add_name.rs`)
- Group center listing → PostgreSQL connection: queries records (evidence: `src/msg_sys/func_msg/game_center_manage/gcm_query_gc.rs`)
- Headcount reports → PostgreSQL connection: checks database readiness (evidence: `src/msg_sys/func_msg/gc_query_report.rs`)
- Headcount reports → Game-center name cache: checks cache readiness (evidence: `src/msg_sys/func_msg/gc_query_report.rs`)
- Headcount query → PostgreSQL connection: queries headcounts (evidence: `src/msg_sys/func_msg/gc_query_report/gcqr_query.rs`)
- Headcount query → Game-center name cache: resolves center name (evidence: `src/msg_sys/func_msg/gc_query_report/gcqr_query.rs`)
- Game-center name cache → PostgreSQL connection: loads names (evidence: `src/msg_sys/func_mod/gc_name.rs`)
- PostgreSQL connection → Feature configuration: reads connection settings (evidence: `src/msg_sys/func_mod/postgres_db.rs`)
- Plus-one command → Plus-one state: uses state (evidence: `src/msg_sys/func_msg/plusone.rs`)
- Emoji and images → Reply composition: composes messages (evidence: `src/msg_sys/func_msg/emoji_photo.rs`)
- Emoji speech → Reply composition: composes messages (evidence: `src/msg_sys/func_msg/emoji_say.rs`)
- Help and play → Reply composition: sends replies (evidence: `src/msg_sys/func_msg/help.rs`)
- Group notices → Reply composition: sends notice replies (evidence: `src/msg_sys/func_notice/group_increase.rs`)
