A multiplayer browser-based real-time strategy game. 1v1 RTS with lobby system, worker-based building, resource gathering, unit combat, and server-authoritative gameplay. Web players get the low-poly 3D view by default; the original 2D view is one key (F3) or one setting away.
Bot-vs-bot battles, captured from replays in the 3D view (blue vs magenta):
![]() |
![]() |
| Shardfall (frost) | Cinder Flats (desert) |
![]() |
![]() |
| Glimmerfen (verdant) | Duskvale (haunted) |
The interface is frosted glass over a live 3D battlefield:
![]() |
![]() |
| Main menu | Play: opponent and map |
![]() |
![]() |
| Online lobby | In match: top bar, command card, minimap |
![]() |
![]() |
| Result: rematch, replay or menu | Replays: filter, star and watch |
The map pool has ten maps in four themes:
![]() |
![]() |
| Verdant: Ironreed, Twin Spires, Glimmerfen | Desert: Basalt Run, Saltmarsh, Cinder Flats |
![]() |
![]() |
| Haunted: Duskvale, Hollow Crown | Frost: Shardfall, Prism Ridge |
CrystalFront-RTS/
├── client/ # React + Vite frontend
├── server/ # Node.js + Express + ws backend
├── shared/ # Shared TypeScript types and constants
├── headless/ # Headless match runner and scripted bots
├── training/ # ML bot training (Python)
├── docs/ # Plans, release notes and screenshots
├── tests/ # Automated tests
├── package.json # Root workspace config
└── tsconfig.json # Root TypeScript config
- Node.js 20+
- npm
npm installnpm run devThis starts both the client (Vite dev server on port 5173) and server (on port 3777) concurrently. The client proxies API requests to the server.
npm run testnpm run buildThis builds the client and server. The server output goes to server/dist/.
npm startThe server serves the built frontend and WebSocket API on port 3777.
The server port is configurable via the PORT environment variable:
PORT=8080 npm startDefaults to 3777 if not set.
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3777 |
The production server is designed to run under a systemd service on a Debian/Ubuntu server.
- Update system packages:
sudo apt update && sudo apt upgrade -y- Install Node.js (if not already installed):
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs- Create a dedicated user (optional but recommended):
sudo useradd -m -s /bin/bash crystalfront
sudo usermod -aG www-data crystalfront- Copy the project to the server (e.g.,
/opt/crystalfront-rts):
# On local machine
scp -r . user@your-server:/opt/crystalfront-rts
# Or clone from git
ssh user@your-server
git clone https://github.com/Tom1tk/CrystalFront.git /opt/crystalfront-rts
cd /opt/crystalfront-rts- Install dependencies and build:
cd /opt/crystalfront-rts
npm install --production
npm run build- Set ownership:
sudo chown -R crystalfront:crystalfront /opt/crystalfront-rtsCreate a systemd service file at /etc/systemd/system/crystalfront-rts.service:
[Unit]
Description=CrystalFront RTS Server
After=network.target
[Service]
Type=simple
User=crystalfront
Group=crystalfront
WorkingDirectory=/opt/crystalfront-rts
Environment=NODE_ENV=production
Environment=PORT=3777
ExecStart=/usr/local/bin/node server/dist/index.js
Restart=on-failure
RestartSec=5
# Restart if process uses more than 512MB memory
MemoryMax=1G
[Install]
WantedBy=multi-user.target# Reload systemd to recognize the new service
sudo systemctl daemon-reload
# Enable the service to start on boot
sudo systemctl enable crystalfront-rts
# Start the service
sudo systemctl start crystalfront-rts
# Check status
sudo systemctl status crystalfront-rts- Check if the service is running:
sudo systemctl is-active crystalfront-rts- Check logs:
sudo journalctl -u crystalfront-rts -f- Test the server:
curl http://localhost:3777# Start
sudo systemctl start crystalfront-rts
# Stop
sudo systemctl stop crystalfront-rts
# Restart
sudo systemctl restart crystalfront-rts
# View logs
sudo journalctl -u crystalfront-rts -f --since "1 hour ago"
# Check resource usage
systemctl status crystalfront-rtsFor production deployment with HTTPS and domain name access:
sudo apt install nginx -yCreate /etc/nginx/sites-available/crystalfront:
server {
listen 80;
server_name your-domain.com www.your-domain.com;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
# WebSocket support
location / {
proxy_pass http://localhost:3777;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# Static assets caching
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
proxy_pass http://localhost:3777;
expires 30d;
add_header Cache-Control "public, immutable";
}
}# Create symlink
sudo ln -s /etc/nginx/sites-available/crystalfront /etc/nginx/sites-enabled/
# Remove default site (optional)
sudo rm /etc/nginx/sites-enabled/default
# Test configuration
sudo nginx -t
# Reload Nginx
sudo systemctl reload nginx# Install Certbot
sudo apt install certbot python3-certbot-nginx -y
# Obtain SSL certificate
sudo certbot --nginx -d your-domain.com -d www.your-domain.com
# Auto-renewal is configured automatically by Certbot
# Test renewal
sudo certbot renew --dry-runFROM node:20-alpine
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY client/package.json ./client/
COPY server/package.json ./server/
COPY shared/package.json ./shared/
# Install dependencies
RUN npm install --production
# Copy source
COPY . .
# Build
RUN npm run build
# Expose port
EXPOSE 3777
# Start server
CMD ["node", "server/dist/index.js"]version: '3.8'
services:
crystalfront:
build: .
ports:
- "3777:3777"
environment:
- NODE_ENV=production
- PORT=3777
restart: unless-stopped
# Optional: Add volume for logs
# volumes:
# - ./logs:/app/logs# Build and run
docker-compose up -d
# View logs
docker-compose logs -f
# Update
docker-compose pull
docker-compose up -d --build# Allow SSH (important!)
sudo ufw allow ssh
# Allow HTTP/HTTPS if using Nginx
sudo ufw allow http
sudo ufw allow https
# Or allow direct port access
sudo ufw allow 3777/tcp
# Enable firewall
sudo ufw enable# Allow established connections
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow SSH
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow HTTP/HTTPS
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Or allow direct port
sudo iptables -A INPUT -p tcp --dport 3777 -j ACCEPT# Navigate to project directory
cd /opt/crystalfront-rts
# Pull latest changes
git pull origin main
# Install dependencies and rebuild
npm install --production
npm run build
# Restart the service
sudo systemctl restart crystalfront-rts
# Check for errors
sudo journalctl -u crystalfront-rts -n 50docker-compose pull
docker-compose up -d --buildCreate a simple health check script:
#!/bin/bash
# /usr/local/bin/crystalfront-health-check.sh
if ! curl -s --max-time 5 http://localhost:3777 > /dev/null; then
echo "CrystalFront server is down!"
sudo systemctl restart crystalfront-rts
fiAdd to crontab for periodic checks:
crontab -e
# Add: */5 * * * * /usr/local/bin/crystalfront-health-check.shThe server logs to the systemd journal, not to individual log files. Log rotation is handled automatically by journald. To control journal log retention and size, configure /etc/systemd/journald.conf:
# Limit journal to 500MB
SystemMaxUse=500M
# Keep logs for 2 weeks
MaxRetentionSec=2weekThen restart journald:
sudo systemctl restart systemd-journaldTo view server logs:
sudo journalctl -u crystalfront-rts -f# Check memory usage
systemctl status crystalfront-rts | grep Memory
# Check CPU usage
top -p $(pgrep -f "server/dist/index.js")
# View real-time logs
sudo journalctl -u crystalfront-rts -f- Port already in use
# Find what's using the port
sudo lsof -i :3777
# Kill the process
sudo kill -9 <PID>- Permission denied
# Fix ownership
sudo chown -R crystalfront:crystalfront /opt/crystalfront-rts- Service won't start
# Check detailed logs
sudo journalctl -u crystalfront-rts -xe
# Test running manually
cd /opt/crystalfront-rts
node server/dist/index.js- WebSocket connection fails
- Ensure Nginx is configured with WebSocket upgrade headers
- Check firewall rules
- Verify CORS settings if accessing from different domain
To run in debug mode with verbose logging:
# Edit systemd service
sudo nano /etc/systemd/system/crystalfront-rts.service
# Add environment variable
Environment=DEBUG=*
# Restart
sudo systemctl restart crystalfront-rts- 3D view (default): low-poly models (Kenney, CC0) with themed terrain. Press F3 in a match, or use Settings → 3D View, to switch to the 2D view; the choice is remembered.
?view=2d/?view=3din the URL overrides it. - Maps: a pool of 10 maps in four themes (verdant, desert, haunted, frost), with high ground, rock, brush and rivers. The host picks the map in the lobby, or leaves it random.
- Fog of war with terrain line of sight: high ground sees over low ground, rock blocks sight, and brush hides units.
- Main Menu: Username input, host game, join by lobby code, Play vs Bot, replays, settings (3D view, sound).
- Lobby System: Create/join lobbies with 6-character codes, ready-up flow, map picker.
- Synchronised start: a loading screen holds the match until both players have loaded, so both see the first tick together.
- RTS Gameplay:
- Six unit types (worker, skirmisher, gunner, bruiser, medic, bulwark) and five buildings (barracks, foundry, supply depot, turret, outpost)
- The bulwark is an unarmed shield: ranged shots that cross its front hit it instead of their target; melee ignores it. Right-click a friendly unit with a bulwark selected and it covers that unit: it stands between the unit and the enemy and follows it, and the unit walks at the bulwark's speed while it is close
- The outpost is a cheap, fragile building (50 resources, 50 health) that trains skirmishers only. It can go on either half of the map, on any ground you can currently see (worker card: A), and it needs a finished barracks: without one it cannot be placed and its training queue stands still. On the enemy half of the map it is built in 50 ticks (a barracks takes 150) and trains a skirmisher in 25 ticks (a barracks takes 100); on your own half it is no faster than a barracks. The placement preview says which half the spot is on.
- Worker-based building, with several workers able to build together
- Resource gathering with range limits
- Unit movement, selection, attack-move and rally points
- Combat system with range-based attacks
- Win by destroying the enemy or by holding the map's control nodes
- Bots: Play vs Bot against scripted opponents (passive, rush variants, turtle, macro, heavy).
- Replays: every completed match is recorded; browse and play back at variable speed, forward or reverse.
- Sound: sound effects with an on/off setting.
- Match Flow: Both players ready → loading → gameplay → match end screen
- Rematch: Same lobby persists, score tracks across rematches
- WebSocket Sync: Real-time state synchronization between clients and server
- Server-Authoritative: Server is source of truth for all game state
- Site-wide UI refresh to match the 3D look (see
docs/UI_PLAN.md) - Retrained ML bot that adapts to the opponent (see
docs/ML_RETRAIN_PLAN.md) - Unit upgrades and technology tree
- Reconnect on refresh
- Chat system
- External matchmaking
- Workers construct buildings by traveling to the placement location
- Multiple workers can contribute to the same building to speed up construction
- Construction progress only increases when workers are within range (60 units)
- Workers are occupied for the entire construction duration
- Building placement is restricted to the player's half of the map
- Workers gather resources from nodes within range (60 units)
- Gathering is shown with visual indicators on the game map
- Workers can be reassigned from gathering to building or combat
- Units attack enemies within their attack range
- Ranged units can attack from a distance
- Melee units must be close to enemies
- HP bars show current health above units
Private project.
This is a private project. For questions or collaboration, please contact the repository owner.













