A lightweight, custom game backend using Deno, SQLite, WebSockets, and KV Store, designed to be deployed to Deno Deploy in seconds.
- SQLite for persistent account storage
- KV Store for lobby and session management
- Native WebSockets for real-time multiplayer
- Discord OAuth Integration
- Lobby System for team-based games
- Real-time Updates via WebSocket pub/sub
- Game Server Allocation via GameFlow API
-
Copy environment variables:
cp .env.example .env
-
Edit
.envand set your JWT secret:PORT=3000 JWT_SECRET=your-secret-key
deno task devdeno task startThe server will start on http://localhost:3000 (or the port specified in .env).
GET /- API informationPOST /auth/discord- Authenticate with Discord tokenPOST /auth/anonymous- Anonymous authenticationGET /accounts/me- Get current user info (requires auth)GET /lobbies- List all public lobbies (requires auth)
Connect to ws://localhost:3000/_ws?token=JWT_TOKEN
Game Client → Backend
| Type | Payload | Description |
|---|---|---|
ping |
- | Ping server |
lobby:create |
isPrivate: boolean |
Create lobby |
lobby:join |
lobbyId?: string, code?: string, team?: "A"|"B" |
Join lobby |
lobby:leave |
- | Leave current lobby |
lobby:ready |
ready: boolean |
Toggle ready status |
lobby:start |
- | Start match (owner only) |
lobby:fill-bots |
- | Fill empty slots with bots (owner only) |
Backend → Game Client
| Type | Payload | Description |
|---|---|---|
connected |
accountId, username |
Connection established |
pong |
- | Pong response |
lobby:created |
lobby |
Lobby created |
lobby:updated |
lobby |
Lobby state changed |
lobby:deleted |
lobbyId |
Lobby deleted |
lobby:left |
- | Left lobby |
match:started |
matchData |
Match started |
error |
message |
Error occurred |
- Client obtains Discord OAuth token
- Client sends POST to
/auth/discordwith{ discordToken: "..." } - Server validates with Discord API, creates/updates account and returns JWT
- Client uses JWT for API calls and WebSocket connection
curl -X POST http://localhost:3000/auth/discord \
-H "Content-Type: application/json" \
-d '{"discordToken":"your-discord-oauth-token"}'curl -X POST http://localhost:3000/auth/anonymous \
-H "Content-Type: application/json" \
-d '{"username":"joedoe"}'Deploy to Deno Deploy
The quickest way to deploy is using the button below:
Alternatively, deploy manually via the CLI:
- Install Deno Deploy CLI:
deno install -Arf https://deno.land/x/deploy/deployctl.ts - Deploy:
deployctl deploy --project=your-project main.ts