How rainyxeon/byteblaze works
Project Type and Purpose
• ByteBlaze is a full-stack TypeScript/Node.js Discord music bot.
• It uses a cluster model (master + multiple workers) to scale across shards.
• It connects to external Lavalink/Nodelink nodes for audio streaming, persists settings in pluggable databases (MySQL, MongoDB, Postgres, JSON), and exposes a small HTTP/WS web service for remote control/status.
Top-Level Components
• Discord Gateway API
• Lavalink/Nodelink Audio Nodes
• Supported Music Sources (YouTube, SoundCloud, Spotify, etc.)
• Database Service (MySQL/MongoDB/Postgres/JSON storage)
• Third-Party Services (Top.gg, optional webhooks)
b. Bot Cluster
• Cluster Manager (src/cluster/core.ts + manager.ts)
• Worker Processes (spawned via Node.js cluster, each handling shards)
c. Application Layers in Each Worker
1. Handlers
– Command Loader & Dispatcher (src/handlers/…)
– Event Loader & Dispatcher (client, guild, node, player, shard, track, websocket)
2. Business Logic & Services (src/services/…)
– Lavalink Auto-Reconnect, Auto-Fix services
– Permission, Rate-limit, Blacklist, Premium, Playlist, Config, Logger, YAML Parser, Top.gg integration
3. Database Access
– Driver abstraction layer (src/database/driver/*.ts)
– Schema definitions & setup scripts (src/database/schema & setup)
– Handler & KeyChecker (src/database/handler.ts)
4. Command & Button Modules
– Slash commands (src/commands/…)
– Button interactions (src/buttons/…)
5. Utilities & Structures
– Common utilities (time conversion, formatting)
– Extended classes (Queue, Player, Localization)
d. Web Service (src/web/)
– HTTP REST endpoints (getStatus, getQueueStatus, postCreatePlayer, patchControl, etc.)
– WebSocket server for push updates to clients
Component Relationships and Data Flows
• Discord Gateway → Cluster Manager → Worker
• Workers receive shard events, route through event handlers → services → send API calls back to Discord.
• Worker ↔ Lavalink Node
• Audio control commands (play, pause, seek) via WebSocket to Lavalink.
• Lavalink → player events → worker event handlers.
• Worker ↔ Database
• Services persist/fetch guild- and user-level settings, premium status, playlists, prefixes.
• Worker ↔ Web Service
• Exposes REST/WS for external dashboards or remote control (shows playback state, queue, allows control).
• Worker ↔ External Music Sources
• Audio metadata and streams pulled by Lavalink or downloaded via plugins.
• Worker ↔ Top.gg
• Bot analytics / vote tracking via HTTP API.
Architectural Patterns and Principles
• Cluster Pattern (Node.js built-in cluster for horizontal scalability)
• Modular Separation of Concerns: handlers, services, database, utilities, commands/buttons
• Adapter/Driver Pattern for pluggable database backends
• Observer/Publisher for event handling (Discord events, player events, shard events)
• Layered architecture in each worker: API Layer (Discord + Web), Business Logic Layer (services), Data Layer (database & Lavalink)
Essential Elements
• Clear component labels and responsibilities
• Cluster boundary with Master vs Worker roles
• Database abstraction layer and supported backends
• Web REST + WS interface module separate from the Discord bot flow