# jermorg/discordosubot architecture

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

- Interactive diagram: https://gitdiagram.com/jermorg/discordosubot
- Repository: https://github.com/jermorg/discordosubot

## Overview

The DiscordOsuBot project is a Node.js-based Discord bot that integrates with the osu! gaming platform, allowing users to view player profiles and create lobbies directly through Discord. The system’s primary functionality revolves around processing Discord commands, interfacing with osu!’s APIs/IRC through external libraries, and managing its internal functions to gather and process game-related data.

##### Main Components
- Functional Utilities: Illustrate the “func” directory as a helper component. It includes functions such as getBestResult.js, getBitMupp.js, and getUser.js that are invoked by the command files to handle core business logic.
- Configuration/Data Files: Include config.json (for credentials such as the Discord token, osu! IRC password, and API key) and userList.json as configuration and data storage elements.
- Assets: Represent the “img” and “font” directories as resource components that may store images and custom fonts (potentially used by the @napi-rs/canvas module for generating dynamic visuals).
- External Libraries/Services: Emphasize external dependencies:
- discord.js for interacting with the Discord API.
- bancho.js for connecting to osu!’s API/IRC.
- @napi-rs/canvas for any image/canvas operations.
Also, mention Node.js as the runtime environment.

##### Relationships and Data Flow
- Static Assets: Show that the “img” and “font” directories are used by parts of the functionality responsible for image generation or display.

##### Architectural Patterns/Design Principles
- Modularity: Note that the project is structured modularly by separating commands, functional logic, and resources.
- Event-Driven Design: The bot actively listens for Discord events (commands) and dispatches them to the respective modules.
- Configuration-Driven Behavior: Highlight the use of configuration files (config.json) which enable dynamic changes without modifying the code base.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Inputs"
        D["Discord (User Interactions)"]:::external
    end

    subgraph "Core Application"
        EP["Entry Point (index.js)"]:::core
    end

    subgraph "Commands Module"
        CL["create_lobby command (create_lobby.js)"]:::commands
        P["ping command (ping.js)"]:::commands
        U["user command (user.js)"]:::commands
    end

    subgraph "Functional Utilities"
        GBR["getBestResult (getBestResult.js)"]:::utilities
        GBM["getBitMupp (getBitMupp.js)"]:::utilities
        GU["getUser (getUser.js)"]:::utilities
    end

    subgraph "Configuration & Data"
        CFG["Configuration (config.json)"]:::config
        UL["Data Storage (userList.json)"]:::config
    end

    subgraph "Assets"
        IMG["Images (img/)"]:::assets
        FNT["Fonts (font/)"]:::assets
    end

    subgraph "External Services"
        DSC["Discord API (discord.js)"]:::external
        OSU["osu! API/IRC (bancho.js)"]:::external
        CAN["Canvas Module (@napi-rs/canvas)"]:::external
        NODE["Runtime Environment (Node.js)"]:::external
    end

    %% Data Flow Connections
    D -->|"emits events"| EP
    EP -->|"registers commands"| CL
    EP -->|"registers commands"| P
    EP -->|"registers commands"| U
    EP -->|"uses"| DSC

    %% Commands delegate to Functional Utilities
    CL -->|"delegates task"| GBR
    CL -->|"delegates task"| GU
    P  -->|"delegates task"| GBM
    U  -->|"delegates task"| GU

    %% Functional Utilities interactions
    GBR -->|"calls osu! API"| OSU
    GBM -->|"calls osu! API"| OSU
    GU  -->|"calls Discord API"| DSC
    GU  -->|"calls Canvas operations"| CAN
    GU  -->|"utilizes"| IMG
    GU  -->|"utilizes"| FNT

    %% Configuration dependencies
    EP ---|"reads config"| CFG
    CL ---|"reads config"| CFG
    P  ---|"reads config"| CFG
    U  ---|"reads config"| CFG
    GBR ---|"reads config"| CFG
    GBM ---|"reads config"| CFG
    GU  ---|"reads config"| CFG
    GU  ---|"reads data"| UL

    %% External Services Runtime
    DSC --- NODE
    OSU --- NODE
    CAN --- NODE

    %% Assets usage note (used by Canvas Module)
    CAN ---|"uses assets"| IMG
    CAN ---|"uses assets"| FNT

    %% Click Events for Component Mapping
    click EP "https://github.com/jermorg/discordosubot/blob/main/index.js"
    click CL "https://github.com/jermorg/discordosubot/blob/main/commands/create_lobby.js"
    click P "https://github.com/jermorg/discordosubot/blob/main/commands/ping.js"
    click U "https://github.com/jermorg/discordosubot/blob/main/commands/user.js"
    click GBR "https://github.com/jermorg/discordosubot/blob/main/func/getBestResult.js"
    click GBM "https://github.com/jermorg/discordosubot/blob/main/func/getBitMupp.js"
    click GU "https://github.com/jermorg/discordosubot/blob/main/func/getUser.js"
    click CFG "https://github.com/jermorg/discordosubot/blob/main/config.json"
    click UL "https://github.com/jermorg/discordosubot/blob/main/userList.json"
    click IMG "https://github.com/jermorg/discordosubot/tree/main/img/"
    click FNT "https://github.com/jermorg/discordosubot/tree/main/font/"

    %% Class Definitions
    classDef core fill:#C5E1A5,stroke:#388E3C,stroke-width:2px;
    classDef commands fill:#AED581,stroke:#7CB342,stroke-width:2px;
    classDef utilities fill:#BBDEFB,stroke:#1E88E5,stroke-width:2px;
    classDef config fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef assets fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
    classDef external fill:#FFE082,stroke:#FB8C00,stroke-width:2px;
```
