Skip to main content

Overview

Hyperscape uses a CDN-based architecture for serving game assets (3D models, textures, audio, manifests). The system supports local development with Docker nginx, production deployment to Cloudflare R2, and automatic fallback for incomplete local caches. CDN code lives in:
  • scripts/cdn.mjs - Local CDN Docker management
  • scripts/ensure-assets.mjs - Asset download and LFS handling
  • packages/server/src/startup/config.ts - Manifest fetching and validation

Architecture

Local Development CDN

Docker nginx Setup

The local CDN runs in a Docker container serving from packages/server/world/assets:

Starting the CDN

Force-recreate is important when assets directory is replaced - it ensures volume mounts refresh.

Asset Directory Structure

Manifest Validation

Required Manifests

The server validates that critical manifests exist before starting:

Validation Flow

If required manifests are missing, server throws error:

Production CDN Fallback

In development, if the local CDN is incomplete, the server automatically falls back to production:
This allows developers to start the game even if they haven’t downloaded the full asset pack.

Asset Download

Automatic Download

Assets are automatically downloaded during bun install:

Full Asset Detection

The script distinguishes between full assets and manifests-only:
If only manifests exist, the script downloads the full asset pack.

Git LFS Handling

Partial Directory Cleanup

If a partial/manifest-only directory exists, it’s removed before cloning:

Production Deployment

Cloudflare R2

Production assets are deployed to Cloudflare R2:
Workflow: .github/workflows/deploy-cloudflare.yml
  • Triggers on push to main branch
  • Uploads assets to R2 bucket
  • Sets PUBLIC_CDN_URL environment variable

Environment Variables

Both client and server need the CDN URL to load assets.

CDN Verification

Test CDN health and asset availability:
Tests:
  • Health check endpoint
  • Music files (normal/combat)
  • Manifest files
  • Environment models and textures

Manifest Fetching

Server fetches manifests from CDN on startup:

Caching Strategy

  • Development: Skip fetch if required manifests exist locally
  • Production: Always fetch from CDN
  • Fallback: Use production CDN if localhost CDN incomplete

PhysX Assets

PhysX WASM runtime is copied to the CDN: