Overview
Project Stardust is a Discord bot built with discord.py that features an anime character gacha system, team-based battles, raids, and RPG progression mechanics. The bot uses a modular cog-based architecture for extensibility and maintainability.Architecture Diagram
Core Components
Main Entry Point
The bot’s entry point ismain.py:43, which orchestrates the startup sequence:
- Health Check Server (
main.py:20-34) - Runs on port 8080 for deployment platforms - Database Initialization (
main.py:54) - Creates all tables if they don’t exist - Cog Loading (
main.py:57-65) - Dynamically loads all modules fromcogs/directory - Bot Start (
main.py:68-69) - Connects to Discord and begins event loop
Cog System
Project Stardust uses discord.py’s cog system to organize functionality into modules. Each cog is a self-contained feature:Available Cogs
- achievements.py - Achievement tracking and rewards
- admin.py - Administrative commands and bot management
- battle.py - Team-based PvP and PvE combat system
- bounty.py - Daily bounty board missions
- buy.py - In-app purchase integration
- daily.py - Daily login rewards and tasks
- event.py - Special timed events
- expedition.py - Passive gem generation system
- gacha.py - Character summoning with banners
- help.py - Command documentation
- inventory.py - Character collection management
- raid.py - Multi-phase boss battles
- rpg.py - Story mode and NPC battles
- shop.py - Daily rotating shop
- teambuilder.py - Interactive team composition UI
- utility.py - Miscellaneous utility commands
Cog Structure
Each cog follows this pattern:Database Layer
The bot uses asyncpg for PostgreSQL database operations with connection pooling:get_db_pool()- Returns the connection pool singletoninit_db()- Creates all tables and schemaget_user(user_id)- Fetches or creates a user recordbatch_add_to_inventory()- Efficiently adds multiple charactersbatch_cache_characters()- Caches AniList data
Skills System
The skills system is the most complex component, handling battle abilities. It consists of three parts:1. Skill Registry (core/skills/registry.py)
Defines all skills with metadata:
2. Battle Context (core/skills/engine.py)
Manages battle state:
3. Skill Implementations (core/skills/implementations.py)
Contains skill logic with lifecycle hooks:
Battle Flow
The battle system (cogs/battle.py:76) orchestrates combat:
Configuration
Environment variables (.env file):
Deployment
The bot includes a health check endpoint (main.py:22-23) for platforms like Render:
Performance Considerations
Connection Pooling
The database uses a conservative pool size (1-3 connections) to work within Supabase free tier limits:Image Generation
Battle and gacha results use PIL for dynamic image generation, reducing reliance on external APIs.Caching
Character data from AniList is cached incharacters_cache table to minimize API calls:
Error Handling
Cogs use try-except blocks with user-friendly error messages:Next Steps
- Database Schema - Complete table structure
- Skills System - Detailed skill mechanics
- Command Reference - Command documentation