bonaminandClaude Opus 5.5 9ccb47cfd1 feat(cloud): online orders keep the delivery area's id for the site's fee check
The site checks the cloud's delivery fee with its own engine when it pulls an order (plan
phase 3S, step S.5) and needs the area by id: a name can change between a menu push and
the order. New column online_orders.delivery_area_id (migration 0004), set from the priced
cart, and in the pending-orders payload (C-4, additive).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:38:00 +02:00

cloud-service — VPS Pack

Everything that runs on the developer's VPS and serves all client sites. This folder is its own git repo, nested inside the xenia-pos parent repo.

Read the global rules first: ../../docs/README.md. This file adds only the rules specific to this pack. The feature catalog, the local ↔ cloud contract, known issues and site records all live in the parent's docs/.


Services

Service Stack Host port Audience
cloud_backend FastAPI + SQLAlchemy + SQLite (${BACKEND_DATA}) 8001 local sites (heartbeat/sync), sysadmin, connect apps
sysadmin_panel React + Vite (VITE_CLOUD_URL baked in at build) 5175 the developer only
connect_frontend nginx serving three SPAs: menu-app at /menu/ (QR menu), order-app at /order/ (online ordering: takeaway, delivery; phase 3S), manager-app at /manage/ 3100 restaurant customers, remote managers

TLS and domains are handled in front of these ports on the VPS (xenia-api.bonamin.net → cloud_backend, xenia-admin.bonamin.net → sysadmin panel, registry.bonamin.net → image registry).

Routers (cloud_backend/routers/)

Prefix File Auth Used by
/api/auth auth.py admin login sysadmin panel
/api/sites sites.py admin bearer sysadmin panel
/api/heartbeat heartbeat.py X-Site-ID + X-Site-Key local sites
/api/menu menu.py public GET; site headers for sync menu-app, local sites
/api/orders orders.py public create/quote/slots/track (priced by services/checkout.py, fees services/fees.py, hours and slots services/ordering.py, rate-limited services/ratelimit.py; never the browser's numbers); site headers for pending/synced/status (own site only) menu-app, order-app, local sites
/api/manager manager_auth.py manager bearer manager-app, sysadmin
/api/remote remote_dashboard.py manager bearer; site headers for POST /snapshot manager-app, local sites

Pack-specific rules

Branch platform-v2: CL-1 applies within v2 only (v1 sites stay on the main cloud until cutover, D-21), and CL-2 is replaced by Alembic (below). The license token is v: 2 with a modules map (CL-6).

CL-1. Old sites are always talking to you. Sites upgrade slowly, and some may be several versions behind. Every endpoint a site calls (the contract, C-1 … C-7) must stay backward compatible:

  • add optional fields only
  • never rename, remove or retype fields
  • never make a new request field required

Any change to one of these endpoints updates the parent's docs/reference/cloud-contract.md (global Rule 6).

CL-2. Schema changes are Alembic revisions (branch platform-v2, D-22). Change the model, add it to models/all.py if new, then from cloud_backend/: alembic revision --autogenerate --rev-id NNNN_short_name -m "...", review the file, run python -m pytest tests -q (drift guard, stamp+upgrade test). create_all is never used. The production DB is stamped to 0001_cloud_baseline once at cutover (DEPLOYMENT_GUIDE.md → Part 6); until then the v2 cloud refuses it. (On main, the v1 rule still applies: _run_migrations(), additive only.)

CL-3. The cloud is never on the service-critical path. If the cloud is down, restaurants must keep taking orders (global Rule 8). Don't design features where the local site blocks while waiting on the cloud.

CL-4. Public endpoints are hostile territory. menu-app endpoints are reachable by anyone on the internet. Validate everything, rate-limit where it makes sense, and never return data from another site. Site secrets (SITE_KEY) are shown once, at registration.

CL-6. The license signing key is permanent. LICENSE_SIGNING_KEY (cloud .env) signs every site's license. Its public half is built into the site code. Never regenerate or lose it: a new key means every site needs a new image. Keep the backup at %USERPROFILE%\.xenia\license_signing_key.txt safe. Never add fields to the token payload that old sites would misread; bump v for incompatible changes.

CL-8. The fee engine has two copies. cloud_backend/services/fees.py is byte-identical to the site's local_backend/services/fees.py (the cloud charges what the manager's "test an order" shows). Change both, and tests/fixtures/fee_cases.json in both repos; the site's tests/test_fees.py compares them.

CL-5. Frontend URLs are baked in at build time. VITE_CLOUD_URL is a build arg, so changing it means rebuilding the image, not restarting it.

CL-7. Licensed modules live in sites.modules (v2). The sysadmin panel edits them (per site, or by applying a plan preset from /api/presets). The module editor is built from the catalogue each site reports in its heartbeat (sites.module_catalog), with sysadmin_panel/src/moduleCatalog.js as the fallback; keep that file in step with the local manifests.

Common commands

# Deploy on the VPS
cd ~/stacks/xenia-pos-cloud && docker compose up -d --build

# Dev
cd cloud_backend && uvicorn main:app --reload --port 8001
cd cloud_backend && python -m pytest tests -q          # schema guards, licensing v2 (pip install -r requirements-dev.txt)
cd sysadmin_panel && npm run dev
cd connect_frontend/menu-app && npm run dev
cd connect_frontend/order-app && npm run dev && npm test   # VITE_CLOUD_URL=http://localhost:8001; e2e: client-services/tests/e2e/order_app.mjs
cd connect_frontend/manager-app && npm run dev

Releasing a new client version also means bumping LATEST_VERSION in cloud_backend/.env and redeploying. See the parent's DEPLOYMENT_GUIDE.md.

S
Description
This this is the Cloud Backend + Sysadmin panel, for the Xenia POS system
Readme
541 KiB
Languages
JavaScript 71.9%
Python 26%
Dockerfile 0.9%
HTML 0.8%
CSS 0.4%