The backend for The Human Pattern Lab — where human chaos gets dissected, emotional weather gets forecasted, and creatures drop unfiltered opinions on everything.
This API serves Lab Notes and supporting systems, backed by a
SQLite Ledger, powered by Express, and guarded by
GitHub OAuth.
Public knowledge flows freely. Admin routes are… supervised. 😼
Production: https://api.thehumanpatternlab.com
Local development: http://localhost:8001
As of v0.2.0, routes are root-based.
The/apipath prefix has been removed from canonical endpoints.
- SQLite Ledger model — append-first persistence powering note history and projections
- Express + TypeScript — simple, explicit, dependable
- GitHub OAuth — browser redirect for admins + Device Flow for CLI access
- Public endpoints — read-only access to Lab Notes
- Protected admin routes — create, edit, delete notes (Carmel is watching)
- Environment-based secrets — no hardcoding, no nonsense
- Admin API tokens — scoped, revocable access for CLI and automation (raw tokens returned once)
git clone https://github.com/AdaInTheLab/lab-api.git
cd lab-api
npm install
cp .env.example .env
npm run devThe API starts in watch mode with automatic reloads.
npm run build
npm startThis compiles TypeScript to dist/ and runs the built server.
PORT=8001
# ── GitHub OAuth ─────────────────────────────
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret
SESSION_SECRET=your-random-long-secret-here
# ── Admin Access Control ─────────────────────
ADMIN_GITHUB_USERS=your-github-username
ADMIN_GITHUB_LOGINS=your-github-username
# ── API Tokens ───────────────────────────────
TOKEN_PEPPER=your-long-random-secret
# ── Database ─────────────────────────────────
DB_PATH=/path/to/lab.db
TOKEN_PEPPERis required in production and is used to securely hash API tokens.
GET /healthGET /lab-notesGET /lab-notes/:slug
GET /auth/githubGET /auth/github/callbackGET /auth/logoutGET /admin/notesPOST /admin/notesDELETE /admin/notes/:id
GET /github/deviceGET /github/device/poll/:device_code
GET /admin/tokens— list issued API tokens (no secrets)POST /admin/tokens— mint a new scoped API token (returned once)POST /admin/tokens/:id/revoke— revoke an existing token
Admin routes are… supervised. 😼 (and logged.)
npm testUses Jest + Supertest for API validation.
- Host: DreamHost VPS
- API origin:
api.thehumanpatternlab.com - Reverse proxy: Routes API subdomain traffic to
localhost:8001 - Process manager: PM2
The main site (
thehumanpatternlab.com) is intentionally separate.
Legacy/api/*paths on the main domain are deprecated and redirected.
This API is intended to run under PM2 in production.
Add these to ~/.bashrc or ~/.zshrc on the VPS:
# ── Human Pattern Lab · API ─────────────────────────────
alias lab-api-start='pm2 start ecosystem.config.cjs --env production'
alias lab-api-restart='pm2 restart lab-api'
alias lab-api-stop='pm2 stop lab-api'
alias lab-api-logs='pm2 logs lab-api'
alias lab-api-status='pm2 status'Reload your shell:
source ~/.bashrcUsage:
lab-api-start
lab-api-logs
lab-api-restartThese scripts live in package.json:
npm run pm2:start
npm run pm2:restart
npm run pm2:stop
npm run pm2:logs
npm run pm2:status- Prefer
pm2 restart lab-apifor routine deploys once the process exists. - Use
pm2 start ecosystem.config.cjs --env productionfor first boot. - After first successful production start, persist the process list:
pm2 save
pm2 startup(Then run the one-line command PM2 prints to enable startup on reboot.)
This API follows semantic versioning while pre-1.0.
- v0.2.0
- Introduces the Ledger persistence model
- Removes the
/apiroute prefix - Canonical API base is
https://api.thehumanpatternlab.com
Clients should rely only on documented HTTP endpoints, not internal DB structure.
This repository (lab-api) is the canonical authority for Lab content.
It owns:
- the database and schema
- content validation and ingestion
- permissions and provenance
Content files themselves live in a separate repository and are mounted here as a git submodule at:
./content/
This allows the API to import deterministic, versioned content while keeping the main site focused purely on presentation.
👉 For full details, workflows, and pitfalls:
See docs/content-source-of-truth.md
MIT
The Human Pattern Lab
https://thehumanpatternlab.com
The lantern is lit.
The foxes are watching.