# christopherbthai/discord-owo-bot architecture

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

- Interactive diagram: https://gitdiagram.com/christopherbthai/discord-owo-bot
- Repository: https://github.com/christopherbthai/discord-owo-bot

## Overview

##### Major Components
- Bot Client/Core: Represented by the main entry point (index.js) where the Discord client is set up.
- Event Handlers: In the “src/eventHandlers” directory you find files for handling Discord events (ready, messageCreate, guild updates, interactions, etc.). These modules receive events from the Discord API.
- Command Handlers:
- The “src/commands” directory organizes various commands into categories such as admin, battle, patreon, economy, shop, social, etc.
- The “src/commands/CommandInterface.js” and “src/commands/command.js” guide the design pattern for command creation and execution.
- Bot Handlers: Components in “src/botHandlers” (like mysqlHandler.js, patreonHandler.js, questHandler.js) abstract interactions with external systems.
- Interaction Handlers: Found in “src/interactionHandlers”, these modules manage button interactions and other interactive components from Discord.
- Data and Configuration: The “src/data” directory stores configuration files (config.json), bot data like animal data, emojis, and other static assets.
- Utility Modules: “src/utils” contains helper functions used throughout the application (logger, cooldown manager, redis, mysql, pub/sub, etc.).
- Secret/External Configuration: The “secret” directory includes secure SQL scripts, environment details, and other sensitive data that integrate with the bot’s databases.
- External Databases & Services: MariaDB (via MySQL connections) and Redis are key parts of the architecture.

##### Relationships and Interaction Flow
- The Discord API is the external input for the bot: events (message creation, reactions, interactions) are sent to the Bot Client.
- The Bot Client (index.js) dispatches events to respective event handlers.
- Event Handlers then call appropriate Command Handlers or Interaction Handlers based on the event type.
- Command Handlers process user commands, which may include querying or updating data from the databases (MariaDB through mysqlHandler and Redis through redis utilities).
- Bot Handlers might manage integration with Patreon and perform quest-related activity.
- Utility modules support various functions (logging, caching, error handling) and may be invoked by commands or events.
- A Pub/Sub system (in “src/utils/pubsub” and related pubsubHandlers) handles internal or cross-module communication.
- Interaction Handlers direct user interactions with message components (buttons, surveys) that feed into the command pipeline.

##### Architectural Patterns & Design Principles
- Modularity: The project is organized with clear separation between commands, event handling, interactions, and utility functionalities.
- Event-Driven Architecture: Emphasis is on reacting to Discord events and delegating work to specialized modules.
- Separation of Concerns: Clear division of business logic (in commands and utilities) from external interactions (bot handlers, database access).
- Configuration Management: Sensitive files (inside the “secret” directory) are managed separately.
- Extensibility: The commands are split into detailed subdirectories (e.g., battle, patreon, economy) permitting easy additions and modifications.

##### Final Steps and Details
- Also, show connections from the Bot Client to auxiliary services like Patreon integration, represented in the “botHandlers” and “commands/commandList/patreon” directories.
- That any connection between the business logic and utility modules (like logging, caching, rate limiting via “utils/”) is clearly represented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Discord API"]:::external
    B["Bot Client (index.js)"]:::core
    C["Event Handlers (src/eventHandlers)"]:::handler

    subgraph "Command Handlers"
        D["Command Framework (src/commands/CommandInterface.js & command.js)"]:::command
        E["Command Definitions (src/commands/commandList)"]:::command
    end

    F["Interaction Handlers (src/interactionHandlers)"]:::interaction
    G["Bot Handlers (src/botHandlers)"]:::bot
    H["Utility Modules (src/utils)"]:::utility
    I["Static Data/Config (src/data)"]:::data
    J["Sensitive Config (secret)"]:::secret
    K["MariaDB"]:::db
    L["Redis"]:::db

    %% Flow
    A -->|"sendsEvents"| B
    B -->|"dispatchesTo"| C
    C -->|"triggers"| D
    C -->|"triggers"| E
    C -->|"triggers"| F
    D -->|"invokes"| G
    E -->|"invokes"| G
    D -->|"utilizes"| H
    E -->|"utilizes"| H
    F -->|"utilizes"| H
    G -->|"queries"| K
    G -->|"queries"| L
    G -->|"uses"| J
    B -->|"loads"| I
    H -->|"supports"| B
    H -->|"supports"| D
    H -->|"supports"| G
    I -->|"providesData"| D
    I -->|"providesData"| G
    J -->|"secures"| G

    %% Click Events
    click B "https://github.com/christopherbthai/discord-owo-bot/blob/master/index.js"
    click C "https://github.com/christopherbthai/discord-owo-bot/tree/master/src/eventHandlers"
    click D "https://github.com/christopherbthai/discord-owo-bot/blob/master/src/commands/CommandInterface.js"
    click E "https://github.com/christopherbthai/discord-owo-bot/tree/master/src/commands/commandList"
    click F "https://github.com/christopherbthai/discord-owo-bot/tree/master/src/interactionHandlers"
    click G "https://github.com/christopherbthai/discord-owo-bot/tree/master/src/botHandlers"
    click H "https://github.com/christopherbthai/discord-owo-bot/tree/master/src/utils"
    click I "https://github.com/christopherbthai/discord-owo-bot/tree/master/src/data"
    click J "https://github.com/christopherbthai/discord-owo-bot/tree/master/secret"

    %% Styles
    classDef external fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef core fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef handler fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef command fill:#fff9c4,stroke:#f57f17,stroke-width:2px;
    classDef interaction fill:#b3e5fc,stroke:#01579b,stroke-width:2px;
    classDef bot fill:#ffcdd2,stroke:#b71c1c,stroke-width:2px;
    classDef utility fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
    classDef data fill:#ffecb3,stroke:#ff6f00,stroke-width:2px;
    classDef secret fill:#ffccbc,stroke:#bf360c,stroke-width:2px;
    classDef db fill:#d7ccc8,stroke:#3e2723,stroke-width:2px;
```
