Architecture
This page is for contributors and architects inspecting Patchwork internals.
Data Model
Section titled “Data Model”Patchwork uses Drizzle ORM (src/db/schema.ts) over PostgreSQL 16+ with plain SQL migrations (drizzle/). See Database Schema & API Route Groups for the generated table and column catalog.
Real-Time Updates (LISTEN/NOTIFY + SSE)
Section titled “Real-Time Updates (LISTEN/NOTIFY + SSE)”- Server mutations emit
NOTIFYpayloads on PostgreSQL channels (src/lib/realtime.ts). GET /api/eventsstreams events over HTTP Server-Sent Events to subscribed clients.- Clients update board state immediately and show an inline status indicator only after consecutive SSE failures.
Full-Text Search
Section titled “Full-Text Search”src/lib/search.ts queries PostgreSQL tsvector + GIN indexes across ticket titles/descriptions, comments, and extracted attachment text (.pdf, .txt, .md, .csv, .json), returning ranked snippets filtered by RBAC permissions.
Permissions Model
Section titled “Permissions Model”src/lib/rbac.ts resolves organization role (admin) and team role (lead, member, viewer, plus developer/tester sub-roles) on every server route. Client UI hints mirror these permissions but never replace server enforcement.
Setup & Installer Flow
Section titled “Setup & Installer Flow”scripts/setup.mjsprovisions PostgreSQL,.env, MinIO bucket, and anAES-256-GCMencrypted Admin Setup Token (src/lib/setup-token.ts)./setup(src/components/SetupWizard.tsxandsrc/lib/setup.ts) verifies the token, deletes the ciphertext, autosaves steps tosetup_state, and locks permanently on completion.
Related Pages
Section titled “Related Pages”Easy Mode Supervisor & Data Layout
Section titled “Easy Mode Supervisor & Data Layout”In Easy mode (PATCHWORK_INSTALL_MODE=easy), npm run start launches scripts/supervisor.mjs, which manages the full stack in one process tree:
scripts/supervisor.mjs (npm run start) ├── 1. Embedded PostgreSQL 18 (./data/postgres, 127.0.0.1:<high-port>) ├── 2. Drizzle SQL migrations (drizzle/*.sql) ├── 3. Official MinIO Server (./bin/minio, ./data/minio, console 127.0.0.1:<port>) └── 4. Next.js Server (PORT, /api/health, /documentation)On SIGINT, SIGTERM, or Windows SIGBREAK, the supervisor shuts down services in reverse order (Next.js -> MinIO -> PostgreSQL) and removes .patchwork*.pid files. If PostgreSQL or MinIO exits unexpectedly, the supervisor restarts it with exponential backoff.