# adivise/nanospace architecture

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

- Interactive diagram: https://gitdiagram.com/adivise/nanospace
- Repository: https://github.com/adivise/nanospace

## Overview

##### Project type and purpose
- This is a Discord music-bot project written in Node.js. It uses the Discord API (via discord.js) to interact with users, LavaLink (Java) to stream and apply audio filters, and MongoDB to store configuration, playlists, premium subscriptions, language settings, etc.
- Its core features include music playback from multiple sources, playlist management, custom filters, multi-language support, and a premium/subscription system.

##### File structure
- Top-level entry point: index.js, Start.bat.
- “commands/” folders organized by feature: Filters, Music, Playlist, Premium, Utilities. Each JS file implements one slash or prefix command.
- “events/” broken into client-level, guild-level, player-level subfolders. Each file handles one event (e.g., ready, messageCreate, trackStart).
- “handlers/” contains loaders for commands, events, database models, and player setup/update logic.
- “settings/” holds static configuration (button definitions, config.js), image assets, and Mongoose-style models in settings/models.
- “languages/” holds YAML translation files per language, enabling i18n.
- “structures/” includes helper classes (time conversion, pagination).
- “nanospace.js” likely central bot class or constants.
- package.json declares dependencies (discord.js, @lavaclient or lavalink-client, mongoose, yaml parsers).

##### README for additional insights
- Lists features, supported sources, runtime requirements (Node.js, Java for Lavalink, MongoDB).

