Overview
Hyperscape is a real-time multiplayer game using WebSocket connections for low-latency communication between clients and the authoritative server.Network Architecture
Server Authority
The server is the single source of truth:Clients predict movement locally but server corrects if needed.
Entity Synchronization
Sync Flow
- Server processes game tick (600ms)
- Entity changes collected via
markNetworkDirty() - Delta updates sent to clients at 20 Hz
- Clients apply updates and interpolate
Entity Network Data
Sync Data
WebSocket Protocol
Connection
Message Types
Persistence
Database Schema
Player data stored in PostgreSQL using Drizzle ORM:Save Strategy
- Immediate: Critical changes (item transactions)
- Periodic: Stats, position (every 30 seconds)
- On disconnect: Full state save
Authentication
Using Privy for identity:- Client authenticates with Privy
- JWT token sent to server
- Server validates token
- Session established
LiveKit Integration
Optional voice chat via LiveKit:- Spatial audio based on position
- Push-to-talk or voice activation
- Server-managed rooms
LIVEKIT_API_KEY and LIVEKIT_API_SECRET.
Scalability
Current Architecture
- Single server instance
- All players in shared world
- SQLite for development, PostgreSQL for production
Future Considerations
- Multiple server instances
- Zone-based sharding
- Load balancing