# hangddev/yubot architecture

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

- Interactive diagram: https://gitdiagram.com/hangddev/yubot
- Repository: https://github.com/hangddev/yubot

## Overview

##### Project type and purpose
- This is a Node.js–based Discord bot.
- Key files: bot.js / index.js (entry points), commands/, events/, handlers/, schema/.
- It provides AI‐powered chat and image generation, moderation, configuration, and utility commands.

##### File structure
- Top‐level:
- bot.js, index.js: create and start the Discord client.
- package.json: lists dependencies (discord.js, mongoose or similar, axios/OpenAI SDK).
- config/: static JSON (emoji mappings, possibly DB URIs).
- commands/: grouped by feature area (AI, config, context menus, moderation, utility). Each command exports a handler.
- events/: defines reaction to Discord gateway events:
- client ready
- message create, mentions
- interactionCreate (slash commands, button clicks, context menus)
- handlers/:
- loaders/command.js & event.js – dynamic registration of commands & events with the client.
- components/embed.js – helper for rich embeds.
- functions/functions.js – shared utilities.
- schema/: Mongoose or similar models for persistent settings (per‐guild config, chatbot history).
- structure/client.js: wrapper around discord.js Client with extended methods (e.g., logger, config loader).

##### Key architectural insights from the (minimal) README
- “Archived project” suggests no further docs, so infer architecture from code organization.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Services
    subgraph "External Services"
        DG["Discord Gateway"]:::external
        OAI["OpenAI API"]:::external
        MDB["MongoDB"]:::external
    end

    %% Bot Client Layer
    subgraph "Bot Client Layer"
        direction TB
        EP1["bot.js"]:::entry
        EP2["index.js"]:::entry
        BC["Client Wrapper\n(structure/client.js)"]:::client
    end

    %% Loader Layer
    subgraph "Loaders"
        direction TB
        CL["Command Loader\n(handlers/loaders/command.js)"]:::loader
        EL["Event Loader\n(handlers/loaders/event.js)"]:::loader
    end

    %% Helpers
    subgraph "Helpers"
        direction TB
        FUNC["Shared Functions\n(handlers/functions/functions.js)"]:::helper
        EMBED["Embed Builder\n(handlers/components/embed.js)"]:::helper
    end

    %% Commands
    subgraph "Commands"
        direction TB
        subgraph "AI Commands"
            GPT["gpt.js"]:::command
            IMG["image.js"]:::command
        end
        subgraph "Config Commands"
            CCHAT["chatbot.js"]:::command
            CCFG["config.js"]:::command
        end
        subgraph "Context Menu Commands"
            AVA["avatar.js"]:::command
            MSGINFO["messageinfo.js"]:::command
            UINFO["userinfo.js"]:::command
        end
        subgraph "Moderation Commands"
            BAN["ban.js"]:::command
            CLR["clear.js"]:::command
            KICK["kick.js"]:::command
            LOCKC["lock.js"]:::command
            UNLOCKC["unlock.js"]:::command
        end
        subgraph "Utility Commands"
            BINFO["botinfo.js"]:::command
            HELP["help.js"]:::command
            PING["ping.js"]:::command
            UPTIME["uptime.js"]:::command
            UINFO2["userinfo.js"]:::command
        end
    end

    %% Event Handlers
    subgraph "Event Handlers"
        direction TB
        subgraph "Client Events"
            READY["ready.js"]:::event
        end
        subgraph "Message Events"
            MCHAT["chatbot.js"]:::event
            MMENTION["mention.js"]:::event
        end
        subgraph "Interaction Events"
            CMDINT["commands.js"]:::event
            CTXINT["contextMenu.js"]:::event
        end
        subgraph "Button Events"
            BRESET["chatBotReset.js"]:::event
            BLOCK["lock.js"]:::event
            BUNLOCK["unlock.js"]:::event
        end
    end

    %% Schema
    subgraph "Database Schemas"
        CHIST["chatbot.js"]:::schema
        GSET["guildSetting.js"]:::schema
    end

    %% Config
    CM["emoji.json"]:::config

    %% Connections
    DG -->|"WebSocket"| BC
    BC --> EP1
    BC --> EP2
    EP1 --> BC
    EP2 --> BC

    BC -->|"on ready"| CL
    CL -->|"register commands"| DG

    BC -->|"on event"| EL
    EL -->|"invoke handlers"| READY
    EL --> READY

    CL --> GPT
    CL --> IMG
    CL --> CCHAT
    CL --> CCFG
    CL --> AVA
    CL --> MSGINFO
    CL --> UINFO
    CL --> BAN
    CL --> CLR
    CL --> KICK
    CL --> LOCKC
    CL --> UNLOCKC
    CL --> BINFO
    CL --> HELP
    CL --> PING
    CL --> UPTIME
    CL --> UINFO2

    EL --> MCHAT
    EL --> MMENTION
    EL --> CMDINT
    EL --> CTXINT
    EL --> BRESET
    EL --> BLOCK
    EL --> BUNLOCK

    GPT -->|"calls"| OAI
    IMG -->|"calls"| OAI

    GPT -->|"DB read/write"| CHIST
    MCHAT -->|"DB read/write"| CHIST
    CCHAT -->|"DB read/write"| GSET

    BC -->|"loads"| CM

    GPT --> FUNC
    IMG --> FUNC
    CCHAT --> FUNC
    CCFG --> FUNC

    FUNC --> EMBED
    READY --> EMBED

    BC --> MDB
    CHIST --> MDB
    GSET --> MDB

    %% Click Events
    click BC "https://github.com/hangddev/yubot/blob/main/structure/client.js"
    click EP1 "https://github.com/hangddev/yubot/blob/main/bot.js"
    click EP2 "https://github.com/hangddev/yubot/blob/main/index.js"
    click CL "https://github.com/hangddev/yubot/blob/main/handlers/loaders/command.js"
    click EL "https://github.com/hangddev/yubot/blob/main/handlers/loaders/event.js"
    click GPT "https://github.com/hangddev/yubot/blob/main/commands/AI/gpt.js"
    click IMG "https://github.com/hangddev/yubot/blob/main/commands/AI/image.js"
    click CCHAT "https://github.com/hangddev/yubot/blob/main/commands/config/chatbot.js"
    click CCFG "https://github.com/hangddev/yubot/blob/main/commands/config/config.js"
    click AVA "https://github.com/hangddev/yubot/blob/main/commands/context/avatar.js"
    click MSGINFO "https://github.com/hangddev/yubot/blob/main/commands/context/messageinfo.js"
    click UINFO "https://github.com/hangddev/yubot/blob/main/commands/context/userinfo.js"
    click BAN "https://github.com/hangddev/yubot/blob/main/commands/moderation/ban.js"
    click CLR "https://github.com/hangddev/yubot/blob/main/commands/moderation/clear.js"
    click KICK "https://github.com/hangddev/yubot/blob/main/commands/moderation/kick.js"
    click LOCKC "https://github.com/hangddev/yubot/blob/main/commands/moderation/lock.js"
    click UNLOCKC "https://github.com/hangddev/yubot/blob/main/commands/moderation/unlock.js"
    click BINFO "https://github.com/hangddev/yubot/blob/main/commands/utility/botinfo.js"
    click HELP "https://github.com/hangddev/yubot/blob/main/commands/utility/help.js"
    click PING "https://github.com/hangddev/yubot/blob/main/commands/utility/ping.js"
    click UPTIME "https://github.com/hangddev/yubot/blob/main/commands/utility/uptime.js"
    click UINFO2 "https://github.com/hangddev/yubot/blob/main/commands/utility/userinfo.js"
    click READY "https://github.com/hangddev/yubot/blob/main/events/client/ready.js"
    click MCHAT "https://github.com/hangddev/yubot/blob/main/events/message/chatbot.js"
    click MMENTION "https://github.com/hangddev/yubot/blob/main/events/message/mention.js"
    click CMDINT "https://github.com/hangddev/yubot/blob/main/events/interaction/commands.js"
    click CTXINT "https://github.com/hangddev/yubot/blob/main/events/interaction/contextMenu.js"
    click BRESET "https://github.com/hangddev/yubot/blob/main/events/button/chatBotReset.js"
    click BLOCK "https://github.com/hangddev/yubot/blob/main/events/button/lock.js"
    click BUNLOCK "https://github.com/hangddev/yubot/blob/main/events/button/unlock.js"
    click FUNC "https://github.com/hangddev/yubot/blob/main/handlers/functions/functions.js"
    click EMBED "https://github.com/hangddev/yubot/blob/main/handlers/components/embed.js"
    click CHIST "https://github.com/hangddev/yubot/blob/main/schema/chatbot.js"
    click GSET "https://github.com/hangddev/yubot/blob/main/schema/guildSetting.js"
    click CM "https://github.com/hangddev/yubot/blob/main/config/emoji.json"

    %% Styles
    classDef external fill:#fde2e2,stroke:#e63946
    classDef client fill:#e0f7fa,stroke:#006064
    classDef entry fill:#fff3e0,stroke:#ef6c00
    classDef loader fill:#e8f5e9,stroke:#2e7d32
    classDef helper fill:#f3e5f5,stroke:#6a1b9a
    classDef command fill:#e3f2fd,stroke:#1565c0
    classDef event fill:#f1f8e9,stroke:#558b2f
    classDef schema fill:#fff0f6,stroke:#c2185b
    classDef config fill:#fffde7,stroke:#f9a825
```
