Snaketron
The code for SnakeTron.com, a multi-player implementation of the classic Snake in Node.js and MooTools.
Install / Use
/learn @lopatin/SnaketronREADME
SnakeTron
A competitive online multiplayer Snake game built with Rust (backend + WebAssembly frontend).
Architecture
- Backend: Rust server with WebSocket connections, gRPC for inter-server communication, and Raft consensus
- Frontend: React + WebAssembly (compiled from Rust)
- Database: PostgreSQL with automatic migrations
- Infrastructure: Docker containers, designed for AWS Fargate deployment
Quick Start
Using Docker (Recommended)
For Development (with hot reloading):
# Start database and server with auto-reload on code changes
./dev.sh
# In another terminal, build and start the client
cd client
wasm-pack build --target web --out-dir pkg
cd web
npm install
npm start
For Production-like environment:
# Start database and server (rebuilds on each change)
docker-compose up --build
The game will be available at:
- Frontend: http://localhost:3000 (webpack dev server)
- WebSocket Server: ws://localhost:8080 (Docker container)
- gRPC Server: localhost:50051 (Docker container)
- Database: localhost:5432 (Docker container)
Manual Setup
-
Start PostgreSQL:
docker-compose up -d db -
Run the server:
cargo run --bin server -
Build and run the client:
cd client wasm-pack build --target web --out-dir pkg cd web npm install npm start
Development
Running Tests
# Run all tests
cargo test
# Run server tests with logging
RUST_LOG=info cargo test -p server -- --nocapture
Run load test
cargo run -p bot -- --url http://localhost:8080 --mode duel --bots 40 --games 10 --queue-mode quickmatch
Project Structure
common/- Shared game logic (compiled to both native and WASM)server/- Game server with WebSocket and gRPC supportclient/- WebAssembly client moduleterminal/- Terminal-based game viewer and replay playerspecs/- TLA+ specifications for distributed systems design
Production Deployment
See server/docker-readme.md for detailed Docker and AWS Fargate deployment instructions.
License
MIT
