# mcwindtim/reina-bot-rework architecture

> Architecture diagram of the GitHub repository mcwindtim/reina-bot-rework, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mcwindtim/reina-bot-rework
- Repository: https://github.com/mcwindtim/reina-bot-rework

## Overview

##### Project type and purpose
- This is a backend “Discord Bot” application built on Node.js (v20.11.0) using Discord.js v14.
- It listens to Discord gateway events, processes slash‐commands and button interactions, interacts with external services (YouTube API for music, WnACG comic API), and responds in Discord channels.

##### File structure
- **index.js**: application entry point; connects to Discord, loads config, registers events and handlers.
- **Core/**: central logic and shared utilities
- bot.js – instantiates and logs in the Discord client
- events.js – dynamic loader for Discord event listeners (messageCreate, interactionCreate, etc.)
- utils.js, rows.js – helper functions (e.g. pagination, embed builders)
- config.js.sample – sample environment/config variables (token, API keys)
- **Commands/**: grouped by feature
- Music (play, skip, queue, stop, filter, join, leave)
- Comic (fetch from WnACG)
- Info (help, info, invite)
- Customize (custom verification command)
- Owner (eval, test)
- **Buttons/**: per‐feature button interaction handlers (e.g. music playback controls)
- **Src/**: (placeholder for other modules or future code)
- **.env** / **.gitignore** / **package.json**: environment + dependencies + scripts

##### README for additional insights
- Confirms Discord.js v14, Node.js v20. Installs via `npm install`.
- No database layer—state is ephemeral or held in memory (e.g. music queues).

a. Main components
- Discord Gateway (websocket)
- Bot Engine (index.js & Core)
- Event Dispatcher (events.js)
- Command Handler modules (Commands/*)
- Button Interaction Handler (Buttons/*)
- Utilities (utils.js, rows.js)
- Configuration loader (.env → config.js)
- External Services
– YouTube API (music streaming)
– WnACG API (comic fetching)
b. Relationships & data flows
1. Bot Engine establishes a gateway connection to Discord.
2. Incoming events (messageCreate/interactionCreate) go to Event Dispatcher.
3. Dispatcher routes to:
– Command Handler (slash‐commands)
– Button Handler (Buttons/*)
4. Handler modules call Utilities, then, if needed, call External Services.
5. Responses are sent back through the Discord client.
c. Important patterns & principles
- Event‐driven architecture (Decoupled event handlers)
- Modular design (each command or button in its own file)
- Single Responsibility (Core vs Commands vs Buttons vs Utils)
d. Key technologies/frameworks
- Node.js, Discord.js v14
- dotenv or similar for config
- External HTTP clients or Discord.js’s built-in REST for API calls

##### Detail
- Every folder/module as its own node or sub‐node if space allows.
- Environment/config loading as its own component.
- Event types that trigger each handler (e.g., slash command vs button click).
- Don’t overthink—break the system into discrete, functional pieces that map directly to your file tree.

## Diagram (Mermaid)

```mermaid
graph TB
    DG["Discord Gateway"]:::gateway
    BE["Bot Engine"]:::core
    EV["Event Dispatcher"]:::core

    subgraph "Handlers"
        direction TB
        subgraph "Commands"
            direction TB
            MPlay["Music.play"]:::commands
            MSkip["Music.skip"]:::commands
            MQueue["Music.queue"]:::commands
            MStop["Music.stop"]:::commands
            MFilter["Music.filter"]:::commands
            MJoin["Music.join"]:::commands
            MLeave["Music.leave"]:::commands
            Comic["Comic.wnacg"]:::commands
            Help["Info.help"]:::commands
            InfoCmd["Info.info"]:::commands
            Invite["Info.invite"]:::commands
            Verify["Customize.驗證"]:::commands
            Eval["Owner.eval"]:::commands
            Test["Owner.test"]:::commands
        end
        subgraph "Buttons"
            direction TB
            BtnMusic["Music Controls"]:::buttons
        end
    end

    subgraph "Utilities & Config"
        direction TB
        Config["Configuration Loader"]:::core
        Util["Utilities"]:::core
        Rows["Pagination & Embeds"]:::core
    end

    subgraph "External Services"
        direction TB
        YouTube((YouTube API)):::external
        WnACG((WnACG API)):::external
    end

    DG --> BE
    BE --> EV
    EV -->|"slash command"| MPlay
    EV -->|"slash command"| MSkip
    EV -->|"slash command"| MQueue
    EV -->|"slash command"| MStop
    EV -->|"slash command"| MFilter
    EV -->|"slash command"| MJoin
    EV -->|"slash command"| MLeave
    EV -->|"slash command"| Comic
    EV -->|"slash command"| Help
    EV -->|"slash command"| InfoCmd
    EV -->|"slash command"| Invite
    EV -->|"slash command"| Verify
    EV -->|"slash command"| Eval
    EV -->|"slash command"| Test
    EV -->|"button interaction"| BtnMusic

    MPlay --> Util
    MSkip --> Util
    MQueue --> Util
    MStop --> Util
    MFilter --> Util
    MJoin --> Util
    MLeave --> Util
    Comic --> Util
    Help --> Util
    InfoCmd --> Util
    Invite --> Util
    Verify --> Util
    Eval --> Util
    Test --> Util
    BtnMusic --> Util

    Util --> YouTube
    Util --> WnACG
    YouTube --> BE
    WnACG --> BE
    BE --> DG

    click DG "https://github.com/mcwindtim/reina-bot-rework/blob/v14/index.js"
    click BE "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Core/bot.js"
    click EV "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Core/events.js"
    click Config "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Core/config.js.sample"
    click Util "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Core/utils.js"
    click Rows "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Core/rows.js"
    click MPlay "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Music/play.js"
    click MSkip "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Music/skip.js"
    click MQueue "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Music/queue.js"
    click MStop "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Music/stop.js"
    click MFilter "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Music/filter.js"
    click MJoin "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Music/join.js"
    click MLeave "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Music/leave.js"
    click Comic "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Comic/wnacg.js"
    click Help "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Info/help.js"
    click InfoCmd "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Info/info.js"
    click Invite "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Info/invite.js"
    click Verify "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Customize/驗證.js"
    click Eval "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Owner/eval.js"
    click Test "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Commands/Owner/test.js"
    click BtnMusic "https://github.com/mcwindtim/reina-bot-rework/blob/v14/Buttons/Music/play.js"

    classDef core fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef commands fill:#d4edda,stroke:#333,stroke-width:1px
    classDef buttons fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef external fill:#f8d7da,stroke:#333,stroke-width:1px
    classDef gateway fill:#f0f0f0,stroke:#333,stroke-width:1px
```
