The kernel, end to end.
AIPROCUREMENT.CLUB runs on three isolated vertical instances sharing one PostgreSQL database, connected by a typed event bus. Agents run as Supabase edge functions. Logic lives in PL/pgSQL constraint triggers, not application code.
System overview
Three Next.js 16 instances (P2P :3000, Treasury :3001, MRO :3004) plus ClinKernel and Telecom share the same Postgres 16 with row-level security. The cross-vertical event bus is database-native: typed tokens, immutable once emitted, causation-tracked.
Agent handoff network
Agents are stateless edge functions. Coordination is by event consumption, not RPC. A typical P2P pipeline:
requisition-agent→po-agent→idoc-architect→invoice-matcher→payment-agentSpawned in parallel for RFQ, surveillance, pricing, and SAP integration. Each agent writes to the event bus; downstream agents subscribe.
Data flow table
| Event | Trigger | Agent | DB writes | Treasury effect |
|---|---|---|---|---|
requisition.created | Telegram /req | requisition-agent | requisitions, audit_events | — |
po.issued | requisition.approved | po-agent | purchase_orders, idocs | commitment posted |
goods.received | WMS scan | goods-agent | goods_receipts | — |
invoice.received | email / OCR | invoice-matcher | invoices, match_results | liability accrued |
invoice.matched | 3-way match ok | invoice-matcher | invoices.state, ledger | payment scheduled |
payment.released | due date reached | payment-agent | ledger_events | cash decrement |
discount.proposed | treasury float | pricing-agent | discount_offers | provisional gain |
dispute.opened | invoice.disputed | dispute-arbitrator | disputes, evidence_hashes | liability frozen |
State machine registry · 131 transitions across 16 entities
Transitions live in the proc_state_machines table. Adding a new valid transition is a single SQL INSERT — no code deploy.
Database invariants · 19 constraints
Constraints enforced by Postgres, not by application code. Cataloged across four levels.
Workflow invariants (Petri-net theory)
Place invariants are conservation laws over active tokens. Transition invariants prove processes reach terminal states. Verification: proc_check_place_invariants().
- adverse event lifecycle
- analysis cycle
- capital deployment
- document lifecycle
- entity registry
- invoice lifecycle
- purchase order lifecycle
- requisition lifecycle
- RFQ lifecycle
- CAPA completion
- market intelligence cycle
- requisition rejection path
- SOP lifecycle
- spawn / close cycle
- procurement workflow
- SUSAR reporting