For Self-Hosters & Camp IT Leads. Camp Store v2.0 deploys automatically to TrueNAS SCALE or any Docker Compose host via Gitea Actions — with zero manual
.envfile setup required.
1. Stack Architecture
Camp Store v2.0 separates authentication/API, logical replication sync, database storage, and static marketing/docs into four lightweight services:
| Service | Hostname (Example) | Port | Role |
|---|---|---|---|
camp-store-postgres |
Internal (default only) |
5432 |
PostgreSQL 17 with wal_level=logical, separate campstore and powersync_storage databases, powersync publication, and Better Auth tables. |
camp-store-powersync |
sync.campstore.app |
8080 |
PowerSync Service (start -r unified) using Edition 2 bucket_definitions sync rules and JWKS JWT verification. |
camp-store-server |
campstore.app |
80 |
Node 24 + Hono API server, Better Auth (Passkeys + Email/Password + JWKS), PowerSync CRUD upload receiver, and bundled Expo Web POS app. |
camp-store-www |
www.campstore.app |
80 |
Nginx Alpine serving this Astro 5 static landing page and documentation portal with /healthz. |
2. Database & PowerSync Isolation Rules
Two architectural guardrails keep replication fast and loop-free:
- Separate
powersync_storageDatabase:infra/postgres/init/00-init-dbs.sqlcreates a dedicatedpowersync_storagedatabase alongsidecampstore. Keeping PowerSync’s internal bucket/checkpoint storage in its own logical database prevents sync engine writes from feeding back intocampstore’s logical replication WAL stream. - Scoped
PUBLICATION powersync: Only domain tables (staff_profiles,camps,camp_members,camp_invites,categories,products,campers,ledger_entries,ledger_items,inventory_movements,sync_rejections) are added toPUBLICATION powersync. Better Auth credential tables ("user","session","account","verification","jwks","passkey") stay local to PostgreSQL and are never replicated to client SQLite databases. Instead, anAFTER INSERT OR UPDATEtrigger (sync_user_to_staff_profiles) mirrors safe profile fields intostaff_profilesand auto-claims matchingcamp_invites. - Edition 2 Sync Rules (
bucket_definitions): PowerSync Open Edition requires compiled or Edition 2bucket_definitionsininfra/powersync/sync_rules.yaml:user_self: syncsstaff_profilesandsync_rejectionsscoped byrequest.user_id().by_camp: syncs all camp operational tables parameterized bySELECT camp_id FROM camp_members WHERE user_id = request.user_id().
3. Zero-Env Configuration & TrueNAS Automation
Camp Store does not use manually created .env files on TrueNAS or local workstations:
- Automated CI/CD Deploy (
truenas-deploy@main): Pushing tomasterruns.gitea/workflows/deploy.yml, builds and pusheslinux/amd64container images with Gitea registry build caching, syncsdocker-compose.ymlto/mnt/jupiter/apps/rodydavis/camp_store/, and verifies live HTTP200health responses after startup. - Optional Gitea Secrets & Vars: If you configure repository
secrets.*(POSTGRES_PASSWORD,BETTER_AUTH_SECRET) orvars.*(BETTER_AUTH_URL,POWERSYNC_URL,PS_AUDIENCE,APPLE_TEAM_ID,ANDROID_SHA256_FINGERPRINTS) in Gitea, the workflow passes them automatically. If omitted, safe defaults apply immediately. - Auto-Persisted Auth Signing Key: When
BETTER_AUTH_SECRETis not explicitly set,camp-store-servergenerates a cryptographically strong 256-bit random key on first boot and saves it to/app/data/auth-secret.key(./data/server/auth-secret.keyon the TrueNAS ZFS dataset), keeping sessions intact across container upgrades. - Private Database Network:
camp-store-postgresbinds only to the Compose internaldefaultnetwork (neverapps-net), keeping database credentials unreachable from other containers or the public proxy.
Proxy & Cookie Note: When deploying behind Traefik or Cloudflare Tunnel, terminate TLS at the edge proxy and route HTTP traffic into
camp-store-server:80,camp-store-powersync:8080, andcamp-store-www:80over the shared externalapps-netDocker network.BETTER_AUTH_URLdefaults tohttps://campstore.appso Passkey RP ID (campstore.app) and secure session cookies match the browser origin.
4. Deploying & Local Stack Usage
Make sure the shared Traefik proxy network exists once on the production host:
docker network create apps-net || true
Deploy or update the production stack manually if needed (using ./data/pg_data and ./data/server ZFS bind mounts):
docker compose pull
docker compose up -d --remove-orphans
Verify container health:
docker compose ps
curl -fsS http://localhost/healthz
Running Local PostgreSQL & PowerSync for Development
Start a local database and PowerSync sync node directly with docker-compose.dev.yml:
docker compose -f docker-compose.dev.yml up -d
Every Dockerfile in the monorepo builds from the repository root (context: .), and apps/www/nginx/nginx.conf disables absolute/port redirects (absolute_redirect off; port_in_redirect off;), enables gzip, sets immutable caching on /_astro/* assets, forces no-cache on HTML pages, and exposes GET /healthz.
5. Migrating Data from Camp Store v1.x (Firebase)
Upgrading from a Camp Store v1.x Firebase/Firestore deployment is idempotent via legacy_firestore_id columns on camps, categories, products, campers, and ledger_entries. Pass connection details directly via CLI flags:
pnpm migrate:firebase -- \
--credentials ./service-account.json \
--project camp-store-23521 \
--database-url postgresql://campstore:campstore@localhost:5432/campstore \
--dry-run
Remove --dry-run when ready to commit. Because every migrated entity carries a UNIQUE(camp_id, legacy_firestore_id) constraint, re-running the importer safely skips previously migrated rows without creating duplicates.
6. Backups & Monitoring
- ZFS Dataset Snapshots & Backups: All persistent production state lives under
/mnt/jupiter/apps/rodydavis/camp_store/data/(./data/pg_datafor PostgreSQL 17 and./data/serverfor the auth signing key), making TrueNAS ZFS snapshots automatic alongside periodicpg_dump -Fc -d campstorelogical backups. PowerSync’spowersync_storagedatabase rebuilds automatically fromcampstoreif cleared. - Sync Rejection Inspection: If an offline client attempts a mutation that fails server validation (for example, a stale reversal or revoked membership), the server logs the diagnostic payload into
sync_rejectionsand alerts the operator without losing transaction history.