Skip to content

Self-hosting

The self-host adapter runs the same portable API as the hosted Worker. Use it for a single office, a pilot, or a deployment in your own cloud account.

Metadata Attachments
SQLite file Local filesystem or S3-compatible bucket
Postgres S3-compatible bucket

The Docker Compose stack in infra/docker/ uses Postgres and MinIO. The local development path uses SQLite and a filesystem directory.

Requirements: Node.js 22.20 or newer and pnpm 11.

Terminal window
pnpm install
pnpm seed:selfhost # applies the schema and seeds synthetic data
pnpm dev:selfhost # API on http://127.0.0.1:8787
pnpm --filter @commitment-desk/web dev # web on http://localhost:5173

Defaults:

  • SQLite: .data/commitment-desk.sqlite
  • Attachments: .data/attachments
  • API key, reviewer, and admin: .local-demo.json (gitignored)

Use pnpm demo:capture after pnpm dev:selfhost to submit a synthetic capture through the API. The web app’s Vite proxy points /v1 at 127.0.0.1:8787.

Terminal window
cd infra/docker
cp .env.example .env
# change POSTGRES_PASSWORD and MINIO_ROOT_PASSWORD
docker compose up --build
Service URL
Web http://localhost:5173
API health http://localhost:8787/v1/health
MinIO console http://localhost:9001

Seed synthetic data into the running Compose database:

Terminal window
docker compose exec api pnpm --filter @commitment-desk/api-node seed

The container writes .local-demo.json inside the API container. To run pnpm demo:capture from the host, set CD_API_URL=http://localhost:8787 and use the API key printed by the seed command, or run the seed command with the same CD_DEMO_API_KEY you want to use.

Production deployments should terminate TLS in front of the web and API, set ENVIRONMENT=production so session cookies are Secure, and use real secrets. The example Compose file uses development settings for local use only.

Variable Purpose
PORT API port, default 8787
ENVIRONMENT production enables secure cookies
WEB_BASE_URL Web origin used for magic links and same-origin checks
DATABASE_URL Postgres connection URL; takes precedence over SQLite
SQLITE_PATH SQLite file path when no Postgres URL is set
STORAGE_DRIVER s3, filesystem, or memory for tests
S3_BUCKET, S3_REGION, S3_ENDPOINT S3-compatible bucket and endpoint
S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY Bucket credentials
S3_FORCE_PATH_STYLE true for MinIO and most self-host stores
ATTACHMENT_DIR Filesystem attachment root when STORAGE_DRIVER=filesystem
MALWARE_SCANNER_URL HTTP scanner endpoint; returns { "verdict": "clean" | "infected" }
EMAIL_PROVIDER cloudflare for production email, or console for development
CLOUDFLARE_ACCOUNT_ID Cloudflare account that owns the sending domain
CLOUDFLARE_EMAIL_API_TOKEN Cloudflare API token with Email Sending: Edit
EMAIL_FROM Verified sender address
EMAIL_FROM_NAME Sender display name
EMAIL_REPLY_TO Optional reply-to address
EMAIL_TIMEOUT_MS Provider timeout in milliseconds, default 5000
MALWARE_SCANNER_FAIL_CLOSED Set false to allow uploads when the scanner is unavailable
RATE_LIMIT_DISABLED Set true only for controlled testing
AUTO_MIGRATE Apply the Node schema on startup, default true
PROCESS_INTERVAL_SECONDS Webhook and retention processing interval, default 30

Local development uses the console sender, so no email account is required. For production self-host email, set EMAIL_PROVIDER=cloudflare and the Cloudflare account, API token, sender, and reply-to variables above. The Node adapter uses the Cloudflare Email Sending REST API; the Worker adapter uses the native send_email binding. Cloudflare Email Sending requires Workers Paid for arbitrary recipients, an onboarded sending domain, and an API token with Email Sending: Edit. See email delivery for domain onboarding, SPF/DKIM/DMARC, limits, and testing. Never commit the API token.

