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.
Options
Section titled “Options”| 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.
Local Node and SQLite
Section titled “Local Node and SQLite”Requirements: Node.js 22.20 or newer and pnpm 11.
pnpm installpnpm seed:selfhost # applies the schema and seeds synthetic datapnpm dev:selfhost # API on http://127.0.0.1:8787pnpm --filter @commitment-desk/web dev # web on http://localhost:5173Defaults:
- 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.
Docker with Postgres and MinIO
Section titled “Docker with Postgres and MinIO”cd infra/dockercp .env.example .env# change POSTGRES_PASSWORD and MINIO_ROOT_PASSWORDdocker 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:
docker compose exec api pnpm --filter @commitment-desk/api-node seedThe 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.
Environment
Section titled “Environment”| 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 |
Email delivery
Section titled “Email delivery”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.
Migrations
Section titled “Migrations”The Node adapter applies its schema at startup by default or on demand:
pnpm migrate:selfhost# or inside Composedocker compose exec api pnpm --filter @commitment-desk/api-node migrateThe schema is idempotent and mirrors the D1 migration logically. Apply D1 migrations separately for the Cloudflare runtime.
Uploads and scanner
Section titled “Uploads and scanner”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.
Webhooks
Section titled “Webhooks”Create an endpoint as an administrator and store the returned secret immediately:
POST /v1/webhooksContent-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.
Retention
Section titled “Retention”Set retention per tenant as an administrator:
PUT /v1/settings/retentionContent-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.
Operational checklist
Section titled “Operational checklist”- Use HTTPS everywhere, including webhook endpoints.
- Set a unique
WEB_BASE_URLand 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.
First administrator
Section titled “First administrator”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.
CD_BOOTSTRAP_ORG_NAME='Synthetic Practice' \CD_BOOTSTRAP_ORG_SLUG=synthetic-practice \CD_BOOTSTRAP_ADMIN_EMAIL=admin@synthetic.test \CD_BOOTSTRAP_ADMIN_NAME='Synthetic Admin' \pnpm bootstrap:selfhostThe 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.
Organization membership upgrade
Section titled “Organization membership upgrade”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:
pnpm migrate:selfhost --membership-dry-runpnpm migrate:selfhost --membership-collisionsThe 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:
pnpm migrate:selfhostFor 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.