##### Elements
- Core Bot Components (commands, events, handlers)
- External Services (Discord API, Lavalink, Music Sources, MongoDB)
- Supporting Modules (languages, settings, structures)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Services
    User["User"]:::external
    DiscordGateway["Discord Gateway\n(WebSocket)"]:::external
    LavalinkREST["LavaLink REST API"]:::service
    LavalinkWS["LavaLink WebSocket"]:::service
    MusicSources["Music Sources\n(YouTube, Spotify, etc.)"]:::external
    MongoDB["MongoDB Database"]:::db

    %% Bot Process
    subgraph "Node.js Bot Process" 
        direction TB
        %% Startup
        subgraph "Startup Scripts & Entry"
            direction TB
            IndexJS["index.js"]:::core
            StartBAT["Start.bat"]:::core
        end

        %% Core Loaders
        subgraph "Handlers & Loaders"
            direction TB
            LoadEvent["loadEvent.js"]:::core
            LoadCommand["loadCommand.js"]:::core
            LoadDatabase["loadDatabase.js"]:::core
            LoadPremium["loadPremium.js"]:::core
            subgraph "Player Handlers"
                direction TB
                LoadPlayer["loadPlayer.js"]:::core
                LoadSetup["loadSetup.js"]:::core
                LoadUpdate["loadUpdate.js"]:::core
            end
        end

        %% Modules
        subgraph "Modules & Components"
            direction TB
            subgraph "Commands (Command Pattern)"
                direction TB
                Commands["commands/"]:::core
            end
            subgraph "Events (Event-Driven)"
                direction TB
                Events["events/"]:::core
            end
            subgraph "Settings & Config"
                direction TB
                ConfigJS["config.js"]:::config
                ButtonJS["button.js"]:::config
                Images["images/"]:::config
                subgraph "Models"
                    direction TB
                    ControlModel["Control.js"]:::db
                    LanguageModel["Language.js"]:::db
                    PlaylistModel["Playlist.js"]:::db
                    PrefixModel["Prefix.js"]:::db
                    PremiumModel["Premium.js"]:::db
                    RedeemModel["Redeem.js"]:::db
                    SetupModel["Setup.js"]:::db
                end
            end
            subgraph "Internationalization"
                direction TB
                EnYAML["en/*.yaml"]:::lang
                ThYAML["th/*.yaml"]:::lang
                LangReadme["README.md"]:::lang
            end
            subgraph "Structures & Utilities"
                direction TB
                ConvertTime["ConvertTime.js"]:::util
                FormatDuration["FormatDuration.js"]:::util
                PageQueue["PageQueue.js"]:::util
            end
            Nanospace["nanospace.js"]:::core
        end
    end

    %% Connections
    User -->|connects| DiscordGateway
    DiscordGateway -->|events| IndexJS
    IndexJS --> Nanospace
    IndexJS --> LoadEvent
    IndexJS --> LoadCommand
    IndexJS --> LoadDatabase
    LoadDatabase --> LoadPremium
    LoadEvent --> Events
    LoadCommand --> Commands
    LoadPlayer --> LoadSetup
    LoadPlayer --> LoadUpdate
    LoadEvent -->|player events| Events
    LoadPlayer -->|init| Events
    Commands -->|invoke play| LavalinkREST
    LavalinkREST -->|enqueue| LavalinkWS
    LavalinkWS -->|stream audio| DiscordGateway
    LoadDatabase -->|read/write| MongoDB
    ConfigJS -->|env| IndexJS
    EnYAML -->|i18n| Commands
    EnYAML -->|i18n| Events

    %% Click Events
    click IndexJS "https://github.com/adivise/nanospace/blob/master/index.js"
    click Nanospace "https://github.com/adivise/nanospace/blob/master/nanospace.js"
    click LoadPlayer "https://github.com/adivise/nanospace/blob/master/handlers/Player/loadPlayer.js"
    click LoadSetup "https://github.com/adivise/nanospace/blob/master/handlers/Player/loadSetup.js"
    click LoadUpdate "https://github.com/adivise/nanospace/blob/master/handlers/Player/loadUpdate.js"
    click LoadPremium "https://github.com/adivise/nanospace/blob/master/handlers/Database/loadPremium.js"
    click LoadDatabase "https://github.com/adivise/nanospace/blob/master/handlers/loadDatabase.js"
    click ControlModel "https://github.com/adivise/nanospace/blob/master/settings/models/Control.js"
    click LanguageModel "https://github.com/adivise/nanospace/blob/master/settings/models/Language.js"
    click PlaylistModel "https://github.com/adivise/nanospace/blob/master/settings/models/Playlist.js"
    click PrefixModel "https://github.com/adivise/nanospace/blob/master/settings/models/Prefix.js"
    click PremiumModel "https://github.com/adivise/nanospace/blob/master/settings/models/Premium.js"
    click RedeemModel "https://github.com/adivise/nanospace/blob/master/settings/models/Redeem.js"
    click SetupModel "https://github.com/adivise/nanospace/blob/master/settings/models/Setup.js"
    click LoadCommand "https://github.com/adivise/nanospace/blob/master/handlers/loadCommand.js"
    click Commands "https://github.com/adivise/nanospace/tree/master/commands/"
    click LoadEvent "https://github.com/adivise/nanospace/blob/master/handlers/loadEvent.js"
    click Events "https://github.com/adivise/nanospace/tree/master/events/"
    click ConfigJS "https://github.com/adivise/nanospace/blob/master/settings/config.js"
    click ButtonJS "https://github.com/adivise/nanospace/blob/master/settings/button.js"
    click Images "https://github.com/adivise/nanospace/tree/master/settings/images/"
    click EnYAML "https://github.com/adivise/nanospace/tree/master/languages/en/"
    click ThYAML "https://github.com/adivise/nanospace/tree/master/languages/th/"
    click LangReadme "https://github.com/adivise/nanospace/blob/master/languages/README.md"
    click ConvertTime "https://github.com/adivise/nanospace/blob/master/structures/ConvertTime.js"
    click FormatDuration "https://github.com/adivise/nanospace/blob/master/structures/FormatDuration.js"
    click PageQueue "https://github.com/adivise/nanospace/blob/master/structures/PageQueue.js"
    click StartBAT "https://github.com/adivise/nanospace/blob/master/Start.bat"

    %% Styles
    classDef external fill:#EFEFEF,stroke:#999,stroke-width:1px
    classDef service fill:#FFDDAA,stroke:#E68A00,stroke-width:1px
    classDef db fill:#FFDDDD,stroke:#DD4949,stroke-width:1px
    classDef core fill:#DDEEFF,stroke:#4A78B0,stroke-width:1px
    classDef config fill:#FFF2CC,stroke:#D6B656,stroke-width:1px
    classDef lang fill:#E2F0D9,stroke:#6CA56C,stroke-width:1px
    classDef util fill:#E8DAEF,stroke:#A569BD,stroke-width:1px
```
