This document describes the technical architecture of HazeBot.
The Flask API was refactored from a monolithic 6500-line file into a clean, modular Blueprint-based architecture:
api/app.py(301 lines) - Flask setup, middleware, Blueprint registration
Organized by feature area:
auth_routes.py- Authentication & sessionsadmin_routes.py- Admin monitoring & logsconfig_routes.py- Bot configurationmeme_routes.py- Meme generation & daily memesrocket_league_routes.py- RL stats integrationticket_routes.py- Support ticket systemhazehub_cogs_routes.py- Dashboard featurescog_routes.py- Cog managementuser_routes.py- User profilesnotification_routes.py- Push & WebSocket
- ✅ Maintainability - Clear separation of concerns
- ✅ Testability - Easier to test individual modules
- ✅ Scalability - Add features as new Blueprints
- ✅ Performance - Smart caching with TTL
HazeBot uses discord.py's Cog system for modularity:
- Hot-reload support - Reload cogs without restart
- APIServer as Cog - Manage via
/api/cogsendpoints - Protection - Critical cogs (CogManager) cannot be unloaded
- APIServer.py - API as loadable Cog
- CogManager.py - Cog management
- RocketLeague.py - RL integration
- DailyMeme.py - Meme system
- TicketSystem.py - Support tickets
- Moderation.py - Mod tools
- Welcome.py - Onboarding system
- Changelog.py - Version management
- TodoList.py - Task management
- Warframe.py - Warframe integration
- And 12 more...
HazeBot/
├── Main.py # Bot entry point (standalone)
├── start_with_api.py # Bot + API Server (Port 5070)
├── Config.py # Bot configuration (not in git)
│
├── Cogs/ # Modular bot features (22 cogs)
│ ├── APIServer.py # API as loadable Cog
│ ├── CogManager.py # Cog management
│ ├── RocketLeague.py # RL integration
│ ├── DailyMeme.py # Meme system
│ ├── TicketSystem.py # Support tickets
│ ├── Moderation.py # Mod tools
│ ├── Welcome.py # Onboarding
│ ├── Changelog.py # Version management
│ ├── TodoList.py # Task management
│ ├── Warframe.py # Warframe integration
│ └── ... # 12 more cogs
│
├── api/ # REST API (Blueprint architecture)
│ ├── app.py # Main Flask app (301 lines)
│ ├── helpers.py # Helper functions
│ ├── auth.py # JWT middleware
│ ├── cache.py # Caching system
│ └── *_routes.py # Blueprint modules (10 files)
│
├── Utils/ # Shared utilities
│ ├── Logger.py # Rich logging with colors
│ ├── CacheUtils.py # Caching system
│ ├── ConfigLoader.py # Config management
│ └── DatabaseManager.py # Database utilities
│
├── Data/ # SQLite databases
│ ├── memes.db # Meme tracking
│ ├── tickets.db # Support tickets
│ ├── users.db # User profiles
│ └── warnings.db # Moderation warnings
│
├── Cache/ # API response cache
│ ├── rl_stats:*.json # Rocket League stats
│ ├── warframe_*.json # Warframe data
│ └── ... # Other cached data
│
├── Logs/ # Log files
│ ├── bot.log # Main bot logs
│ ├── api.log # API logs
│ └── error.log # Error logs
│
└── .env # Environment variables (not in git)
- Python 3.11+ - Modern Python features
- discord.py 2.0+ - Discord API wrapper
- Flask 3.0+ - Web framework for API
- SQLite - Lightweight database
- JWT Authentication - Secure token-based auth
- Blueprint Architecture - Modular routing
- Smart Caching - TTL-based response caching
- CORS Support - Cross-origin requests
- Flutter 3.0+ - Cross-platform UI framework
- Material Design 3 - Modern design system
- Riverpod - State management
Discord User → Bot Command → Cog Handler → Database/API → Response
Client → JWT Auth → Blueprint Route → Helper Function → Database/Cache → JSON Response
Bot Event → WebSocket Server → Connected Clients → UI Update
- JWT tokens with automatic refresh
- Session tracking in SQLite
- Rate limiting on API endpoints
- Config.py excluded from git (contains secrets)
- Environment variables for sensitive data
- Encrypted credentials for external APIs
- Admin-only endpoints for sensitive operations
- User role validation in Discord commands
- Permission checks before database modifications
- API responses cached with TTL (Time To Live)
- Rocket League stats: 5 minutes
- Warframe market data: 15 minutes
- Discord user data: 1 hour
- Indexed columns for frequent queries
- Connection pooling for API
- Prepared statements to prevent SQL injection
- Async/await throughout for non-blocking I/O
- Connection limits for external APIs
- Automatic cleanup of old logs and cache
- Linux - Primary deployment target
- Docker - Containerized deployment
- Cloudflare Tunnel - Secure external access
- Rich console logging with colors
- Discord channel for bot logs
- API access logs
- Error tracking and alerts
See DEPLOYMENT_CHECKLIST.md for detailed deployment instructions.