This uses Django for the backend, Sanic for websockets, a little bit of Javascript and HTMX for the frontend, and PostgreSQL for the database and async notifications (SQLite would work just fine for the database except the interprocess communication uses Postgres LISTEN/NOTIFY).
This is purposefully kept very simple- no Javascript build process and no static files to serve.
Make a virtualenv and install requirements.
git clone [email protected]:mattfox/sidestacker.git
cd sidestacker
./setup-dev.sh
Make a PostgreSQL user and database.
createuser --pwprompt sidestacker # Record the password
createdb --owner sidestacker sidestacker_db
Make life easier with an .envrc
file. Call source .envrc
or better yet, have Direnv do it for you.
cat > .envrc << EOF
source venv/bin/activate
export DATABASE_URL=postgres://sidestacker:[email protected]/sidestacker_db
export SECRET_KEY=something really random (like from https://duckduckgo.com/?t=h_&q=password+30+strong&ia=answer)
EOF
Create database tables.
cd app/
python manage.py migrate
To run the servers:
cd app/
python manage.py runserver
and
sanic server --port 8001
Matt's notes on how to write this:
- ✓ Django project basics (virtualenv, can fetch page from runserver)
- ✓ Game model stubs
- ✓ Game model tests (new moves, game completion cases)
- ✓ Implement game model methods (make test pass)
- ✓ Simple URLs, views, templates (associate session with game, match making, only initial state supported)
- ✓ Support whole game lifecycle (waiting for match, taking turns, completion)
- ✓ Consider design (layout, colours, mobile)
- ✓ Javascript, websockets, Sanic, PostgreSQL notify (update game view without refresh; page refresh reloads game state)