This is the initial state of the Speed card game.
- Python 3.x
- Docker
- Make
- Clone the repository:
git clone https://github.com/YoccoDante/speed-bff.git
cd speed-bff- Initialize the project (creates virtual environment, starts Docker containers, and sets up database):
make init- Start the database (if not already running):
make docker-setup- Run the Flask application:
make runFor daily development, you typically need to:
- Start the database (if not running):
make docker-setup- Run the Flask application:
make runThe application uses Docker for the PostgreSQL database:
speed_postgres: PostgreSQL database (runs on port 5432)
After running make init, you need to set up the database schema:
- Initialize Flask-Migrate (only needed once):
FLASK_APP=app.main flask db initThis comment sets the env variable for the console session for windows:
$env:FLASK_APP = "app.main"- Create initial migration:
FLASK_APP=app.main flask db migrate -m "Initial migration with Player and GameRoom tables"- Apply migration to create tables:
FLASK_APP=app.main flask db upgradeThe PostgreSQL database will be available with these connection details:
Host: localhost (or 127.0.0.1)
Port: 5432
Database: speed_db
Username: speed
Password: speed
# Connection string format:
postgresql://speed:speed@localhost:5432/speed_db
You can use these credentials to connect using any PostgreSQL client (pgAdmin, DBeaver, etc.).
CRITICAL: If you have a local PostgreSQL installation running, it will conflict with the Docker container on port 5432. This will cause connection errors like:
FATAL: role "speed" does not exist
Solution: Stop your local PostgreSQL service before starting the Docker containers:
# Stop local PostgreSQL (macOS with Homebrew)
brew services stop postgresql
brew services stop postgresql@16 # or whatever version you have
# Check what's running on port 5432
lsof -i :5432
# Then start Docker containers
make docker-setupTesting the connection: Use 127.0.0.1 instead of localhost to avoid IPv6/AirPlay conflicts:
# Test with curl
curl -X POST http://127.0.0.1:5000/auth/sign-up -H "Content-Type: application/json" -d '{"name": "Test", "lastName": "User", "email": "test@test.com", "firebaseId": "123", "refreshToken": "token"}'make init- First time setup (virtual environment, Docker, database)make docker-setup- Start Docker containersmake venv- Create and setup virtual environment
make run- Run the Flask application
make up- Start all containersmake down- Stop all containersmake restart- Restart containersmake logs- Show container logsmake ps- List running containersmake clean- Remove all containers, volumes, and virtual environment
make db-create- Create databasemake db-migrate- Run database migrationsmake db-rollback- Rollback last migrationmake db-reset- Reset database (drop, create, migrate)
make install-deps <package1> [package2] ...- Install Python packages and update requirements.txtmake update-deps- Update Python dependencies
make git-clean- Remove ignored files from Git tracking (keeps files locally)
- First time setup:
make init
# Set up database schema (only needed once)
FLASK_APP=app.main flask db init
FLASK_APP=app.main flask db migrate -m "Initial migration"
FLASK_APP=app.main flask db upgrade
make run- Daily development:
make docker-setup # if database is not running
make run- Adding new database changes:
# After modifying models
FLASK_APP=app.main flask db migrate -m "Description of changes"
FLASK_APP=app.main flask db upgrade- Viewing logs:
make logs- Stopping everything:
make down- Complete reset:
make clean
make init
# Re-run database setup
FLASK_APP=app.main flask db init
FLASK_APP=app.main flask db migrate -m "Initial migration"
FLASK_APP=app.main flask db upgradeThe application uses the following environment variables:
POSTGRES_USER: Database user (default: speed)POSTGRES_PASSWORD: Database password (default: speed)POSTGRES_DB: Database name (default: speed_db)POSTGRES_HOST: Database host (default: localhost)POSTGRES_PORT: Database port (default: 5432)
Problem: Local PostgreSQL is running and conflicting with Docker container.
Solution:
# Stop local PostgreSQL
brew services stop postgresql
brew services stop postgresql@16
# Verify nothing is running on port 5432
lsof -i :5432
# Restart Docker containers
make down
make upProblem: Database tables haven't been created yet.
Solution:
# Run database migrations
FLASK_APP=app.main flask db upgradeProblem: macOS AirPlay is using port 5000, or you're using localhost instead of 127.0.0.1.
Solution:
# Use 127.0.0.1 instead of localhost
curl http://127.0.0.1:5000/
# Or disable AirPlay Receiver in System Preferences > SharingProblem: Using DATETIME instead of TIMESTAMP for PostgreSQL.
Solution: In your models, use:
from sqlalchemy.types import TIMESTAMP
# Instead of DATETIME
created_at: Mapped[datetime] = mapped_column(TIMESTAMP(timezone=True), ...)Problem: Port conflicts or Docker issues.
Solution:
# Check what's using the ports
lsof -i :5432 # PostgreSQL
lsof -i :6379 # Redis
# Clean up Docker
make clean
docker system prune -f
make init.
├── app/
│ ├── __init__.py # Flask app factory
│ ├── main.py # Application entry point
│ ├── config.py # Configuration settings
│ ├── models/ # SQLAlchemy models
│ ├── api/ # Flask-RESTX API endpoints
│ ├── controllers/ # Business logic
│ ├── repositories/ # Data access layer
│ └── utils/ # Utility functions
├── migrations/ # Database migration files
├── Dockerfile # Python application container
├── docker-compose.yml # Docker services configuration
├── Makefile # Build automation
├── requirements.txt # Python dependencies
└── README.md # This file