A lightweight multiplayer-ready backend built with Rust and Rocket, backend by PostgreSQL and Diesel ORM. Includes database migrations and a clean foundation for real-time or turn-based game logic. Note this repo has not been updated in a while. Disclaimer: I am also new to Rust in case you see some indiomatic patterns Im not utilizing. As I find time, I will continue to grow this from its current state thanks for your patience
- Rust (see
Cargo.tomlfor toolchain/edition) - Rocket web framework (async HTTP server & routing)
- Diesel ORM + PostgreSQL (
diesel.toml,migrations/)
- Rust toolchain:
curl https://sh.rustup.rs -sSf | sh rustup update - PostgreSQL 14+ running locally (or in Docker)
Handy for migrations:
cargo install diesel_cli --no-default-features --features postgrescreatedb rocket_queue_dev
# or:
# psql -c 'CREATE DATABASE game_server_dev;'Set DATABASE_URL (Diesel & Rocket will read it):
export DATABASE_URL=postgres://localhost/game_server_dev
# $env:DATABASE_URL="postgres://localhost/game_server_dev"If you use Rocket profiles, you can also add a Rocket.toml:
[default]
port = 8000
address = "127.0.0.1"diesel setup
diesel migration runAdd a new migration:
diesel migration generate add_players_table
cargo run
# or optimized:
# cargo run --releaseServer will start on http://localhost:8000 (or your Rocket profile’s port).
.
├─ src/ # Rocket routes, state, domain modules
├─ migrations/ # Diesel migrations (up/down SQL)
├─ Cargo.toml # Rust deps & metadata
├─ diesel.toml # Diesel configuration
└─ .gitignore
Routes for fetching and creating players.
GET /health
200 OK {"status":"ok"}
POST /players # create player
GET /players/{id} # fetch player
GET /players?limit=50 # list players
PATCH /players/{id} # update fields
DELETE /players/{id} # soft/hard delete
POST /sessions
POST /matchmaking/enqueue
DELETE /matchmaking/enqueue
| Variable | Example | Notes |
|---|---|---|
DATABASE_URL |
postgres://localhost/game_server_dev |
Required by Diesel/Rocket |
RUST_LOG |
info |
Enable logs via env_logger |
ROCKET_PORT |
8000 |
Overrides Rocket.toml |
ROCKET_ADDRESS |
0.0.0.0 |
Bind to all interfaces |
cargo testIf tests need the DB, point them at a throwaway database:
createdb game_server_test
export DATABASE_URL=postgres://localhost/game_server_test
diesel migration run
cargo testdocker build -t game-server .
docker run --rm -p 8000:8000 -e DATABASE_URL=postgres://host.docker.internal/game_server_dev game-server- New migration:
diesel migration generate <name> - Apply migrations:
diesel migration run - Revert last:
diesel migration revert - Format:
cargo fmt - Lint:
cargo clippy -- -D warnings
- Matchmaking endpoints
- Redis ZSets for MMR queues
- WebSocket or SSE channel for live game state
- Auth (JWT / session cookies)
- Rate limiting & request metrics (e.g.,
tower,prometheus) - E2E tests (pg test container)
PRs are welcome. Please run cargo fmt and cargo clippy before submitting.