ByThePowerOfMemory is a memory training game built with FastAPI backend and vanilla JavaScript frontend. The game challenges players to remember and recall different attributes of tiles displayed on a grid.
The game displays a grid of tiles, each with multiple attributes:
- Position - Location on the grid
- Color - Tile color
- Symbol - Shape or emoji displayed
- Number - Numeric value
Players must memorize these attributes and recall them when prompted, testing different aspects of memory.
The backend provides REST API endpoints for:
- Score submission
- Leaderboard retrieval
- Player statistics
- Game logging
main.py- FastAPI application with API routesdatabase.py- Database connection setuppgmodel.py- SQLModel for Score data
Submits a new score to the database.
{
"player": "string",
"score": "integer",
"duration": "float"
}Retrieves top scores sorted by score (descending). Returns array of Score objects.
Retrieves daily average scores per player. Returns JSON object with player names as keys.
Logs game events for debugging.
{
"message": "string",
"timestamp": "string"
}The frontend is a Single Page Application (SPA) using ES6 modules.
index.html- Main HTML structurestyle.css- Game stylingstate.js- Game state managementround.js- Round logic and tile generationrender.js- UI renderingbutton.js- Button event handlingscore.js- Score tracking and submissionchart.js- Statistics visualizationhelp.js- Help overlayoverlay.js- Overlay managementlogic.js- Game logic helperstile.js- Tile object modelcolor.js- Color managementemoji.js- Symbol/emoji managementnumber.js- Number generationsound.js- Audio feedbackconfig.js- Game configuration
- Start Game - Player clicks "Start / Restart"
- Memorization Phase - Grid of tiles is displayed with all attributes
- Recall Phase - Tiles are hidden, player must recall specific attributes
- Scoring - Points awarded for correct answers
- Statistics - Performance tracked and displayed
- Position memory
- Color memory
- Symbol/Shape memory
- Number memory
- Correct answers increase score
- Wrong answers decrease score
- Net score displayed
- Ratio bar showing correct vs wrong percentage
- Real-time score tracking
- Historical performance chart
- Daily averages per player
- Global leaderboard
- Responsive design
- Visual feedback for correct/wrong answers
- Help overlay with instructions
- Statistics overlay with performance metrics
- Python 3.8+
- PostgreSQL database
- Node.js (optional for development tools)
-
Clone the repository
-
Create virtual environment:
python -m venv venv source venv/bin/activate # Linux/Mac # or venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
# .env file DATABASE_URL=postgresql+psycopg2://user:password@localhost/dbname LOG_PATH=/var/log/games/ByThePowerOfMemory.log DEBUG=false -
Run the application:
uvicorn main:app --host 0.0.0.0 --port 8000
The frontend is served statically by FastAPI. No additional setup required.
CREATE TABLE scores (
id SERIAL PRIMARY KEY,
player VARCHAR NOT NULL,
score INTEGER NOT NULL,
duration FLOAT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);- Grid size
- Tile attributes
- Scoring rules
- Timer settings
DATABASE_URL- PostgreSQL connection stringLOG_PATH- Path for game logsDEBUG- Enable debug mode
- Backend: Add new routes in
main.py - Frontend: Create new modules in
static/ - Database: Update models in
pgmodel.py
- Manual testing through web interface
- API testing with tools like Postman
- Log analysis for debugging
- Use production-grade WSGI server (Gunicorn)
- Configure database connection pooling
- Set up proper logging rotation
- Enable HTTPS
- Configure CORS if needed
The application can be containerized for easy deployment.
- Fork the repository
- Create feature branch
- Make changes
- Test thoroughly
- Submit pull request
[Add license information here]
For issues or questions:
- Check game logs
- Review API responses
- Contact development team