# deivao06/yt-mp3-whatsapp-bot architecture

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

- Interactive diagram: https://gitdiagram.com/deivao06/yt-mp3-whatsapp-bot
- Repository: https://github.com/deivao06/yt-mp3-whatsapp-bot

## Overview

##### Main components
a. WhatsApp Web Client Interface:
- Represented by src/whatsapp-web-client.js and the use of a QR code scan process as described in the README.
b. Bot Core/Controller:
- Likely represented by the entry points such as main.js, server.js, and routes.js. This is where commands are intercepted and routed.
c. Modular Command Services:
- Each command (such as YouTube-to-MP3 conversion, dice roller, meme fetching, game info, etc.) is implemented in separate files within src/Modules (e.g., youtube-music-downloader.js, dice-roller.js, steam-games.js, etc.). These modules encapsulate specific functionalities.
d. File Storage/Data and Configuration:
- Some configuration and external JSON files (like notequest/adventurer.json and sample JSONs in src/Modules/rotmg) hint at a data layer or configuration storage layer.
e. External Services/APIs:
- The system interacts with various third-party services (e.g., YouTube, Steam API, Monster Hunter World API, etc.), which should be depicted as external nodes.
f. Containerization & Deployment:
- Dockerfile and docker-compose.yml indicate that the application is also containerized. This suggests a deployment container where the entire bot environment is executed.

##### Relationships and Interactions
- The Bot Core receives commands, interprets them (possibly with routing logic in routes.js), and delegates command execution to the appropriate Module.
- Each Module may then interact with external services/APIs:
- For instance, the YouTube command module converts a video to MP3 and sends it back through the Bot.
- Other modules retrieve data from their respective external APIs.
- Data flow is bi-directional where the Bot sends commands to modules and then routes the responses back to WhatsApp.

##### Architectural Patterns and Design Principles
- Modular Design: The separation of functionality into individual files (each command and utility) promotes maintainability and scalability.
- Possibly a controller/router pattern in handling incoming commands.

##### Additional Notes
- Detail the process flow: a WhatsApp message is received (triggered by a command like “!p”), the Bot Core uses routing logic to direct the task to the appropriate module (e.g., the YouTube-to-MP3 module), processes the task possibly leveraging external libraries or calling external API endpoints, and finally sends the resulting media back to the user via the WhatsApp interface.
- Modular structure demonstrating how each functionality is separate yet integrated into a cohesive system.
- As a best practice, consider indicating configuration files or static resources (notequest/adventurer.json, configuration files in src/Modules) as part of the data/configuration layer.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Services
    subgraph "External Services"
        YT_API["YouTube API"]:::external
        Steam_API["Steam API"]:::external
        Meme_Svc["Meme Service"]:::external
        Game_API["Game/Utility API"]:::external
        Reddit_API["Reddit API"]:::external
    end

    %% Docker Deployment Container
    subgraph "Docker Container / Deployment Environment"
        WC["WhatsApp Web Client"]:::client
        BotCore["Bot Controller"]:::controller
        Data["Data/Config Storage"]:::data
        Deployment["Deployment Config"]:::data

        %% Modules Subgraph
        subgraph "Modules"
            YT["YouTube-to-MP3 Module"]:::module
            Dice["Dice Roller Module"]:::module
            Meme["Meme Fetching Module"]:::module
            Steam["Steam Information Module"]:::module
            Anime["Anime Module"]:::module
            MH["Monster Hunter World Module"]:::module
            Tibia["Tibia Module"]:::module
            Waifu["Waifu Module"]:::module
            Reddit["Reddit Module"]:::module
            Encore["Encore Module"]:::module
            Notequest["Notequest Module"]:::module
            ROTMG["ROTMG Module"]:::module
        end
    end

    %% Interactions: User -> Bot Controller
    WC -->|"sends message"| BotCore

    %% Bot Core routes commands to Modules
    BotCore -->|"routes to"| YT
    BotCore -->|"routes to"| Dice
    BotCore -->|"routes to"| Meme
    BotCore -->|"routes to"| Steam
    BotCore -->|"routes to"| Anime
    BotCore -->|"routes to"| MH
    BotCore -->|"routes to"| Tibia
    BotCore -->|"routes to"| Waifu
    BotCore -->|"routes to"| Reddit
    BotCore -->|"routes to"| Encore
    BotCore -->|"routes to"| Notequest
    BotCore -->|"routes to"| ROTMG

    %% Modules interacting with External Services
    YT -->|"calls"| YT_API
    Steam -->|"calls"| Steam_API
    Meme -->|"calls"| Meme_Svc
    Anime -->|"calls"| Game_API
    MH -->|"calls"| Game_API
    Tibia -->|"calls"| Game_API
    Waifu -->|"calls"| Game_API
    Encore -->|"calls"| Game_API
    Notequest -->|"calls"| Game_API
    ROTMG -->|"calls"| Game_API
    Reddit -->|"calls"| Reddit_API

    %% Data Flow: Modules return results to Bot Controller then to Client
    YT ---|"response"| BotCore
    Dice ---|"response"| BotCore
    Meme ---|"response"| BotCore
    Steam ---|"response"| BotCore
    Anime ---|"response"| BotCore
    MH ---|"response"| BotCore
    Tibia ---|"response"| BotCore
    Waifu ---|"response"| BotCore
    Reddit ---|"response"| BotCore
    Encore ---|"response"| BotCore
    Notequest ---|"response"| BotCore
    ROTMG ---|"response"| BotCore
    BotCore -->|"sends reply"| WC

    %% Click Events
    click WC "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/whatsapp-web-client.js"
    click BotCore "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/main.js"
    click YT "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/youtube-music-downloader.js"
    click Dice "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/dice-roller.js"
    click Meme "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/meme-api.js"
    click Steam "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/steam-games.js"
    click Anime "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/animes.js"
    click MH "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/monster-hunter-world.js"
    click Tibia "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/tibia.js"
    click Waifu "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/waifu.js"
    click Reddit "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/reddit.js"
    click Encore "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/encore.js"
    click Notequest "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/notequest.js"
    click ROTMG "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/src/Modules/rotmg/rotmg.js"
    click Data "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/notequest/adventurer.json"
    click Deployment "https://github.com/deivao06/yt-mp3-whatsapp-bot/blob/master/docker-compose.yml"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef controller fill:#ABEBC6,stroke:#1D8348,stroke-width:2px;
    classDef module fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef data fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef container fill:#D6DBDF,stroke:#566573,stroke-width:2px;
```
