This guide covers setting up the Flask API backend and Flutter web/mobile interface for managing HazeBot.
⚠️ Prerequisites: HazeBot Discord bot must be set up first! See Bot Setup Guide for complete instructions.
┌─────────────────┐
│ Flutter Web/ │
│ Android App │
└────────┬────────┘
│ HTTP/REST
│
┌────────▼────────┐
│ Flask API │
└────────┬────────┘
│ Python Import
│
┌────────▼────────┐
│ Config.py │
│ (HazeBot) │
└─────────────────┘
- Python 3.9+ - For the Flask API
- Flutter 3.0+ - For the web/Android interface
- HazeBot - The bot should be set up and configured
pip install -r api_requirements.txtThis installs:
- Flask - Web framework
- Flask-CORS - Cross-origin resource sharing
- PyJWT - JSON Web Token authentication
Add these to your .env file:
# API Configuration
API_PORT=5000
API_SECRET_KEY=your-very-secret-key-here-change-this
API_ADMIN_USER=admin
API_ADMIN_PASS=your-secure-password-hereSecurity Note: Always use strong, unique values in production!
cd api
python app.pyThe API will be available at http://localhost:5000
# Health check
curl http://localhost:5000/api/health
# Login
curl -X POST http://localhost:5000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"your-password"}'If you haven't installed Flutter yet:
Linux/macOS:
git clone https://github.com/flutter/flutter.git -b stable
export PATH="$PATH:`pwd`/flutter/bin"
flutter doctorWindows: Download from: https://docs.flutter.dev/get-started/install/windows
cd hazebot_admin
flutter pub getEdit lib/services/api_service.dart and update the base URL:
For local development:
// Web
static const String baseUrl = 'http://localhost:5000/api';
// Android Emulator
static const String baseUrl = 'http://10.0.2.2:5000/api';
// Android Device (replace with your computer's IP)
static const String baseUrl = 'http://192.168.1.100:5000/api';For production:
static const String baseUrl = 'https://your-domain.com/api';flutter run -d chromeOr build for production:
flutter build web
# Files will be in build/web/Using Android Emulator:
# Start emulator from Android Studio or:
flutter emulators --launch <emulator_id>
# Run app
flutter runUsing Physical Device:
# Enable USB debugging on your device
# Connect via USB
flutter devices # Check device is detected
flutter runBuild APK:
flutter build apk --release
# APK will be in build/app/outputs/flutter-apk/- Install dependencies:
pip install -r requirements.txt -r api_requirements.txt- Use a production WSGI server:
pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 api.app:app- Set up systemd service (Linux):
[Unit]
Description=HazeBot API
After=network.target
[Service]
User=hazebot
WorkingDirectory=/path/to/HazeBot
Environment="PATH=/path/to/venv/bin"
ExecStart=/path/to/venv/bin/gunicorn -w 4 -b 0.0.0.0:5000 api.app:app
[Install]
WantedBy=multi-user.target- Configure nginx reverse proxy:
server {
listen 80;
server_name your-domain.com;
location /api {
proxy_pass http://localhost:5000/api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}Railway:
# Install Railway CLI
npm install -g @railway/cli
# Login and deploy
railway login
railway init
railway upHeroku:
# Create Procfile
echo "web: gunicorn api.app:app" > Procfile
# Deploy
heroku create hazebot-api
git push heroku mainDocker:
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt api_requirements.txt ./
RUN pip install -r requirements.txt -r api_requirements.txt
COPY . .
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "api.app:app"]flutter build web --releaseDeploy build/web/ to:
-
Firebase Hosting:
firebase init hosting firebase deploy
-
GitHub Pages:
# Push build/web contents to gh-pages branch -
Netlify/Vercel:
- Drag and drop
build/webfolder - Or connect GitHub repo
- Drag and drop
FROM nginx:alpine
COPY build/web /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]- Sign your app:
keytool -genkey -v -keystore ~/hazebot-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias hazebot- Configure signing in
android/app/build.gradle:
android {
signingConfigs {
release {
storeFile file("/path/to/hazebot-release-key.jks")
storePassword "your-password"
keyAlias "hazebot"
keyPassword "your-password"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}- Build App Bundle:
flutter build appbundle --release- Upload to Play Console:
- Create app in Google Play Console
- Upload
build/app/outputs/bundle/release/app-release.aab
flutter build apk --release
# Share build/app/outputs/flutter-apk/app-release.apk- Username:
admin(or value fromAPI_ADMIN_USER) - Password:
changeme(or value fromAPI_ADMIN_PASS)
Change these immediately in production!
- General - Bot name, prefix, cooldowns
- Channels - Discord channel IDs
- Roles - Discord role IDs
- Memes - Subreddit and Lemmy configuration
- Rocket League - RL integration settings
- Welcome - Welcome messages and rules
- Login to the interface
- Navigate to the configuration category
- Update the fields
- Click "Save Configuration"
- Changes are applied immediately
Problem: Connection refused
- Ensure Flask API is running
- Check firewall allows port 5000
- Verify correct IP address
Problem: CORS errors
- CORS is enabled by default
- Check Flask-CORS is installed
- Verify API URL in Flutter app
Problem: Dependencies won't install
flutter clean
flutter pub getProblem: Android build fails
cd android
./gradlew clean
cd ..
flutter build apkProblem: Web build errors
flutter clean
flutter pub get
flutter build webProblem: Can't connect to API
- Use your computer's local IP (not localhost)
- Ensure both devices on same network
- Check firewall allows connections
- For HTTP, configure network security config
- Changed default API credentials
- Using HTTPS in production
- Strong API secret key
- Firewall configured properly
- API rate limiting enabled (recommended)
- Regular security updates
- Secure storage of .env file
- Android app signed properly
- Test the interface thoroughly
- Configure all bot settings
- Set up production deployment
- Enable HTTPS
- Configure Android signing
- Deploy to Play Store (optional)
For issues or questions:
- Check the logs (Flask and Flutter)
- Review API responses
- Test API endpoints directly
- Check Flutter console for errors
- Flask Documentation: https://flask.palletsprojects.com/
- Flutter Documentation: https://docs.flutter.dev/
- Discord.py Documentation: https://discordpy.readthedocs.io/
- JWT: https://jwt.io/