A production-ready Discord bot infrastructure built with a monorepo architecture featuring:
- Bot: Discord.js v14 with sharding support
- API: NestJS with JWT authentication, RBAC, and WebSocket
- Panel: Next.js 15 with Tailwind CSS
- Database: PostgreSQL with Prisma ORM
- Cache: Redis for caching and pub/sub
sufbot-v5/
βββ apps/
β βββ bot/ # Discord bot (Discord.js v14)
β βββ api/ # REST API (NestJS)
β βββ panel/ # Web dashboard (Next.js 15)
βββ packages/
β βββ database/ # Prisma schema & client
β βββ shared/ # Shared types & constants
βββ docker-compose.yml
βββ package.json
- Node.js 20+
- PostgreSQL 16+
- Redis 7+
- Docker & Docker Compose (optional)
git clone <repository>
cd sufbot-v5
npm installcp .env.example .envEdit .env with your configuration:
# Discord
DISCORD_TOKEN=your_bot_token
DISCORD_CLIENT_ID=your_client_id
DISCORD_CLIENT_SECRET=your_client_secret
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/sufbot_db
# Secrets
JWT_SECRET=your_jwt_secret_min_32_chars
JWT_REFRESH_SECRET=your_refresh_secret_min_32_chars
API_SECRET=your_api_secret
WS_SECRET=your_websocket_secret# Generate Prisma client
npm run db:generate
# Push schema to database
npm run db:push
# Or run migrations
npm run db:migrate# Start all services
npm run dev
# Or start individually
npm run bot:dev
npm run api:dev
npm run panel:dev# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose downbot/
βββ src/
β βββ config/ # Configuration
β βββ events/ # Discord events
β βββ handlers/ # Command & event handlers
β βββ modules/ # Feature modules
β β βββ moderation/ # Ban, kick, mute, etc.
β β βββ economy/ # Daily, work, balance
β βββ services/ # Cache, WebSocket
β βββ types/ # TypeScript types
β βββ utils/ # Utilities
βββ bot.ts # Bot client
βββ index.ts # Sharding manager
api/
βββ src/
β βββ auth/ # Authentication (Discord OAuth2, JWT)
β βββ guilds/ # Guild management
β βββ bot/ # Bot control endpoints
β βββ admin/ # Admin endpoints
β βββ websocket/ # WebSocket gateway
β βββ prisma/ # Database service
βββ main.ts
panel/
βββ src/
β βββ app/ # Next.js app router
β βββ components/ # React components
β βββ stores/ # Zustand stores
βββ tailwind.config.ts
- JWT + Refresh Token: Access tokens expire in 15 minutes
- Discord OAuth2: Secure authentication via Discord
- RBAC: Role-based access control (USER, MODERATOR, ADMIN, OWNER)
- Rate Limiting: Per-endpoint rate limits
- CSRF Protection: Built into Next.js
- Webhook Signature Verification: All bot communications are signed
- Modular command system with JSON metadata
- Sharding support for large bots
- Redis caching for guild settings
- Real-time WebSocket communication with API
- Dashboard with bot statistics
- Guild management (settings, modules, commands)
- Moderation logs viewer
- Economy configuration
- Welcome message editor
- Auto-role management
- Filter configuration
- RESTful endpoints for all operations
- WebSocket for real-time updates
- Swagger documentation at
/docs - Audit logging
npm run dev # Start all services
npm run bot:dev # Start bot only
npm run api:dev # Start API only
npm run panel:dev # Start panel onlynpm run db:generate # Generate Prisma client
npm run db:push # Push schema to database
npm run db:migrate # Run migrations
npm run db:studio # Open Prisma Studionpm run build # Build all packages
npm run bot:start # Start bot in production
npm run api:start # Start API in production
npm run panel:build # Build panel for productionnpm run docker:up # Start Docker services
npm run docker:down # Stop Docker services
npm run docker:build # Build Docker images- Create a new file in
apps/bot/src/modules/<category>/commands/:
// apps/bot/src/modules/utility/commands/ping.ts
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js';
import type { Command } from '../../../types';
const command: Command = {
meta: {
name: 'ping',
description: 'Check bot latency',
category: 'utility',
permissions: [],
botPermissions: [],
cooldown: 3000,
guildOnly: false,
ownerOnly: false,
nsfw: false,
panelEditable: true,
enabled: true,
},
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Check bot latency'),
async execute(interaction: ChatInputCommandInteraction) {
const ping = interaction.client.ws.ping;
await interaction.reply(`π Pong! Latency: ${ping}ms`);
},
};
export default command;- Create
module.jsonin the module folder:
{
"name": "utility",
"description": "Utility commands",
"enabled": true,
"version": "1.0.0"
}- Commands are automatically loaded on bot start!
GET /api/auth/discord- Initiate Discord OAuthGET /api/auth/discord/callback- OAuth callbackPOST /api/auth/refresh- Refresh access tokenPOST /api/auth/logout- LogoutGET /api/auth/me- Get current user
GET /api/guilds- Get user's guildsGET /api/guilds/:id- Get guild detailsPUT /api/guilds/:id/settings- Update settingsPUT /api/guilds/:id/welcome- Update welcome configPUT /api/guilds/:id/moderation- Update moderation configGET /api/guilds/:id/modlogs- Get moderation logs
GET /api/bot/stats- Get bot statisticsGET /api/bot/commands- Get available commandsGET /api/bot/modules- Get available modules
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request