40 KiB
Platform Architecture — B2B Customer Portal
Status: Revised design (2026-09 revision) Authors: Sharang, Benjamin Date: 2026-05-11 · cluster split 2026-06-30 · revised 2026-09-11
2026-09-11 revision. This supersedes the 2026-06-30 three-cluster design. What changed:
- Two Orca clusters, not three. The existing
breakpilotcluster (orca-infra) is company core infrastructure only. A newbreakpilot-platformcluster hosts everything customer-facing. Staging and production live in that one cluster on separate Hetzner VMs.- Hosts are fixed. Portal at
app-stage.breakpilot.com/app.breakpilot.com, tenants addressed by path (/[slug]/…), one branded host per web product per environment. No wildcard DNS, no customer custom domains.- No web-component embedding. Product UIs are standalone apps behind SSO (or headless, or CLI). The widget/custom-element contract is gone (
PRODUCT_INTEGRATION_SPEC.md2.0).- Products: Werkpilot, Werkbank, Prüfwerk, Firmwerk are the first line. CERTifAI is parked; breakpilot-compliance (the "dsms" stack) migrates last and is re-onboarded afterwards.
- ERPNext stays on core and is the commercial truth. The customer ⇄ CRM ⇄ ERP link is always on (outbox + webhooks + reconcile), billing is ERPNext invoicing only (Stripe/Polar dropped), usage flows continuously as usage records.
- Keycloak stays on core; the platform gets realms
breakpilot-stageandbreakpilot-prod. Token claims carry only coarse status; the tenant-registry is the entitlement authority (ERP/02).- CLI products are licensed by signed licence tokens issued by the tenant-registry.
Migration mechanics:
IMPLEMENTATION_PLAN.md(M-MIG milestones). Topology:INFRASTRUCTURE.md.
1. Vision
We sell Werkpilot, Werkbank, Prüfwerk and Firmwerk as modular B2B building blocks for machine and plant manufacturers and their software teams. Customers buy one or several and operate them under one platform tenant — a single login, a single bill, a single audit trail — without needing to understand that they are separate products under the hood.
Each customer is a tenant: fully isolated data, their own user base, their own identity configuration. We manage all tenants from a single operator backstage.
ERPNext runs our company: CRM, sales orders, invoicing, HR. Frappe Helpdesk runs customer support. Gitea runs engineering. All of that is core infrastructure on the breakpilot cluster. The customer-facing platform — portal, tenant-registry, and the products — runs on the breakpilot-platform cluster and talks to core over HTTPS.
2. Products in Scope
| Product | Catalog key | Type | What it is |
|---|---|---|---|
| Prüfwerk | pruefwerk |
Web + MCP | Compliance scanner for CRA/IEC 62443 style assessments: SBOM, DAST, LLM-assisted pentest orchestration, PLC provisioning tests, issue-tracker sync, CVE monitoring. Rust (agent API, Dioxus dashboard, MCP server, docs). Repo platform/pruefwerk (formerly compliance-scanner-agent, user-facing name until 2026-09-02: "Certifai"). |
| Werkbank | add-on of pruefwerk |
Runner | Pull-based execution runner (plc-provision, qemu-boot, dast, pentest jobs) that leases work from Prüfwerk. Never sold standalone (CRA-WBK-* always attaches to a CRA-CSA-* subscription). Repo platform/werkbank. |
| Werkpilot | werkpilot |
CLI | On-prem AI coding agent (goose fork) for machine and plant manufacturers: werkpilot, werkpilotd, werkpilot-tui. Talks to llm.breakpilot.com; no hosted UI. Repo platform/werkpilot. |
| Firmwerk | firmwerk |
CLI + cloud-server | Reproducible firmware build, SBOM/VEX/attestation toolchain (firmwerk CLI) with a small cloud control plane for licences, SBOM upload, invites and OSV lookups (firmwerk-cloud-server). Formerly Tramiton. Repo platform/firmwerk. |
| Platform tenant | — | Portal | PLT-CORE-CLD-*: the tenant itself (users, SSO, API keys, audit, billing). Every cloud SKU needs one. |
Later / parked:
| Product | Status |
|---|---|
breakpilot-compliance (compliance; the "dsms" stack: backend-compliance, ai-compliance-sdk, admin-compliance, developer-portal, dsms-node/gateway, crawler, TTS) |
Migrates to the platform cluster last (M-MIG-9). Re-onboarded to contract 2.0 afterwards. Until then it runs on the core cluster as today. |
| CERTifAI (GenAI admin dashboard) | Parked. Repo stays under sharang, nothing deployed, catalog key removed. |
Out of scope: breakpilot-dataroom, breakpilot-lehrer, breakpilot-pitch-deck (the pitch deck moves together with dsms because it shares its database, but it is not a product).
3. Topology — Two Clusters, Two Environments
╔═══════════════════════════════════════════════════════════════════════════════╗
║ CORE cluster `breakpilot` (orca-infra) — company infrastructure only ║
║ master breakpilot-infra-vm1 (46.225.100.82) · workhorse ubuntu-16gb-fsn1-1 ║
║ ║
║ Keycloak (auth.) ERPNext + Helpdesk (erp.) Gitea (git.) Harbor (repo.) ║
║ LiteLLM (llm.) Infisical (secrets.) SigNoz (signoz./otel.) Nextcloud ║
║ Matrix/Element/Jitsi Penpot kellnr Gatus (status.) landing (breakpilot.com)║
║ [until M-MIG-9: breakpilot-dsms + tenant-registry-dev + compliance-mcp] ║
╚═══════════════════════════════════════════════════════════════════════════════╝
▲ HTTPS only: OIDC/JWKS, ERPNext REST + webhooks, image pulls,
│ LLM calls, OTel export, secret bootstrap
╔═══════════════════════════════════════════════════════════════════════════════╗
║ PLATFORM cluster `breakpilot-platform` (orca-platform) ║
║ ║
║ ┌─────────────────────────────────┐ ┌─────────────────────────────────┐ ║
║ │ VM bp-platform-stage (MASTER) │ │ VM bp-platform-prod (agent) │ ║
║ │ app-stage.breakpilot.com │ │ app.breakpilot.com │ ║
║ │ portal-stage, tenant-registry- │ │ portal-prod, tenant-registry- │ ║
║ │ stage + pg, erpnext-mock-stage │ │ prod + pg │ ║
║ │ pruefwerk-*-stage, werkbank- │ │ pruefwerk-*-prod, werkbank- │ ║
║ │ runner-stage, firmwerk-*-stage │ │ runner-prod, firmwerk-*-prod │ ║
║ │ realm breakpilot-stage │ │ realm breakpilot-prod │ ║
║ └─────────────────────────────────┘ └─────────────────────────────────┘ ║
║ (prod VM joins later — same cluster, separate node, separate projects) ║
╚═══════════════════════════════════════════════════════════════════════════════╝
Environments are separated by VM, realm, registry, database and secret scope. Staging shares nothing stateful with production:
| stage | prod | |
|---|---|---|
| VM / Orca node | bp-platform-stage (cluster master) |
bp-platform-prod (agent) |
| Portal host | app-stage.breakpilot.com |
app.breakpilot.com |
| Product hosts | pruefwerk-stage., firmwerk-stage. |
pruefwerk., firmwerk. |
| Registry host | registry-stage.breakpilot.com |
registry.breakpilot.com (+ alias licence.breakpilot.com) |
| Keycloak realm (on core) | breakpilot-stage |
breakpilot-prod |
| tenant-registry + Postgres | own instance, own DB | own instance, own DB |
| ERPNext | mock (erpnext-mock-stage, in-cluster) |
live erp.breakpilot.com |
| Orca projects / secrets | *-stage |
*-prod |
| Data | synthetic + demo | real |
The four planes (Identity, Control, App, Infra) survive as the SLA and ownership vocabulary (INFRASTRUCTURE.md §6). Identity and Infra are owned by the core cluster; Control and App by the platform cluster, per environment.
4. Plane 1 — Identity
Technology: Keycloak 26 on the core cluster (auth.breakpilot.com), one realm per platform environment: breakpilot-stage, breakpilot-prod. (breakpilot remains the company-staff SSO realm; breakpilot-dev is retired after the dsms migration.)
Keycloak is the only truth about who anyone is. Every other service validates JWTs issued here — nothing else handles auth logic. Keycloak carries only a coarse tenant status; it never carries entitlements (ERP/02).
Structure
Realm: breakpilot-prod (breakpilot-stage is identical)
│
├── Organizations (one per B2B customer; org attribute tenant_id = registry UUID)
│ ├── Acme Corp → org_id: uuid-acme
│ └── ...
│
├── Organization Roles
│ ├── IT_ADMIN — full portal access, user management, IdP config
│ ├── CXO — dashboard, billing, audit (read)
│ ├── FINANCE — billing, invoices
│ ├── LEGAL — audit log, compliance read
│ └── USER — product access only
│
├── Realm Roles (operators)
│ ├── BREAKPILOT_ADMIN — full backstage, impersonation, demo tenant edit
│ ├── SUPPORT_ENGINEER — read backstage, limited impersonation
│ └── SALES_REP — demo tenant login, CRM read, NO real-tenant access
│
├── Clients
│ ├── portal-{env} confidential, auth code + PKCE
│ ├── portal-svc-{env} service account (registry calls)
│ ├── tenant-registry-svc-{env} service account (KC admin API: users + organizations)
│ ├── pruefwerk-dashboard-{env} public PKCE
│ ├── pruefwerk-svc-{env} service account
│ ├── firmwerk-svc-{env} service account
│ ├── werkpilot-cli / firmwerk-cli public, device-authorization grant (CLI login)
│ └── erp-svc-{env} service account (ERPNext → registry webhooks, prod only)
│
├── Client scopes
│ ├── tenant-context tenant_id, tenant_slug, org_roles, tenant_status
│ ├── tenant-registry-audience aud: tenant-registry
│ └── pruefwerk-audience aud: pruefwerk
│
└── Identity Provider Brokering (per org, optional)
├── OIDC (Okta, Google Workspace, any OIDC provider)
└── SAML (Azure AD, ADFS, any SAML 2.0 provider)
JWT Structure
sub — user UUID
email — user email
tenant_id — customer tenant UUID (= Keycloak org attribute; = registry tenants.id)
tenant_slug — acme
org_roles — [IT_ADMIN, USER, ...]
realm_roles — [] | [BREAKPILOT_ADMIN] | [SUPPORT_ENGINEER] | [SALES_REP]
tenant_status — demo | trial | active | warning | restricted | halted | archived
aud — per client scope (tenant-registry, pruefwerk, ...)
iss — https://auth.breakpilot.com/realms/breakpilot-{env}
tenant_status is written by the tenant-registry (SyncClaims) whenever the ladder changes; token-TTL lag (≤ access-token lifetime) is accepted. There is no products or plan claim. Products ask the registry (§5c) for entitlements and cache the answer for ≤ 60 s.
Multi-org users: the registry's GET /v1/users/{id}/memberships is the membership authority; per-user attributes in the token reflect the active org only.
CLI identity
werkpilot login and firmwerk login use the OAuth device-authorization grant against the realm. The resulting user token is exchanged once at the registry for a licence token (§5c, ERP/02); day-to-day the CLIs run on the licence token, offline-verifiable, with an hourly phone-home.
5. Plane 2 — Control
5a. Customer Portal
Technology: Next.js 16, Auth.js v5 (Keycloak provider)
Deployed at: app-stage.breakpilot.com (stage) / app.breakpilot.com (prod) — one fixed host per environment.
The front door for all customers and for us. Owns no business logic — it is a routing, auth, and UI layer.
Tenant routing (path-based):
- The first path segment is the tenant slug:
https://app.breakpilot.com/acme/dashboard. - The portal resolves the slug via tenant-registry
GET /v1/tenants/by-slug/{slug}(cached 60 s) and checks it against the session'stenant_id; mismatch → redirect to the user's own tenant. - Reserved first segments:
start,backstage,api,auth,demo. - No
Host-header tenancy, no wildcard certificates, no customer domains.
Customer area (requires valid JWT for their org):
/[slug]/dashboard product tiles, usage summary, activity, billing-state banner
/[slug]/catalog browse ALL products, subscribed and not (upgrade/upsell flow)
/[slug]/products/
/pruefwerk launch → https://pruefwerk.breakpilot.com (SSO), runner status
/werkpilot downloads, licence status, seat usage
/firmwerk downloads, licence status, environments, cloud-server link
/[slug]/projects optional sub-tenancy [IT_ADMIN] (API deferred)
/[slug]/settings/
/identity IdP configuration [IT_ADMIN]
/users invite, roles, deactivate [IT_ADMIN]
/api-keys API keys (products, MCP, runners) [IT_ADMIN]
/integrations webhooks, process hooks
/[slug]/billing/ plan, subscriptions, usage, invoices (from ERPNext via registry) [FINANCE, CXO, IT_ADMIN]
/[slug]/audit/ platform + product audit, filterable by product [LEGAL, IT_ADMIN]
/[slug]/support/ link to Frappe HD customer portal [all roles]
Product tiles launch the product on its own host (SSO hand-off through Keycloak; no iframe, no custom element). Headless/CLI products render a portal-owned page (downloads, keys, licences, usage).
Operating principles (unchanged): role-based UI hiding; browse before buy; Tenant → Project → Resources hierarchy; cross-product activity log; cost and usage as first-class.
Backstage (/backstage/…, by realm role) — unchanged in scope: BREAKPILOT_ADMIN everything; SUPPORT_ENGINEER read + impersonation; SALES_REP only /backstage/leads, /backstage/demo.
/backstage/dashboard MRR, active tenants, system health
/backstage/tenants/
/new create customer
/[id]/overview health, logins, API volume
/[id]/products enable/configure products, add-ons (werkbank runners)
/[id]/users view members, impersonate
/[id]/billing ERPNext view: subscriptions, invoices, dunning level, usage records
/[id]/licences issued CLI licences, revoke
/[id]/support tickets for this customer
/[id]/audit full audit trail
/backstage/system/
/health all service health
/erp-link outbox depth, last reconcile, webhook failures
/incidents incident log
/releases deployment history
5b. ERPNext (core cluster)
Technology: Frappe + ERPNext v15 (+ Frappe CRM, Helpdesk) — ghcr.io/mighty840/erpnext-stack:v15, self-hosted via Orca on the core cluster
Access: erp.breakpilot.com — us only
Auth: Keycloak OIDC (realm breakpilot)
ERPNext is our business operations backbone and the commercial source of truth for every tenant: customer, subscribed SKUs, term, payment status, dunning level. We do not build CRM, invoicing, or HR — we configure ERPNext for these.
| ERPNext Module | Used for |
|---|---|
| CRM | Leads, opportunities, deal pipeline (website form via kontakt-relay, portal catalog requests, trial requests) |
| Sales | Quotations, Sales Orders (= contracts), Subscriptions (recurring SLA tiers), Pricing Rules |
| Accounts | Sales Invoices, Payment Entries, Dunning, DATEV export, Usage Records |
| Buying | Our own SaaS costs, infrastructure invoices |
| HR | Founders as employees, expense claims |
| Support (Frappe HD) | Customer tickets, SLA, escalation to Gitea |
Integration with the platform — always on, both directions (ERP/02, P12, P17, P18):
- ERPNext Customer carries the custom field
tenant_id(= registry UUID). The registry creates/updates the Customer when a tenant is created (erp_customer_idwritten back). - Down (ERP → registry): Frappe Webhooks (HMAC-signed) on
Sales Ordersubmit,Subscriptionstatus change,Sales Invoiceoverdue,Payment Entrysubmit,Dunninglevel change →POST /v1/internal/erp/webhook. Idempotent by ERP document name + modified timestamp. A 15-minute reconcile job re-reads open Subscriptions per Customer and repairs any missed event. - Up (registry → ERP): an outbox in the registry pushes Customer upserts, CRM Leads (catalog / trial requests), and usage records (
usage_events→ ERPNext usage lines on the Subscription) with retry/backoff. Target lag ≤ 60 s; the backstage/system/erp-linkpage shows outbox depth. - Portal billing page reads Subscriptions and Sales Invoices from ERPNext server-side via the registry — customers never log into ERPNext directly.
- Staging talks to
erpnext-mock-stage, an in-cluster mock of the same REST surface that can fire the same webhooks on demand. The live ERP configuration is applied only for production (ERP/03 Phase 5).
5c. Tenant Registry
Technology: Go service, PostgreSQL (one instance per environment)
Hosts: registry-stage.breakpilot.com / registry.breakpilot.com (alias licence.breakpilot.com) — needed publicly for ERPNext webhooks and CLI phone-home; everything else may use the in-node network.
The glue between Keycloak, ERPNext, and the products. The entitlement authority: it decides what each tenant may do now, derived from ERPNext's commercial state and expressed as one ladder.
Key data it holds:
tenants id (= Keycloak org attribute tenant_id), slug, name,
erp_customer_id, status, kind (customer | demo), plan (SKU tier),
trial_ends_at, contract_start/end, sales_owner.
status ∈ {demo, trial, active, warning, restricted, halted, archived}
demo shared demo tenant; reset nightly; no billing
trial real customer in their N-day evaluation window
active paid, current (Betriebsbereit)
warning overdue within grace; full access + banner (Warnung)
restricted grace exceeded; read-only + export only (Eingeschränkt)
halted long overdue / contract ended; export window only (Angehalten)
archived export window closed; data deleted; audit retained
products catalog (was hard-coded): key, name, type (standalone|headless|cli),
launch_url per env, skus[], addons[] (e.g. pruefwerk → werkbank),
manifest_url, enabled
plans SKU → tier, limits (seats, targets, scans/mo, environments, runners)
subscriptions tenant ↔ ERP Subscription / Sales Order: sku, tier, seats, period,
erp_status (mirrors ERPNext), synced_at
tenant_products tenant ↔ product entitlement: enabled, config (limits, addons,
litellm_url…), expires_at — derived from subscriptions
tenant_projects OPTIONAL sub-tenancy (schema exists; API deferred)
tenant_idp_config type (oidc/saml), metadata, verified
api_keys portal-owned; tenant_id, product, scopes, name, hash (argon2id),
created_by, last_used_at, revoked_at. Products and runners verify
via /v1/internal/api-keys/verify. Single source of truth.
licences CLI licence tokens: id, tenant_id, product, sku, kid, issued_at,
expires_at, last_heartbeat_at, revoked_at, ladder_state
usage_events product, tenant_id, metric, quantity, occurred_at, idempotency_key,
erp_pushed_at
erp_outbox pending ERPNext writes (customer upsert, lead, usage record):
payload, attempts, next_attempt_at, last_error
audit_log every portal AND product action (Retraced-compatible; see
PRODUCT_INTEGRATION_SPEC.md §8.4)
Links:
tenants.id= Keycloak org attributetenant_id(one-to-one; org alias = slug)tenants.erp_customer_id= ERPNextCustomer.name(one-to-one; ERPNextCustomer.tenant_idcustom field is the reverse link)
API surface (groups):
Tenant lifecycle POST /v1/tenants · GET /v1/tenants (service) · GET /v1/tenants/{id}
GET /v1/tenants/by-slug/{slug} · POST …/activate · POST …/cancel
Catalog GET /v1/catalog · POST /v1/catalog/request · POST /v1/catalog/trial-request
Entitlements GET /v1/entitlements?tenant_id= ·
POST /v1/internal/entitlements/check {tenant_id, product, [addon]}
→ {allowed, status, limits, reason} (products call this; cache ≤ 60 s)
Usage POST /v1/usage/events (batch, idempotent) · GET /v1/usage?tenant_id=
API keys GET/POST/DELETE /v1/api-keys · POST /v1/internal/api-keys/verify
Licences (CLI) POST /v1/licences (issue) · POST /v1/licences/heartbeat ·
POST /v1/licences/{id}/revoke · GET /.well-known/licence-keys.json
Identity GET /v1/users/{id}/memberships · (SyncClaims → Keycloak tenant_status)
ERP link POST /v1/internal/erp/webhook (HMAC) · GET /v1/internal/erp/status
Audit POST /v1/audit · GET /v1/audit
Probes GET /healthz · GET /readyz
Authorization is per client: each Keycloak service client is mapped to the route groups it may call (portal-svc: tenants/catalog/api-keys/audit; pruefwerk-svc: entitlements/usage/audit/api-keys.verify; erp-svc: erp webhook only; …).
5d. Demo Tenant (Shared)
Slug: demo — reachable at app.breakpilot.com/demo/…
Status: demo (never transitions; never billed)
Owner: us (BREAKPILOT_ADMIN curates content; SALES_REP reads + logs in)
A single, shared tenant pre-seeded with realistic-but-fake data covering the first-line products. Sales reps use it to walk prospects through the product live. Prospects do NOT log in directly — the sales rep drives the screen.
Differences from a real tenant and the nightly reset (03:00 Europe/Berlin, POST /v1/tenants/demo/reset on each product, fixtures from platform/seed-data) are unchanged from the 2026-05 design.
5e. Frappe Helpdesk + Gitea Issues
Unchanged: customer submits via /[slug]/support/ (link to the Frappe HD customer portal on erp.breakpilot.com; no iframe), agent triages in Frappe HD, "Escalate to Engineering" creates a Gitea issue via REST, issue close → webhook → ticket resolved.
6. Plane 3 — App (Products)
All products run on the platform cluster, pinned to the environment's VM, and integrate through PRODUCT_INTEGRATION_SPEC.md 2.0. Each product owns its data store; nothing is shared across products.
Prüfwerk (pruefwerk)
Surface: standalone web app at pruefwerk[-stage].breakpilot.com (Dioxus dashboard), agent API, MCP server (/mcp), docs (/docs).
Multi-tenancy: one MongoDB database per tenant (compliance_scanner_<tenant_id>), tenant-scoped webhooks, tenant-bound MCP tokens.
Auth: dashboard = Keycloak OIDC PKCE; agent validates user JWTs via JWKS with issuer and audience pinned; service token for registry; MCP = API keys / bound tokens.
Entitlement: on every tenant-context build the agent calls entitlements/check (cached ≤ 60 s): product pruefwerk enabled, limits (targets, scans/month), addons (werkbank runner count), ladder state. Scheduler enumerates tenants via GET /v1/tenants with a service token.
Usage: scan.completed, target.added, seat.login events → registry.
Role mapping: IT_ADMIN → Admin; CXO, USER → Member; FINANCE, LEGAL → Viewer.
Werkbank runners authenticate with a tenant-scoped API key (product=pruefwerk, scope werkbank:runner), verified by the agent through the registry; the runner count per tenant is an entitlement limit.
Werkpilot (werkpilot)
Surface: CLI only (werkpilot, werkpilotd, werkpilot-tui), released as signed tarballs through Gitea releases; no hosted service.
Auth + entitlement: werkpilot login (device flow) → licence token from the registry; offline verification; hourly heartbeat; local 4-state ladder. Seats = named users (DEV-WP-CLD-*), on-prem instances (DEV-WP-OPR-*) get yearly licences.
Usage: seat.session_started heartbeat events (daily aggregate) via the phone-home.
LLM: llm.breakpilot.com (core LiteLLM) with a per-tenant virtual key issued at licence time.
Firmwerk (firmwerk)
Surface: CLI (firmwerk) + firmwerk-cloud-server at firmwerk[-stage].breakpilot.com (licensing, SBOM upload receipts, invites, OSV lookups).
Auth + entitlement: firmwerk login (device flow) → licence token from the registry. The cloud-server drops its own tenant/api-key/licence model; it verifies registry licence tokens (public keys from /.well-known/licence-keys.json) and calls entitlements/check for limits (environments per user). Read-only usage is free forever; writes need an active subscription; 14-day trial on any tier.
Usage: environment.created, sbom.uploaded, seat.active events.
breakpilot-compliance (compliance) — after M-MIG-9
Tenant identity from validated JWT; Postgres RLS by tenant_id; role mapping LEGAL approves DSFA, IT_ADMIN compliance admin, USER contributes. Re-onboarded to contract 2.0 once it runs on the platform cluster.
7. Plane 4 — Infra
Orchestration: Orca on Hetzner VMs. Per-node ingress: every node binds 80/443 and runs its own ACME (HTTP-01); a service's A record points at the VM that runs it. Two clusters, two IaC repos: sharang/orca-infra (core) and platform/orca-platform (platform).
Placement: every platform service carries placement.node = "bp-platform-stage" | "bp-platform-prod"; service names are unique cluster-wide (-stage / -prod suffix); scripts/validate.sh enforces both in CI.
Secrets: Orca project-scoped secrets (orca secrets set --project <p>), never global for production values. Infisical (core) holds the licence signing key and CI credentials.
CI/CD: Gitea Actions → image → Harbor repo.breakpilot.com/<project>/<image> → signed webhook to the platform master (main → stage). Production deploys on tags via a prod branch webhook (prod plan).
Routing (platform cluster, per node):
bp-platform-stage bp-platform-prod (later)
app-stage.breakpilot.com → portal-stage app.breakpilot.com → portal-prod
registry-stage.… → tenant-registry-stage
registry.… / licence.… → tenant-registry-prod
pruefwerk-stage.… → pruefwerk-dashboard-stage
/mcp/* → pruefwerk-mcp-stage
/docs/* → pruefwerk-docs-stage
firmwerk-stage.… → firmwerk-cloud-stage
pruefwerk.… / firmwerk.… (same shape)
(erpnext-mock-stage, pg, mongo, browserless, soft-plc, plc-sim, werkbank-runner: internal)
Services managed by Orca (platform cluster, per environment):
Control portal-{env}, tenant-registry-{env}, pg-{env}, erpnext-mock-stage (stage only)
Prüfwerk pruefwerk-agent, pruefwerk-dashboard, pruefwerk-mcp, pruefwerk-docs,
pruefwerk-mongo, browserless, soft-plc, plc-sim (scan targets), werkbank-runner
Firmwerk firmwerk-cloud, firmwerk-mongo
(dsms, after M-MIG-9) breakpilot-db, backend-compliance, ai-compliance-sdk, admin-compliance,
developer-portal, dsms-node, dsms-gateway, document-crawler, tts, qdrant,
ollama-embed, pitch-deck
Core services consumed over HTTPS: Keycloak, ERPNext (prod), Gitea, Harbor, LiteLLM, Infisical, SigNoz/OTel, Gatus.
Security headers: Orca [security_headers] frame_options = "DENY", CSP set — product UIs are never embedded.
8. Process Sketches
Only the sketches that changed are drawn in full; the rest are listed with their delta.
P1 — New Customer Onboarding (Sales-Led)
US (ERPNext) TENANT REGISTRY KEYCLOAK IT ADMIN
│ Lead → Opportunity │ │ │
│ → Quotation → Sales Order │ │ │
│ submit ── webhook (HMAC) ──►│ │ │
│ │ create/lookup tenant │ │
│ │ create org ──────────►│ │
│ │◄── org_id ────────────│ │
│ │ subscriptions ← SO │ │
│ │ tenant_products │ │
│ │ status = active │ │
│ │ SyncClaims ──────────►│ │
│ │ outbox: Customer.tenant_id ──► ERPNext │
│ │ invite IT_ADMIN ──────────────────────►│
│ │ │ set pw + 2FA │
│ │ lands on app.breakpilot.com/acme/dashboard
P2 / P3 — User Login
As before, with app.breakpilot.com/acme instead of acme.breakpilot.com: portal resolves the slug from the path, looks up the tenant (IdP hint if configured), redirects to Keycloak, lands on /acme/dashboard.
P4 — IdP configuration, P5 — Invite: unchanged.
P6 — Customer Accesses a Product
USER PORTAL TENANT REGISTRY PRODUCT (pruefwerk.breakpilot.com)
│ /acme/products/ │ │ │
│ pruefwerk │ │ │
│─────────────────►│── check ─────────►│ │
│ │◄ allowed/denied ──│ │
│ [allowed] ◄─── "Open Prüfwerk" ─────┤ │
│──────────── SSO redirect (Keycloak, same realm session) ───────►│
│ │ │◄── entitlements/check ───│ (cached ≤60 s)
│ │ │── {allowed, limits} ────►│
│◄─────────────────────────────────────────────── product UI ────│
│ [denied] ◄── "Not in your plan" + request CTA (P13) │
P7 — Finance User Views Billing
FINANCE USER PORTAL TENANT REGISTRY ERPNEXT (core)
│ /acme/billing │ │ │
│──────────────►│── subscriptions ─►│ (local mirror) │
│ │── invoices ──────►│── REST (server) ────►│
│ │◄──────────────────│◄─────────────────────│
│◄── plan · usage (usage_events) · invoices · dunning state │
│ [Download PDF] ─────────────────►│── print format ─────►│
│ [Upgrade] → CRM Lead via outbox (P13) │
P8 — Audit export, P9 — Support escalation, P10 — Backstage create, P11 — Impersonation: unchanged (URLs become app.breakpilot.com/acme/...). P10 additionally queues the ERPNext Customer upsert through the outbox.
P12 — ERPNext Event Drives the Ladder (always-on link)
ERPNEXT TENANT REGISTRY KEYCLOAK PRODUCTS
│ Sales Order submit / │ │ │
│ Payment Entry / Invoice │ │ │
│ overdue / Dunning / cancel │ │ │
│── webhook (HMAC, doc name+ts)►│ idempotency check │ │
│ │ recompute ladder: │ │
│ │ paid → active │ │
│ │ overdue ≤ grace → warning │ │
│ │ grace exceeded → restricted │ │
│ │ ended → halted → archived │ │
│ │ update subscriptions/products │ │
│ │── SyncClaims(tenant_status) ─►│ │
│ │── suspend/reactivate ────────────────────► │
│ │ audit event │ │
│ every 15 min: reconcile ◄─────│ (re-read Subscriptions, repair drift) │
P13 — Catalog Request → CRM Lead (via outbox), P14 — Sales demo (app.breakpilot.com/demo), P15 — Self-serve trial (/start; conversion = Sales Order in ERPNext, no card PSP), P16 — Cancel and offboard (Subscription cancel in ERPNext → halted → export window → archived; DELETE /v1/tenants/{id}/data on every product): unchanged in substance.
P17 — Usage Event → ERPNext Usage Record
PRODUCT TENANT REGISTRY ERPNEXT
│ scan completed │ │
│── POST /v1/usage/events│ (idempotency_key) │
│ [{metric, qty, at}] ►│ store usage_events │
│ │ enqueue erp_outbox │
│◄── 202 ────────────────│ │
│ │ worker: ── Usage Record on the │
│ │ tenant's Subscription ►│ (≤ 60 s, retry/backoff)
│ │◄── ok / error (kept for retry) ──│
│ │ portal usage chart reads usage_events; invoices stay fixed-tier
P18 — CLI Licence Lifecycle (Werkpilot, Firmwerk)
CLI (customer machine) KEYCLOAK TENANT REGISTRY ERPNEXT
│ werkpilot login │ │ │
│── device code ─────────────►│ user approves │ │
│◄── user token ──────────────│ │ │
│── POST /v1/licences (token, product, machine id) ►│ entitlements + ladder │
│◄── licence JWT (Ed25519, valid-until, sku, tier, grace policy) ─┤ │
│ verify offline against /.well-known/licence-keys.json │ │
│ hourly: POST /licences/heartbeat ──────────────► │ refresh or refuse │
│ │◄── ladder from ERP events ─│
│ no renewal → local ladder: Healthy 0–7d → Warning 7–14d → Degraded 14–30d │
│ (read-only) → Hard-stop > 30d │ │
Headless Product Flows (H1–H6)
Unchanged for frontend.type = headless products (API keys, webhooks, portal-rendered config page, no impersonation). H5 no longer has a widget branch: dashboard tiles are either "Open" (standalone), a stat tile fed by GET /v1/usage (headless), or a licence/seat tile (cli).
9. Technology Decisions (Locked — 2026-09-11)
| Decision | Choice | Rationale |
|---|---|---|
| Identity | Keycloak on core, one realm per platform env (breakpilot-stage, breakpilot-prod) |
One instance to operate; hostname collision avoided; company SSO untouched |
| Tenant model | Keycloak Organization per customer, tenant_id org attribute = registry UUID |
Native isolation, JWT claims, no custom multi-tenant auth code |
| Tenant routing | Fixed host per env, tenant slug in the path | Orca has no wildcard routing or DNS-01; no custom domains anyway |
| Product UIs | Standalone apps on branded hosts behind SSO; headless; CLI | No embedding contract to maintain; products keep their own stacks |
| Entitlements | tenant-registry is the authority; products call entitlements/check; Keycloak carries coarse tenant_status only |
Finance never touches the IdP (ERP/02); no stale entitlement claims |
| Commercial truth | ERPNext (core), always-on link via outbox + webhooks + 15-min reconcile | One accounting system; no delivery-loss blind spot |
| Billing | ERPNext invoicing only (Quotation → SO → SI → Payment Entry, Subscriptions, Dunning); usage records continuous, invoices fixed-tier for launch | B2B DACH customers pay by invoice; no PSP integration before launch |
| CLI licensing | Registry-issued Ed25519 licence JWTs, offline verify, hourly phone-home, 4-state ladder | Works in customer CI and air-gapped setups; one licence system for both CLIs |
| Secret management | Orca project-scoped secrets; Infisical for signing keys + CI | Matches how Orca resolves ${secrets.*}; prod never global |
| Business operations | ERPNext (Frappe) + Frappe CRM + Helpdesk | CRM + sales + invoicing + HR + support in one |
| Engineering issues | Gitea Issues | Already running; Frappe HD → Gitea via REST |
| Data isolation | Logical (tenant_id / per-tenant DB) | Sufficient for Starter/Professional; physical isolation for Enterprise later |
| Customer portal | Next.js 16 app (platform/portal) |
Exists; path-based tenancy is a middleware change |
| Tenant Registry | Go service (platform/tenant-registry) |
Exists; extended with products/plans/subscriptions/usage/licences/outbox |
| Products scope | Prüfwerk (+Werkbank), Werkpilot, Firmwerk | First line; compliance re-onboarded after migration; CERTifAI parked |
| Hosting | Hetzner Cloud, EU; one platform cluster, one VM per env | Legal entity exists; smallest topology that separates stage from prod |
10. Phasing
See IMPLEMENTATION_PLAN.md: the migration milestones M-MIG-0 … M-MIG-9 (spec revision → stop on core → staging VM → repo moves → platform services → products → entitlements/licences/ERP link → E2E → dsms) replace the earlier M0–M19 plan. Production is planned separately after the staging gate passes.
End of document. Revised 2026-09-11 (staging rollout).