Files
tssbot.web/backend/README.md
T
Liam 341dae1913 feat: replace PM2 with systemd --user services for production
Runs tssbot-web, tssbot-webhook, and tssbot-backend as systemd --user
units instead of PM2 processes. tssbot-web moves from a 2-worker PM2
cluster to a single instance, so deploys now restart it directly
instead of doing a zero-downtime cluster reload.

webhook.cjs now shells out to `systemctl --user restart` instead of
`pm2 reload`, and PM2_RESTART_TARGETS/WEBHOOK_PM2_NAME are renamed to
RESTART_TARGETS/WEBHOOK_SERVICE_NAME. scripts/install-systemd-services.sh
symlinks the new unit files into ~/.config/systemd/user and enables them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-01 22:58:15 +00:00

2.1 KiB

tssbot backend

Rust backend API service for Toothless' TSS Bot.

It reads two SQLite databases:

  • TSS_BATTLES_DB for tss_battles.db (matches, players, and the match_logs table)
  • TSS_TEAMS_DB for tss_teams.db
  • TSS_TOURNAMENTS_DB for tss_tournaments.db

If any of these are unset, the backend first looks under STORAGE_VOL_PATH before falling back to the current working directory.

  • BACKEND_HOST bind host, default 127.0.0.1
  • BACKEND_ALLOWED_ORIGINS comma-separated browser origins allowed by CORS

Both paths can be absolute or relative to the repo root when run through the root scripts/systemd units.

Vehicle translation + icons

At startup the backend loads two cache files (built by the bots, shared under STORAGE/CACHE) into memory to translate player_games_hist.vehicle_internal (the WT cdk) into localized vehicle names and icon filenames for the game scoreboard:

  • VEHICLE_TRANSLATIONS_JSONvehicle_translations.json ({ cdk: { en, ru, ... } }). The /api/tss/games/:id endpoint honors ?lang= (default en), falling back lang → en → raw cdk.
  • VEHICLE_DATA_CACHE_JSONvehicle_data_cache_all.json ([cdk, name, icon, tags]), used for icon filenames (fallback <cdk>.png).

The icon PNGs themselves are served statically by the frontend at /vehicle-icons (deploy-time copy/symlink of SHARED/ICONS/VEHICLES).

It currently exposes:

  • GET /health
  • GET /api/tss/leaderboard/teams?limit=100
  • GET /api/tss/leaderboard/players?limit=100
  • GET /api/tss/games/recent?limit=50
  • GET /api/tss/games/:session_id?lang=en — scoreboard (teams, players, vehicle lineup)
  • GET /api/tss/games/:session_id/logs — chat + battle logs from match_logs
  • GET /api/tss/teams/resolve?name=...
  • GET /api/tss/teams/search?q=...&limit=10
  • GET /api/tss/teams/:team
  • GET /api/tss/teams/:team/history
  • GET /api/tss/teams/:team/games
  • GET /api/tss/player/:uid

Local development

npm run dev:backend

The backend listens on http://127.0.0.1:6000 by default. Override with BACKEND_PORT and BACKEND_HOST.

Production build

npm run build:backend