Architecture Overview
The game is split into four components:Client
Handles rendering, UI, and user input
Core
Deterministic simulation engine
Server
Coordinates players and relays game state
API
Authentication, stats, and monetization
Client Component
Location:/src/client/
The client is responsible for:
- Rendering game graphics using PixiJS
- Handling user input and UI interactions
- Managing the WebSocket connection to the game server
- Running a Web Worker that executes the core simulation
- Displaying game updates received from the core
The client does NOT handle game logic. All game state modifications happen in the core component.
Key Technologies
- PixiJS for 2D rendering
- Lit for UI components
- Web Workers for running core simulation in a separate thread
- Vite for development and bundling
Core Component
Location:/src/core/
The core is the heart of OpenFront’s deterministic simulation:
Core Characteristics
- Pure TypeScript/JavaScript with no external dependencies
- Runs in a Web Worker on the client side
- Fully deterministic - given the same inputs, always produces the same outputs
- Executes game logic through the Intent → Execution pattern
Why Deterministic?
By making the simulation deterministic, each client can run its own instance of the game logic. This eliminates the need for the server to simulate the game, reducing server load and enabling game replays.Server Component
Location:/src/server/
The server is a lightweight coordinator built with Express and WebSockets:
- Manages player connections
- Collects intents from all players
- Bundles intents into “turns” and broadcasts them
- Does NOT run game simulation
- Handles lobby creation and matchmaking
The server does not validate game logic. It trusts that all clients running the same deterministic core will reach the same game state.
API Component
Location: Closed-source Cloudflare Worker The API handles:- User authentication and accounts
- Player statistics and leaderboards
- Game data storage
- Cosmetics and monetization
- RESTful endpoints for non-realtime operations
Simulation Architecture
Client-Side Simulation
The game simulation does not run on the server. Instead, each client runs their own instance of core in a Web Worker thread. This architecture:- Reduces server computational load
- Enables instant local feedback
- Allows game replays by re-running intents
- Requires strict determinism in the core
Communication Flow
Game Flow
Execution Creation
Core creates an “Execution” for each intent. Executions are the only thing that can modify game state
Intent → Execution Pattern
Directory Structure
Key Design Principles
- Determinism First: Core must be deterministic to enable client-side simulation
- Separation of Concerns: Client renders, core simulates, server coordinates
- Intent-Based Actions: All player actions are intents that become executions
- No Server Simulation: Server never runs game logic, only relays data
- Thread Isolation: Core runs in a Web Worker for performance
Related Documentation
Development Setup
Set up your local development environment
Testing Guide
Learn how to test core game logic