Deploying
You can run the whole mall two ways: with docker compose on any machine, or on Railway, which the demo uses (ADR 0005 explains why). Both run the same images.
| Piece | Image | Compose | Railway |
|---|---|---|---|
web: nginx serving the built site, proxying /ws, /api, /files, /health, /host-token, /directory/ to the server | client/Dockerfile | web | service web (public domain) |
server: multiplayer, content API, uploads | server/Dockerfile | server | service server (private only) |
| Postgres | stock | postgres:17 | Railway Postgres template (18) |
| Object storage | S3-compatible | SeaweedFS | Railway bucket uploads |
| Daily backup | tools/backup/Dockerfile | run by hand | service backup, cron 0 3 * * * |
Settings
server
| Variable | What |
|---|---|
DATABASE_URL | Postgres. Migrations run on start, and an empty database is seeded from mall.config.ts. |
S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_REGION | Uploads bucket. |
S3_URL_STYLE | virtual for Railway and AWS (bucket in the hostname). Leave unset for SeaweedFS and MinIO. |
HOST_SECRET | The host password: signs in on the landing screen and at /admin/. Unset means no host and no admin. |
PORT | Default 8787. |
MAX_PLAYERS, MAX_PER_IP | The most people in the mall at once (default 20), and connections per IP address (default 5). |
CHAT_KEEP_DAYS, CHAT_SHOW_MIN | Days of chat history to keep (default 30), and how far back newcomers see it, in minutes (default 60). |
AWAY_AFTER_S, DROP_SILENT_S, IDLE_KICK_MIN | When someone shows as away (15 s), leaves because their tab is in the background (120 s), or leaves for being idle (15 min, 0 for never). See the configuration guide. |
MAIL_PROVIDER, RESEND_API_KEY, MAIL_FROM, MAIL_REPLY_TO, RESEND_WEBHOOK_SECRET, PUBLIC_URL | Email approved applicants, and set-password links to new shop owners (Resend by default); with the webhook secret, track bounces. See the configuration guide. |
ROOM_CAPACITY, REPORT_WEBHOOK, RENTAL_WEBHOOK, BLOCKLIST_FILE, METRICS | Optional, see .env.example. |
web
| Variable | What |
|---|---|
PORT | Port nginx listens on (default 80). |
API_UPSTREAM | host:port of the server (default server:8787). It's looked up per request, so the web can start before the server. |
CLIENT_IP_FROM | Where each visitor's IP address comes from, for the per-visitor limits. See Behind a proxy or CDN. |
backup: DATABASE_URL, the same S3_* as the server, KEEP (dumps to keep, default 30), and the build argument PG_MAJOR, which must be at least the database's major version.
Railway
The production project shopping-mall runs in Singapore (asia-southeast1, bucket region sin) and is served at https://mall.devmtnaing.com, through Cloudflare's proxy. Railway's own address for it, https://web-production-cc219.up.railway.app, still works too. Every service builds from main on GitHub. Watch paths keep a docs-only push from rebuilding anything.
| Service | Dockerfile (RAILWAY_DOCKERFILE_PATH) | Notable settings |
|---|---|---|
web | client/Dockerfile | Public domains on port 8080 (mall.devmtnaing.com and Railway's own), PORT=8080, API_UPSTREAM=${{server.RAILWAY_PRIVATE_DOMAIN}}:8787, CLIENT_IP_FROM=cloudflare, health check / |
server | server/Dockerfile | PORT=8787, DATABASE_URL=${{Postgres.DATABASE_URL}}, S3_*=${{uploads.*}}, S3_URL_STYLE=virtual, HOST_SECRET, health check /health |
backup | tools/backup/Dockerfile | Cron 0 3 * * * (UTC), restart never, PG_MAJOR=18, same database and bucket references |
Postgres | Railway template | Volume postgres-volume |
uploads | Railway bucket | Private. Files reach visitors through the server's /files/ route. |
.railway/railway.ts describes the same project as code (Railway IaC). It keeps the one secret, HOST_SECRET, out of the repo with preserve(). To compare it with the live project, install the SDK next to it (npm install railway, left out of the repo's dependencies) and run railway link, then railway config plan (Railway CLI 5 or newer, or npx @railway/cli@latest). A whole-project apply deletes anything the file leaves out, so read the plan first.
One click: . The template creates all five pieces with the variables above, and only asks you for
HOST_SECRET.
To set it up by hand, create a project with the Postgres template and a bucket named uploads, add three empty services with the names above, set the variables from the table, connect the repo and give web a domain. Or edit .railway/railway.ts and run railway config apply.
Behind a proxy or CDN
The server limits how many connections one visitor can have (MAX_PER_IP, 5 by default), and how often they can try the host password. For that it needs each visitor's own IP address. When something sits in front of the mall (a CDN, a load balancer, another reverse proxy), the web container sees that thing's address instead, for every visitor, unless you tell it which header carries the real one. Set CLIENT_IP_FROM on the web container:
| What's in front of the mall | CLIENT_IP_FROM |
|---|---|
| Nothing: visitors connect straight to your server (a VPS or droplet running docker compose) | direct (the default) |
| Railway, without a CDN | x-real-ip (picked automatically on Railway) |
| Cloudflare's proxy (the orange cloud) | cloudflare |
A load balancer or proxy that adds X-Forwarded-For: DigitalOcean's load balancer and App Platform, AWS, Caddy, Traefik, most CDNs | x-forwarded-for |
Only choose a header when a proxy really sets it, because otherwise visitors could send it themselves and pretend to be someone else. With x-forwarded-for, the last address in the header is used: the one added by the proxy directly in front of the mall. If there are two proxies in a row (a CDN and then a load balancer), use the CDN's own header if it has one, or switch the per-visitor limit off with MAX_PER_IP=0 on the server.
The web container prints which one it's using when it starts (client-ip: visitors' addresses come from: …). If this is set up wrong, the server's log says limits: turned a connection away… and visitors start seeing "too many connections from here", even though the mall isn't full.
Caching with a CDN
Everything under /assets/ is safe for a CDN to keep for good. The page asks for each model, sound and portrait with a fingerprint of the file's contents (mall.glb?v=6d165415be), and nginx marks those responses immutable. A rebuilt file gets a new fingerprint and so a new address, so a cache never serves a stale copy and there's nothing to purge. Uploads under /files/ are named by their contents too, and the server marks them the same way. The page itself, /api/ and /ws are never cached.
With Cloudflare, add one Cache Rule (Caching → Cache Rules): when the URI path starts with /assets/ or /files/, mark it eligible for cache, and leave the edge and browser TTLs to respect the origin's headers. Keep the default cache key, which includes the query string, since the fingerprint is in it.
Abuse and floods
Everything that reaches the server is limited per visitor IP address, so the IP settings above matter here too. There are three layers, and the outer ones take the most load:
| Layer | What it does |
|---|---|
| Cloudflare (if it's in front) | Absorbs real DDoS traffic, which nothing behind it can. It's on as soon as the orange cloud is, and the settings below tighten it. |
| nginx (the web container) | Lets each address send 20 requests a second to the server (/api/, /ws, /files/, /directory/, /host-token), with bursts of 60. The rest get a 429 without ever reaching Node. Headers have to arrive within 15 s and a body can't stall for 30 s, so slow-request floods time out. Static files aren't limited. |
| The server | Finer limits per address. Any request except /health: 120, then 20 a second. New WebSocket connections: 10, then one every 2 s, and at most MAX_PER_IP open at once. Rental applications: 3, then one every 20 minutes (60 an hour from everyone together). Host sign-in: 5, then one a minute. Shop-owner sign-in, invite links and setting a password: 5, then one a minute. Usage events: 10 batches, then one every 10 s; extra ones are dropped. On the WebSocket itself it also limits chat, emotes, apples, reports and character changes, and checks movement. |
The server also keeps /api/content and /directory/ in memory until the content changes, so a flood of reads costs it one small database query each instead of a full load.
With Cloudflare, these settings are in the dashboard for your domain (dash.cloudflare.com, then pick the domain). Cloudflare moves menus around now and then. If a path below doesn't match, search the dashboard for the setting's name.
A rate-limiting rule for the forms and sign-ins. This is the one that matters most. Go to Security → Security rules (older dashboards: Security → WAF → Rate limiting rules), then Create rule → Rate limiting rules:
When incoming requests match: click Edit expression and paste this. Each path needs its own quotes, separated by spaces:
(http.request.uri.path in {"/api/rentals" "/host-token" "/api/owner/sign-in" "/api/owner/password" "/api/owner/invite"})With the same characteristics: IP. When rate exceeds: 10 requests per 10 seconds. Then take action: Block, for 10 seconds.
The free plan allows one such rule and can only match on the path, not the method or the hostname, so it applies to these paths on every subdomain. Only the mall uses them. A person filling in a form never comes close to 10 in 10 seconds. A script hammering them is stopped at Cloudflare and never costs you anything on Railway.
The paths come from
server/src/routes.ts, where every route says who may call it and how it's limited. CI fails if a route in the code isn't declared there, or if the expression above is out of date. When a change to the list reachesmain, CI opens an issue with the new expression, so the rule in Cloudflare gets updated too.Bot Fight Mode (optional). Go to Security → Settings, filter by Bot traffic, and switch on Bot fight mode (older dashboards: Security → Bots). It challenges traffic that looks automated. It covers the whole domain: every subdomain, not just the mall. It can't be limited to one hostname, and no rule can make an exception. Real browsers pass, and search engines are let through. But anything else on the domain that's called by scripts (an API, webhooks, an uptime monitor, a mobile app) may start being challenged. Leave it off if something like that lives on the domain.
Under Attack Mode, only during an actual attack. Every visitor gets a few seconds of browser check before the page loads, so turn it off afterwards. The switch under Overview → Quick Actions covers the whole domain. To cover just the mall, use a Configuration Rule instead: Rules → Configuration Rules → Create rule, Hostname equals
mall.devmtnaing.com, then Security Level: I'm Under Attack. Turn the rule on when you need it and off afterwards.
Know the way around Cloudflare. Railway's own address (*.up.railway.app) skips Cloudflare entirely, and so does anyone who sends requests straight to Railway with your domain name. On that path a visitor can also send a made-up CF-Connecting-IP with each request, so every request looks like it came from someone new and the per-IP limits stop working. The limits on everyone together (rentals and sign-ins) still hold. Removing the Railway domain from the web service, once the custom domain works, closes the easy way round. Closing it completely means having Cloudflare add a secret header to every request (a Transform Rule) and nginx refusing requests without it. That isn't built yet.
Backups and restoring
The backup service runs pg_dump --format=custom every night and uploads it to the bucket as backups/mall-<UTC time>.dump, keeping the newest 30. The server never serves these files (/files/ only serves <kind>/<sha256>.<ext>). The uploaded files aren't in the dump, since they're already in the bucket, named by their content hash.
To run a backup now on Railway, open the backup service and choose Run now, or redeploy it.
To restore, run the same image's restore.sh with the database and bucket settings. It downloads the dump and replaces every table in it, in one transaction.
docker build -f tools/backup/Dockerfile --build-arg PG_MAJOR=18 -t shopping-mall-backup .
# restore.env: DATABASE_URL (Railway: the Postgres service's DATABASE_PUBLIC_URL) and the S3_* values
docker run --rm --env-file restore.env shopping-mall-backup /usr/local/bin/restore.sh latest
# or a specific one: … restore.sh mall-2026-09-29T030000Z.dumpThen restart the server service, so visitors reconnect and pick up the restored content.
We tested this on 2026-09-29. Locally, with compose, we backed up, deleted a shop and restored: the shop and its products came back, and KEEP removed the older dumps. On Railway, the cron job wrote backups/mall-2026-09-28T202057Z.dump to the bucket.
docker compose
cp .env.example .env # set HOST_SECRET to use /admin/
docker compose up --build # → http://localhost:8080 (WEB_PORT to change)Postgres data and uploads live in the pgdata and s3data volumes. To back up the database, run docker compose exec postgres pg_dump -U mall -Fc mall > mall.dump, and to restore it, docker compose exec -T postgres pg_restore -U mall -d mall --clean --if-exists < mall.dump.