The Node adapter applies its schema at startup by default or on demand:

Terminal window
pnpm migrate:selfhost
# or inside Compose
docker compose exec api pnpm --filter @commitment-desk/api-node migrate

The schema is idempotent and mirrors the D1 migration logically. Apply D1 migrations separately for the Cloudflare runtime.

Uploads are limited to 25 MB and to JPEG, PNG, WebP, HEIC, or PDF. The declared content type must match the file signature. The scanner runs before storage and before deduplication. An infected file returns 422 malware_detected. Configure a scanner before accepting real data; the default no-op scanner is for synthetic development only.

Create an endpoint as an administrator and store the returned secret immediately:

POST /v1/webhooks
Content-Type: application/json
{ "url": "https://office.example/hooks/commitment-desk", "events": ["capture.accepted"] }

Verify X-CommitmentDesk-Signature: t=<unix-seconds>,v1=<hex> with HMAC-SHA256 over <timestamp>.<raw-body>. Reject stale timestamps and duplicate delivery identifiers. Failed deliveries retry with backoff and are visible at GET /v1/webhooks/deliveries.

Set retention per tenant as an administrator:

PUT /v1/settings/retention
Content-Type: application/json
{ "captureRetentionDays": 365, "uploadRetentionDays": 30 }

The scheduled pass soft-deletes expired terminal captures, removes evidence objects, and keeps audit events. POST /v1/maintenance/retention runs it on demand. See retention and deletion.

  • Use HTTPS everywhere, including webhook endpoints.
  • Set a unique WEB_BASE_URL and keep the web app same-origin with /v1.
  • Change every default password and restrict database and bucket access.
  • Enable encryption at rest for the database and bucket.
  • Configure the malware scanner and rate limits.
  • Back up metadata and attachments together and test restores.
  • Monitor /v1/health, webhook delivery failures, and storage growth.
  • Apply releases and dependency updates promptly.

Point SQLITE_PATH or DATABASE_URL at the self-host metadata database and run the bootstrap command with your organization and first administrator settings. This example uses synthetic values.

Terminal window
CD_BOOTSTRAP_ORG_NAME='Synthetic Practice' \
CD_BOOTSTRAP_ORG_SLUG=synthetic-practice \
CD_BOOTSTRAP_ADMIN_NAME='Synthetic Admin' \
pnpm bootstrap:selfhost

The bootstrap applies migrations and creates the organization, normalized user identity, and administrator membership in a transaction. Repeating it for the same active administrator is safe. For a synthetic demo with sample parcels and demo users, use pnpm seed:selfhost.

Back up the metadata database and set AUTO_MIGRATE=false before starting the upgraded server. The server otherwise applies the schema at startup. With the legacy self-host schema and the target database configured, run the preflight:

Terminal window
pnpm migrate:selfhost --membership-dry-run
pnpm migrate:selfhost --membership-collisions

The first command reports aggregate counts and the second lists every affected row. Review both before migrating. Migration 0003 prefers an active membership over an inactive one, then the highest role (admin, reviewer, submitter). Unknown legacy roles become submitter; any non-active status becomes disabled for the global user and inactive for the membership. The preflight’s invalid_role_users and invalid_status_users counts identify legacy values outside the expected sets, and the collision query shows the tenant, email, role, status, and timestamp for every same-tenant collision. Resolve or explicitly accept those rows before migrating.

For D1, run organization-membership-preflight.sql and organization-membership-collisions.sql against the legacy database before applying migration 0003. Both are read-only and leave the database unchanged.

After reviewing the reports, apply the migration explicitly and then start the server:

Terminal window
pnpm migrate:selfhost

For Docker, set AUTO_MIGRATE=false for the preflight container, then run the migration before starting the upgraded service. After migration, ask users to request new magic links, since the upgrade invalidates legacy links and sessions.