Reference backend implementation for GameBackendSDK
Fast Bun runtime + SQLite + Admin Dashboard
Features β’ Quick Start β’ API Endpoints β’ Admin Panel β’ Deployment
β οΈ This is the backend server. You need both repositories to build a complete solution:
- Backend API: Godot-GameBackendAPI (server-side - this repo)
- Godot SDK: Godot-GameBackendSDK (client-side)
| Feature | Description |
|---|---|
| π Bun Runtime | Lightning-fast JavaScript runtime |
| ποΈ SQLite Database | Persistent storage, zero configuration |
| π JWT Authentication | Secure access & refresh token system |
| π Admin Dashboard | Real-time stats, user management, live console |
| π WebSocket | Live request streaming to admin panel |
| π‘οΈ Security | Helmet.js, CORS, request logging |
| β Guest Auth | Guest authentication support |
| πΎ Cloud Storage | Key-value storage with versioning |
| π Leaderboards | Automatic ranking system |
| βοΈ Remote Config | Platform-specific configuration |
- Bun v1.0+
- Godot-GameBackendSDK (for testing with Godot)
git clone https://github.com/hoxsec/Godot-GameBackendAPI.git
cd Godot-GameBackendAPI
bun installbun devThe server starts at http://localhost:3000
- Make sure this backend server is running
- Install the Godot-GameBackendSDK in your Godot project
- Initialize the SDK with
http://localhost:3000as the base URL - Test all features using the demo scene included in the SDK
bun startThe backend includes a modern admin panel with real-time features:
| Page | Description |
|---|---|
| π Dashboard | Live RPS chart, stats overview, recent requests |
| π‘ Console | Real-time request streaming via WebSocket |
| π₯ Users | User management, ban/unban functionality |
| πΎ KV Store | Browse and manage key-value data |
| π Leaderboards | View and manage leaderboard entries |
| π§ Endpoints | Interactive API tester |
Access: http://localhost:3000/dashboard
Default Credentials: admin / admin123
| Method | Endpoint | Description |
|---|---|---|
POST |
/v1/auth/guest |
Create guest session |
POST |
/v1/auth/register |
Register new user |
POST |
/v1/auth/login |
Login existing user |
POST |
/v1/auth/refresh |
Refresh access token |
POST |
/v1/auth/logout |
Logout (invalidate tokens) |
| Method | Endpoint | Description |
|---|---|---|
GET |
/v1/kv/:key |
Get stored value |
PUT |
/v1/kv/:key |
Set value |
DELETE |
/v1/kv/:key |
Delete value |
| Method | Endpoint | Description |
|---|---|---|
POST |
/v1/leaderboards/:board/submit |
Submit score |
GET |
/v1/leaderboards/:board/top |
Get top entries |
GET |
/v1/leaderboards/:board/me |
Get user's rank |
| Method | Endpoint | Description |
|---|---|---|
GET |
/v1/config |
Get remote config |
GET |
/health |
Health check |
curl -X POST http://localhost:3000/v1/auth/guestResponse:
{
"user_id": "guest_1234567890_abc123",
"access_token": "eyJhbGc...",
"refresh_token": "eyJhbGc..."
}curl -X POST http://localhost:3000/v1/auth/register \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "secure123"}'curl -X PUT http://localhost:3000/v1/kv/player_data \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"value": {"level": 10, "coins": 5000}}'curl -X POST http://localhost:3000/v1/leaderboards/global/submit \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"score": 9999}'curl "http://localhost:3000/v1/leaderboards/global/top?limit=10" \
-H "Authorization: Bearer YOUR_TOKEN"Create a .env file:
PORT=3000
JWT_SECRET=your-super-secret-key-change-this
NODE_ENV=production| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Server port |
JWT_SECRET |
dev-secret |
JWT signing secret ( |
NODE_ENV |
development |
Environment mode |
This backend uses SQLite for persistent storage via Bun's built-in SQLite support.
- users: Stores user accounts (guest & registered)
- kv_store: Key-value storage per user with versioning
- leaderboards: Score submissions with automatic ranking
- refresh_tokens: Token tracking and revocation
The database file is created at game.db on first run.
The backend includes database management tools:
bun run db:stats # Show database statistics
bun run db:export # Export to JSON
bun run db:clear # Clear all data (keeps schema)
bun run db:reset # Full reset (WARNING: deletes everything!)To reset manually, delete game.db and restart the server.
Use any SQLite viewer or the sqlite3 CLI:
sqlite3 game.db
sqlite> SELECT * FROM users;
sqlite> SELECT * FROM leaderboards;
sqlite> .quit- Create a new project on Railway
- Connect your GitHub repository
- Add environment variables:
PORT=3000 JWT_SECRET=your-super-secret-key-change-this NODE_ENV=production - Deploy!
- Create a new Web Service on Render
- Connect your repository
- Configure:
- Build Command:
bun install - Start Command:
bun start
- Build Command:
- Add environment variables
- Deploy!
Create a Dockerfile:
FROM oven/bun:1
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --production
COPY . .
ENV PORT=3000
ENV NODE_ENV=production
EXPOSE 3000
CMD ["bun", "start"]Build and run:
docker build -t gamebackend .
docker run -d -p 3000:3000 -e JWT_SECRET=your-secret gamebackend# Install dependencies
bun install
# Create environment file
cat > .env << EOF
PORT=3000
JWT_SECRET=your-super-secret-key-change-this
NODE_ENV=production
EOF
# Start with PM2 (recommended for production)
npm install -g pm2
pm2 start "bun start" --name gamebackend
# Or run directly
bun startGameBackendAPI/
βββ server.js # Main Express server
βββ routes/
β βββ auth.js # Authentication endpoints
β βββ kv.js # Cloud storage endpoints
β βββ leaderboards.js # Leaderboard endpoints
β βββ config.js # Remote config endpoint
β βββ admin.js # Admin API endpoints
βββ utils/
β βββ auth.js # JWT helpers & middleware
β βββ database.js # SQLite setup & queries
β βββ websocket.js # WebSocket server
β βββ requestLogger.js # Request logging
βββ public/ # Admin panel HTML/CSS/JS
β βββ dashboard.html
β βββ console.html
β βββ users.html
β βββ kv.html
β βββ leaderboards.html
β βββ endpoints.html
βββ package.json
βββ db-tools.js # Database management utilities
βββ README.md
Before deploying to production:
- Change
JWT_SECRETto a strong, unique value - Enable HTTPS (use a reverse proxy like nginx/caddy)
- Implement password hashing (bcrypt)
- Add rate limiting
- Set up database backups
- Configure proper logging
- Change default admin credentials
- Review CORS settings
- Add input validation
- Set up monitoring (Sentry, etc.)
bun run test:db # Test database operationsHaving issues? Check the Troubleshooting Guide for common problems:
- SQLITE_CONSTRAINT_FOREIGNKEY - Invalid session after database reset
- Database locked - Multiple processes accessing database
- Token expired - Need to refresh access token
- Troubleshooting Guide - Common issues and solutions
- SQLite Implementation Details - Full database documentation
- Bun SQLite Documentation
- SQLite Official Documentation
This project is licensed under the MIT License - see the LICENSE file for details.
- π Godot SDK Repository
- π Report Issues
- π‘ Request Features
Made with β€οΈ for game developers
