# dunneeee/dunn-bot architecture

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

- Interactive diagram: https://gitdiagram.com/dunneeee/dunn-bot
- Repository: https://github.com/dunneeee/dunn-bot

## Overview

##### Main Components
- Bot Core & Entry Points:
- The root index.js and src/index.js files serve as the application’s starting points.
- A “Messenger Bot Core” component which initializes the bot, sets up configurations (from utils/Config.js), and ties together other components.

- Authentication & Message Routing:

- Command Framework:
- “Commands Module” encapsulating all files within src/commands (add.js, admin.js, game.js, etc.). This module interprets commands and invokes corresponding handlers.

- Modules for Extended Functionality:

- Database Layer:

- Utility Components:
- A “Utilities” section (from utils/) showing Config, Logger, Fs, Time, etc., which support the bot’s operation by offering configuration management, logging mechanisms, and other helper functions.

##### Relationships and Data Flow
- Flow from Bot Core to “Message Authentication & Routing” (MyAuthen, MyHook, MyController) to validate and direct messages.
- Next, indicate that validated messages are passed to the “Commands Module” where the appropriate command (e.g., feedback, admin, game, weather) is selected and executed.
- Some commands may trigger operations in the “Modules” block (e.g., Youtube, Game, Hangman, fishing modules) for extended features.
- Commands and modules interact with the “Database” layer to store or retrieve persistent data (users, threads, command options, bans, etc.).
- Utilities (Config, Logger, etc.) should have directional interactions with all primary components, indicating that they provide support functions across the system.

##### Architectural Patterns & Design Principles
- Modular Architecture: Emphasize the clean separation between command logic, feature-specific modules, authentication, and persistence.
- Separation of Concerns: The design separates messaging and command routing from business logic (modules) and data persistence (database models).
- Extensibility: New commands or modules can be added without risking the overall stability of the bot.
- Reusability: Utility functions are centralized for use across different aspects of the bot.

## Diagram (Mermaid)

```mermaid
graph TD
    fm["Facebook Messenger"]:::external

    subgraph "Bot Core & Entry Points"
        bc1["Root index.js"]:::core
        bc2["src/index.js"]:::core
        bc3["utils/Config.js"]:::core
    end

    subgraph "Authentication & Routing"
        auth1["src/MyAuthen.js"]:::auth
        auth2["src/MyHook.js"]:::auth
        auth3["src/MyController.js"]:::auth
    end

    subgraph "Commands Module (src/commands)"
        cmd1["Commands Module Directory"]:::cmd
    end

    subgraph "Modules (src/module)"
        mod1["Modules Directory"]:::modules
    end

    subgraph "Database / Persistence"
        db1["Database Layer (src/database)"]:::db
        db2["Database Models (src/database/Models)"]:::db
    end

    subgraph "Utilities (utils)"
        util1["Utilities Directory"]:::util
    end

    fm -->|"receiveMsg"| bc1
    bc1 -->|"loadConfig"| bc3
    bc1 -->|"initAuth"| auth1
    auth1 -->|"runHook"| auth2
    auth2 -->|"dispatch"| auth3
    auth3 -->|"executeCommand"| cmd1
    cmd1 -->|"invokeModule"| mod1
    mod1 -->|"dbQuery"| db1
    mod1 -->|"dbQuery"| db2
    db1 -->|"returnData"| bc2
    db2 -->|"returnData"| bc2
    bc2 -->|"sendResponse"| fm

    util1 -.-> bc1
    util1 -.-> auth1
    util1 -.-> cmd1
    util1 -.-> mod1
    util1 -.-> db1
    util1 -.-> db2

    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef auth fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef cmd fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef modules fill:#FFB347,stroke:#000,stroke-width:2px;
    classDef db fill:#FFC0CB,stroke:#000,stroke-width:2px;
    classDef util fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef external fill:#F4A460,stroke:#000,stroke-width:2px;

    click bc1 "https://github.com/dunneeee/dunn-bot/blob/main/index.js"
    click bc2 "https://github.com/dunneeee/dunn-bot/blob/main/src/index.js"
    click bc3 "https://github.com/dunneeee/dunn-bot/blob/main/utils/Config.js"
    click auth1 "https://github.com/dunneeee/dunn-bot/blob/main/src/MyAuthen.js"
    click auth2 "https://github.com/dunneeee/dunn-bot/blob/main/src/MyHook.js"
    click auth3 "https://github.com/dunneeee/dunn-bot/blob/main/src/MyController.js"
    click cmd1 "https://github.com/dunneeee/dunn-bot/tree/main/src/commands/"
    click mod1 "https://github.com/dunneeee/dunn-bot/tree/main/src/module/"
    click db1 "https://github.com/dunneeee/dunn-bot/tree/main/src/database/"
    click db2 "https://github.com/dunneeee/dunn-bot/tree/main/src/database/Models/"
    click util1 "https://github.com/dunneeee/dunn-bot/tree/main/utils/"
```
