The Zero-knowledge encrypted sync backend for Beaver Notes with: ML-KEM post-quantum encryption, real-time collaboration, team workspaces, SSO, audit logs, and self-hostable enterprise deployment.
flowchart LR
Client["Client<br/>(Tauri)"] --> API["API (3000)<br/>Fastify"]
API --> DB["PostgreSQL 16"]
Client -. WebSocket .-> Relay["ws-relay<br/>(8080)"]
Relay --> DB
API --> Storage["MinIO / R2<br/>(encrypted blobs)"]
- API: Fastify server handling auth, sync, workspaces, admin, SSO, webhooks
- WebSocket relay (
src/ws-relay.js): y-websocket-compatible relay for real-time multiplayer editing; authenticates each connection against the API - Storage: S3-compatible (MinIO dev, Cloudflare R2 prod); all blobs ML-KEM encrypted
- Database: PostgreSQL 16 — single source of truth;
LISTEN/NOTIFYfans out sync events - Error monitoring: Optional Glitchtip / Sentry (DSN-based, no-op when unset)
| Feature | Free | Starter | Pro | Team | Enterprise |
|---|---|---|---|---|---|
| Notes & editor | ✓ | ✓ | ✓ | ✓ | ✓ |
| Sync container | Folder only | Personal workspace | Personal workspace | Personal + shared team workspaces | Personal + shared team workspaces |
| Receive shared notes | ✓ (as note collaborator) | ✓ | ✓ | ✓ | ✓ |
| Invite / share notes | ✗ | ✓ | ✓ | ✓ | ✓ |
| Collaborators (page-scoped) | ✗ | ✗ | ✗ | ✓ | ✓ |
| Team workspaces & permissions | ✗ | ✗ | ✗ | ✓ | ✓ |
| Admin dashboard | ✗ | ✗ | ✗ | ✓ | ✓ |
| Audit logs | ✗ | ✗ | ✗ | ✗ | ✓ |
| SSO / SAML | ✗ | ✗ | ✗ | ✗ | ✓ |
| Self-hosted | ✗ | ✗ | ✗ | ✗ | ✓ |
| Cloud storage | 0 | 10 GB | 50 GB | 100 GB + 25 GB × seats | Contractual |
| Version history | ✗ | 30 days | 1 year | 1 year | Contractual |
| Device limit | Unlimited | Unlimited | Unlimited | Unlimited | Unlimited |
Run the backend exactly like production (VPS docker compose) locally:
PLAN_OVERRIDE=team docker compose -f docker-compose.test.yml up -dPLAN_OVERRIDEforces every account to the given tier (free|starter|pro|team|enterprise).EMAIL_ENABLED=falsedisables all Resend sends in this environment.- Seed a tier-specific account:
npm run seed:tier -- team tester@example.com - Frontend: point
VITE_BEAVER_SYNC_API_URL=http://localhost:4000andVITE_BEAVER_SYNC_WS_URL=ws://localhost:8080(defaults already).
cp .env.example .env
bash scripts/generate-keys.sh
docker compose up -dThis starts Postgres, MinIO, the API, the WebSocket relay (ws-relay), and a scheduled Postgres backup sidecar. The API connects to Postgres at localhost:5432 (default credentials in .env.example).
docker compose -f docker-compose.enterprise.yml up -dIncludes Postgres, MinIO, GlitchTip, the API, and the WebSocket relay. Offline HMAC licenses: BL<base64url(payload)>.<base64url(HMAC-SHA256(payload, LICENSE_SECRET))> with canonical JSON {licensee, plan:'enterprise', seats?, expiry}. Verification is timing-safe; expired licenses have a 14-day grace period (warning logged). Seats is a soft limit (warn only).
- Development:
ENTERPRISE_MODE=truealone unlocks enterprise features. - Production (
NODE_ENV=production): a valid license is required — setLICENSE_KEY(theBL...token) andLICENSE_SECRET(HMAC secret).ENTERPRISE_MODE=truealone is insufficient. Generate a license offline:The generator (LICENSE_SECRET=$(openssl rand -hex 32) node scripts/generate-license.js --licensee "Acme Corp" --expiry 2027-08-30 --seats 50 # then set LICENSE_SECRET and LICENSE_KEY in .env
scripts/generate-license.js) also acceptsLICENSEE/EXPIRY/SEATSenv vars or--stdinJSON; it is excluded from Docker images via.dockerignoreand onlysrc/lib/license.jsreadsLICENSE_SECRETat runtime.
Full guide: docs/deployment.md.
- A VPS with Docker + Docker Compose
- DNS records pointing your domain at the VPS
- External or co-located Postgres reachable via
DATABASE_URL - Cloudflare R2 bucket (or self-hosted MinIO) for blob storage
# 1. Configure secrets
cp .env.example .env
bash scripts/generate-keys.sh # JWT + ML-KEM keys
# Edit .env with real values
# 2. Start the stack
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --buildCI/CD alternative: push to main with repo variables DEPLOY_TARGET=vps and secrets VPS_HOST, VPS_USERNAME, VPS_SSH_KEY — GitHub Actions runs tests then deploys over SSH.
git pull
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build
# Rollback: check out the previous tag/commit and redeploy the same wayThe API is stateless — scale it horizontally with the overlay (adds Redis as the shared rate-limit store):
export REDIS_URL=redis://redis:6379
docker compose -f docker-compose.yml -f docker-compose.scale.yml up -d --scale api=3The WebSocket relay must stay a single instance (rooms live in memory); Caddy's sticky routing keeps clients pinned to it.
A pg-backup sidecar runs scripts/backup-postgres.sh on a schedule (BACKUP_INTERVAL_SECONDS, retention via BACKUP_RETENTION_DAYS, dumps land in ./backups). Verify restores periodically:
scripts/restore-postgres.sh backups/pg-<timestamp>.sql.gz <target-db>docker compose logs -f api ws-relay
docker compose psApache 2.0