A Flask web application where users make wishes that get twisted by an AI-powered Monkey's Paw.
This application uses Redis as a backend for rate limiting via Flask-Limiter. Redis ensures that:
- Rate limits persist across app restarts and multiple server instances (distributed/scalable)
- Limits are enforced globally, not just per server
- The app is protected from abuse and denial-of-service attacks
- Purpose: Stores rate limit counters and metadata for each user/IP
- Integration: Configured via the
REDIS_URLenvironment variable, this is changed in production. - Fallback: If Redis is not available, the app uses in-memory storage (not recommended for production)
To run Redis locally for development:
docker run -d -p 6379:6379 --name monkeypaw-redis redis:7Add this to your .env file:
REDIS_URL=redis://localhost:6379
- Use a managed Redis service or your own Redis server
- Set
REDIS_URLto your production Redis instance
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables (create a
.envfile):FLASK_SECRET_KEY=your_secret_key_here OPENAI_API_KEY=your_openai_api_key_here DATABASE_URL=postgresql://localhost:5432/monkeypaw REDIS_URL=redis://localhost:6379 -
Create the database:
createdb monkeypaw python init_db.py
-
Run the application:
python app.py
- Render account
- OpenAI API key
-
Push your code to GitHub
-
Create a new Web Service on Render:
- Connect your GitHub repository
- Choose "Python" as the environment
- Set the build command:
pip install -r requirements.txt - Set the start command:
gunicorn app:app
-
Configure Environment Variables:
FLASK_ENV:productionFLASK_SECRET_KEY: Generate a secure random keyOPENAI_API_KEY: Your OpenAI API key
-
Create a PostgreSQL Database:
- Create a new PostgreSQL database on Render
- The
DATABASE_URLwill be automatically provided
-
Initialize the Database:
- After deployment, run the database initialization:
python init_db.py
- The app automatically handles Render's PostgreSQL URL format
- Database tables are created automatically in development
- In production, run
init_db.pyonce after deployment - Make sure your OpenAI API key has sufficient credits
- The app runs on port 5001 locally to avoid AirPlay conflicts on macOS
- User registration and session management
- AI-powered wish twisting using OpenAI GPT-4
- Streak tracking and leaderboard
- Game over after 5 failed wishes
- High score tracking