# bsyla/discordbot_js architecture

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

- Interactive diagram: https://gitdiagram.com/bsyla/discordbot_js
- Repository: https://github.com/bsyla/discordbot_js

## Overview

##### Project type and purpose
- This is a single-service, event-driven Node.js application: a Discord Bot built with Discord.js.
- It exposes three core features via slash commands:
- Pokémon card lookup and evolution
- Quote generation with author image
- ChatGPT prompt/reply integration

##### File structure
- Top level
- src/bot.js – application entry point, sets up the Discord client and command registration
- src/commands/commands.js – central dispatcher for slash commands
- src/helpers/… – modular helper functions grouped by feature (embeds, buttons, API calls)
- No separate frontend or persistent database; all data is fetched on demand from external APIs.
- Configuration is driven by environment variables (.env).

##### README for additional insights
- Confirms the three feature sets and their external dependencies:
- Pokémon API
- Api-Ninjas Quotes API
- Search-API (Google Images)
- RapidAPI ChatGPT
- Describes expected user interactions and result formatting (embeds, buttons, edited messages).

a. Main components
1. Discord Gateway (Discord API)
2. Bot Application (Node.js + Discord.js)
– Command Registration & Dispatcher (bot.js + commands.js)
– Feature Modules (helpers folder)
- pokemonFinder / pokemonModifier / embeds / buttonCreate
- getQuotes / findImage
- chatGPT
– Environment Configuration (.env loader)
3. External Services
– Pokémon REST API
– Api-Ninjas Quotes API
– Google Images Search-API
– RapidAPI ChatGPT AI API

b. Relationships and interactions
- User in Discord → issues slash command →
- Discord Gateway routes to Bot Application →
- Command Dispatcher selects appropriate helper module →
- Helper module calls External API →
- Response is transformed into an Embed/Button payload →
- Bot Application sends message/update via Discord Gateway →
- (If button click) Interaction Update triggers another cycle.

c. Architectural patterns / design principles
- Modular Monolith: clearly separated feature modules under a common process
- Event-driven: uses Discord.js event handlers for commands and component interactions
- Single responsibility: each helper file handles one API or payload type
- Configuration-as-code: all secrets and IDs injected via environment variables

d. Key technologies
- Node.js runtime
- Discord.js library
- REST API calls (fetch or axios)
- RapidAPI / external HTTP services
- dotenv for configuration

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actors
    User["Discord User"]:::user
    User -->|"issues slash command"| DG

    %% External Discord API
    DG["Discord Gateway (Discord API)"]:::discord
    click DG "https://github.com/bsyla/discordbot_js/blob/main/src/bot.js"
    DG -->|"routes event"| BotApp

    %% Bot Application
    subgraph "Bot Application (Node.js Process)" 
        Env["Environment Configuration (.env)"]:::internal
        click Env "https://github.com/bsyla/discordbot_js/blob/main/src/bot.js"
        Dispatcher["Command Registration & Dispatcher"]:::internal
        click Dispatcher "https://github.com/bsyla/discordbot_js/blob/main/src/commands/commands.js"
        subgraph Helpers
            PFinder["Pokémon Finder Module"]:::internal
            click PFinder "https://github.com/bsyla/discordbot_js/blob/main/src/helpers/pokemonFinder.js"
            PModifier["Pokémon Modifier Module"]:::internal
            click PModifier "https://github.com/bsyla/discordbot_js/blob/main/src/helpers/pokemonModifier.js"
            Embeds["Embed Builder Module"]:::internal
            click Embeds "https://github.com/bsyla/discordbot_js/blob/main/src/helpers/embeds.js"
            Buttons["Button Creation Module"]:::internal
            click Buttons "https://github.com/bsyla/discordbot_js/blob/main/src/helpers/buttonCreate.js"
            Quotes["Quote Retrieval Module"]:::internal
            click Quotes "https://github.com/bsyla/discordbot_js/blob/main/src/helpers/getQuotes.js"
            ImageSearch["Image Search Module"]:::internal
            click ImageSearch "https://github.com/bsyla/discordbot_js/blob/main/src/helpers/findImage.js"
            ChatGPT["ChatGPT Integration Module"]:::internal
            click ChatGPT "https://github.com/bsyla/discordbot_js/blob/main/src/helpers/chatGPT.js"
            Utils["General Utility Functions"]:::internal
            click Utils "https://github.com/bsyla/discordbot_js/blob/main/src/helpers/simpleFunction.js"
        end
    end

    BotApp((" ")):::internal --> Env
    BotApp --> Dispatcher
    Dispatcher -->|selects module| PFinder
    Dispatcher -->|selects module| PModifier
    Dispatcher -->|selects module| Embeds
    Dispatcher -->|selects module| Buttons
    Dispatcher -->|selects module| Quotes
    Dispatcher -->|selects module| ImageSearch
    Dispatcher -->|selects module| ChatGPT
    Dispatcher -->|uses utils| Utils

    %% External Services
    PFinder -->|"calls REST API"| PokemonAPI
    PModifier -->|"calls REST API"| PokemonAPI
    Quotes -->|"calls Quotes API"| QuotesAPI
    ImageSearch -->|"calls Image Search API"| ImageAPI
    ChatGPT -->|"calls ChatGPT AI API"| ChatAPI

    %% Response flow
    PokemonAPI["Pokémon REST API"]:::external
    QuotesAPI["Api-Ninjas Quotes API"]:::external
    ImageAPI["Google Images Search-API"]:::external
    ChatAPI["RapidAPI ChatGPT AI API"]:::external

    PokemonAPI -->|"returns data"| PFinder
    PokemonAPI -->|"returns data"| PModifier
    QuotesAPI -->|"returns quote"| Quotes
    ImageAPI -->|"returns image URL"| ImageSearch
    ChatAPI -->|"returns AI response"| ChatGPT

    PFinder -->|"builds embed"| Embeds
    PModifier -->|"builds embed"| Embeds
    Quotes -->|"builds embed"| Embeds
    ImageSearch -->|"builds embed"| Embeds
    ChatGPT -->|"builds embed"| Embeds

    Embeds -->|"sends message/update"| DG
    Buttons -->|"adds interactive buttons"| DG

    %% Button interaction loop
    DG -->|"button click event"| BotApp

    %% Styles
    classDef user fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef discord fill:#FFA500,stroke:#333,stroke-width:1px
    classDef internal fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#ADD8E6,stroke:#333,stroke-width:1px
```
