A high-performance, concurrent Go backend for Capture The Flag (CTF) competitions.
- Real-time leaderboard with intelligent caching
- Atomic flag validation preventing race conditions
- User progress tracking across multiple challenge levels
- Optimized performance with prefetching and in-memory caching
- Graceful shutdown and signal handling
- Go - Backend server
- MongoDB - Database
- CORS-enabled REST API
- Go 1.16+
- MongoDB instance
-
Install dependencies
go mod download
-
Set environment variables
export MONGODB_URI="your_mongodb_connection_string" export PORT=10000 # Optional, defaults to 10000
-
Run the server
go run main.go
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/test |
Health check |
| GET | /getLevel?userId={id} |
Get user's current level |
| POST | /checkFlag |
Submit a flag |
| POST | /resetUser |
Reset user progress |
| POST | /deleteUser |
Delete a user |
| GET | /api/leaderboard |
Get top 100 players |
| GET | /api/challenges |
List all challenges |
curl -X POST http://localhost:10000/checkFlag \
-H "Content-Type: application/json" \
-d '{"userId": "player1", "flag": "CTF{...}"}'curl http://localhost:10000/api/leaderboard- O(1) challenge lookups via hash maps
- User data prefetching for reduced latency
- Leaderboard caching with background refresh
- Database indexes for optimized queries
- Atomic operations for thread-safety
Run with race detector:
go run -race main.goBuild for production:
go build -o ctf-server main.goMIT