Skip to main content

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

  1. Server processes game tick (600ms)
  2. Entity changes collected via markNetworkDirty()
  3. Delta updates sent to clients at 20 Hz
  4. 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:
  1. Client authenticates with Privy
  2. JWT token sent to server
  3. Server validates token
  4. Session established
Without Privy credentials, each session creates a new anonymous identity.

LiveKit Integration

Optional voice chat via LiveKit:
  • Spatial audio based on position
  • Push-to-talk or voice activation
  • Server-managed rooms
Configure with 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

Network Files