A real-time multiplayer quiz application, built in Go and React. Features WebSocket-based gameplay, live leaderboards,live chat and scalable architecture designed to handle 50,000+ concurrent users.
- Real-time Multiplayer: WebSocket-based real-time communication
- Lobby System: Create and join game lobbies
- Live Scoring: Real-time leaderboards with streak bonuses
- In-game chat: Players can text and communicate with each other in-game.
- Responsive UI: Works on desktop and mobile devices
- Auto-reconnection: Handles network disconnections gracefully
- Go 1.21 or higher
- PostgreSQL (optional, for production)
- Clone the repository:
git clone <repository-url>
cd buildprize-game- Install dependencies:
go mod tidy- Run the server:
go run main.go- The server will start on
http://localhost:8080
POST /api/v1/lobbies- Create a new lobbyGET /api/v1/lobbies- List available lobbiesPOST /api/v1/lobbies/:id/join- Join a lobbyPOST /api/v1/lobbies/:id/leave- Leave a lobbyPOST /api/v1/lobbies/:id/start- Start the gamePOST /api/v1/lobbies/:id/answer- Submit an answer
join_lobby- Join a lobby via WebSocketleave_lobby- Leave a lobbystart_game- Start the gamesubmit_answer- Submit an answer
- Create/Join Lobby: Players create or join a lobby
- Wait for Players: Lobby waits for minimum 2 players
- Start Game: Host starts the game
- Questions: Server sends questions with time limits
- Scoring: Points awarded for correct answers and speed
- Leaderboard: Real-time leaderboard updates
- Game End: Final results and winner announcement
- Base Score: 100 points for correct answer
- Speed Bonus: Up to 50 points for fast responses
- Accuracy Bonus: 25 points for correct answers
- Streak Bonus: Multiplier for consecutive correct answers
The application uses several design patterns:
- Event-Driven Architecture: Real-time updates via WebSocket events
- Repository Pattern: Abstracted data persistence layer
- Observer Pattern: Hub system for client notifications
- Command Pattern: WebSocket message handling
- Singleton Pattern: Global game state management
- Load balancing across multiple server instances
- PostgreSQL for shared session state
- Regional deployment for reduced latency
- Connection pooling
- Message batching
- Database caching
- CDN for static assets
buildprize-game/
├── main.go # Application entry point
├── internal/
│ ├── config/ # Configuration management
│ ├── models/ # Data models
│ ├── hub/ # WebSocket hub system
│ ├── services/ # Business logic
│ ├── repository/ # Data persistence
│ └── server/ # HTTP/WebSocket server
└── ARCHITECTURE_FLOW.md # Detailed architecture docs
- New Game Modes: Extend the
GameServicewith new game logic - Question Categories: Add to
QuestionDatabaseinservices/questions.go - Scoring Rules: Modify
calculateScoreinservices/game_service.go
- Open multiple browser tabs
- Create a lobby in one tab
- Join the lobby from other tabs
- Start the game and test the flow
# Run Go tests
go test ./internal/testing -v
# Or use Makefile
make test# Build image
docker build -t buildprize-game .
# Run container
docker run -p 8080:8080 buildprize-gameThe application is configured for Railway deployment with automatic PostgreSQL database provisioning.
PORT: Server port (default: 8080)DATABASE_URL: PostgreSQL connection URL (required)MAX_LOBBY_SIZE: Maximum players per lobby (default: 8)QUESTION_TIME: Time per question in seconds (default: 30)
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details