How realchriss/bladebot works
1. Overall shape
BladeBot is a Node.js/TypeScript Discord bot. Its architecture is centered on a Discord client that receives events and slash commands, then routes them into feature-specific handlers. Most business state is persisted in a relational database through Prisma.
2. Bootstrap and runtime
src/index.ts and src/bot/run.ts are the entry path into the bot process. Startup loads environment config, initializes logging, connects to the database, creates the Discord client, and registers command/event handlers before the bot begins processing Discord traffic.
3. Discord integration boundary
The bot’s main external boundary is the Discord API via discord.js. Everything under src/bot/ is organized around Discord interaction types: slash commands, gateway events, message/embed sending, and modal submissions. This is the primary ingress/egress path for the system.
4. Command subsystem
src/bot/slash/ contains the user-facing slash commands such as ping, help, settings, application viewing/listing, statistics, warns, changelog, and Roblox-related stats. slashHandler.ts and cmdHandler.ts provide discovery/routing so commands are loaded as discrete modules rather than hardcoded in one place.
5. Event-driven workflow
src/bot/events/ contains the operational workflows that happen after Discord interactions or server events. Examples include application acceptance/rejection, verify-and-waitlist behavior, invite confirmation, user leave notifications, and application cleanup on leave. These handlers are where the bot reacts to state changes and drives follow-up actions.
6. Application management pipeline
Application flow is one of the core subsystems. Users open and submit application modals, the bot validates the submission, stores application records, and moderators can review them via commands or event-driven actions. Acceptance/rejection then triggers downstream effects like role assignment, status updates, notifications, and invite handling.
7. Warns and member notifications
The warnings subsystem tracks AP and donation warnings, supports listing/removal, and notifies members directly by DM with channel fallback when needed. Utility modules like warnUtils.ts encapsulate the warning-specific logic, while event handlers coordinate member-facing notifications.
8. Persistence layer
src/db/prisma.ts is the database access boundary, backed by prisma/schema.prisma and prisma/seed.js. The database stores application records, warnings, settings, and related server state so the bot can recover after restarts and support moderation workflows across sessions.
9. Ephemeral UI state
src/bot/stores/ holds in-memory state for interactive modals such as application and eval flows. This is separate from the database because these are short-lived interaction contexts tied to Discord component lifecycles rather than durable business records.
10. Shared utilities and presentation
src/utils/ contains cross-cutting services: configuration loading, logging, application statistics, chart generation, string normalization, build info, and application action helpers. src/bot/assets/emoji.ts maps custom emojis used across embeds and responses, making presentation consistent across commands and events.
11. Deployment model
The repo is built for containerized deployment with Docker and compose files, plus shell scripts for start/stop/restart lifecycle management. This suggests a long-running bot service rather than a request/response app, with environment-driven configuration and externalized secrets per deployment.
12. External services
Besides Discord, the bot integrates with Roblox-related data for application validation and statistics. That makes Roblox an important external dependency for the application and profile-checking flows, while Discord remains the transport and user interface layer.
Main entry points: run.ts Run bot · cmdHandler.ts Command router · eventHandler.ts Event router · prisma.ts Prisma DB
Components 20
Bootstrap
Process entry, runtime startup, and Discord client wiring.
Discord boundary
Client-facing Discord integration and command/event routing.
- Discord client · Discord.js client wrapper used to connect to the platform.
src/bot/client.ts - Command router · Discovers and dispatches slash commands.
src/bot/cmdHandler.ts - Event router · Loads and dispatches gateway and interaction event handlers.
src/bot/eventHandler.ts - Command types · Shared command abstractions used by the command system.
src/bot/classes/ClientSlash.ts - Event types · Shared event abstractions used by the event system.
src/bot/classes/ClientEvent.ts - Message sender · Shared sending and response helper for Discord output.
src/bot/classes/MessageSender.ts
Workflows
Feature workflows driven by slash commands and gateway events.
- Applications · Application-facing slash command flow and embeds.
src/bot/slash/applicationEmbed.ts - Moderation · Warn and moderation command surface.
src/bot/slash/warn.ts - Info cmds · Help, ping, settings, changelog, stats, and Roblox stats commands.
src/bot/slash/help.ts - App events · Application acceptance, rejection, verification, cleanup, and invite handling.
src/bot/events/applicationAccept.ts - Modal flows · Modal open and submit handlers for application and eval interactions.
src/bot/events/applyModalOpen.ts - Member alerts · Leave and card notification flows sent to members and channels.
src/bot/events/userLeaveNotify.ts
State & persistence
Database access plus short-lived interaction state.
- Prisma DB · Database access boundary for durable bot state.
src/db/prisma.ts - Schema · Relational schema defining applications, warnings, settings, and related state.
prisma/schema.prisma - Modal store · In-memory state for short-lived application and eval modal lifecycles.
src/bot/stores/applyModalStore.ts
Shared services
Cross-cutting utilities and presentation helpers.
- Shared utils · Config, logging, stats, charts, string normalization, build info, and action helpers.
src/utils/ConfigManager.ts - Emoji map · Shared custom emoji definitions used in responses and embeds.
src/bot/assets/emoji.ts
Deployment
Container and lifecycle scripts for operating the bot.
- Deploy scripts · Docker and shell lifecycle scripts for running and restarting the bot.
docker/start.sh
Connections 28
- Entry → Run bot: starts · Entry point invokes the bot bootstrap.
- Run bot → Discord client: creates · Bootstrap constructs and configures the Discord client.
- Run bot → Command router: registers · Bootstrap loads slash command routing.
- Run bot → Event router: registers · Bootstrap loads event routing.
- Run bot → Prisma DB: connects · Bootstrap initializes database access.
- Run bot → Shared utils: uses · Startup depends on shared config and logging services.
- Command router → Command types: loads · Command router discovers command modules via shared types.
- Event router → Event types: loads · Event router discovers handler modules via shared types.
- Discord client → Message sender: sends via · Client output flows through message helper utilities.
- Discord client → Command router: routes commands · Discord interactions are dispatched to slash commands.
- Discord client → Event router: routes events · Gateway and modal events are dispatched to handlers.
- Command router → Applications: serves · Command routing includes application-related commands.
- Command router → Moderation: serves · Command routing includes moderation commands.
- Command router → Info cmds: serves · Command routing includes informational commands.
- Event router → App events: drives · Event routing executes application lifecycle workflows.
- Event router → Modal flows: drives · Event routing handles modal open and submit flows.
- Event router → Member alerts: drives · Event routing handles user-facing notifications.
- App events → Prisma DB: persists · Application workflows store and update durable records.
- App events → Modal store: uses · Some application interactions depend on ephemeral modal state.
- Modal flows → Modal store: uses · Modal submit flows consult in-memory interaction state.
- Moderation → Prisma DB: reads/writes · Warning commands operate on persistent moderation data.
- Moderation → Shared utils: uses · Warn behavior relies on shared warning and formatting helpers.
- Info cmds → Shared utils: uses · Informational commands reuse shared utilities for stats and formatting.
- Applications → Shared utils: uses · Application views and embeds use shared helpers.
- Shared utils → Emoji map: formats · Shared utilities and responses use common emoji mappings.
- Prisma DB → Schema: backed by · Prisma access is defined by the schema.
- Deploy scripts → Run bot: launches · Deployment scripts start and manage the bot process.
- Deploy scripts → Prisma DB: configures · Runtime deployment expects external database configuration.