Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
paths: - "apps/erp/app/routes/api+/kanban..tsx" - "apps/erp/app/modules/inventory/ui/Kanbans/.tsx" - "packages/documents/src/pdf/KanbanLabelPDF.tsx" - "packages/database/supabase/migrations/kanban.sql" - "apps/erp/app/modules/inventory/inventory.service.ts" - "packages/database/src/stock-transfer.ts" - "packages/database/src/event-system/handlers/kanban.sql" - "packages/jobs/src/inngest/functions/tasks/kanban-level-check.ts"
Kanban System
Scan-based replenishment cards for inventory items, per location. Each kanban scan
(via QR/label/URL) triggers a purchase order (Buy), a production job (Make), or a
stock transfer (Transfer). Lives in the inventory module.
Data model
Table kanban (initial migration 20250909012102_kanban.sql; newest 20261028191437_kanban-readable-id.sql (after 20261012232517_kanban-replenishment-level.sql), plus the generated 20261012232520_kanban-level-check-triggers.sql for its interceptor).
Composite PK ("id", "companyId"). Key columns:
idTEXT defaultid('kb'),itemIdFK→item (CASCADE),companyIdFK→companykanbanIdTEXT (nullable) — the readable number (KB000001, sequencekanban), printed on the label (20261028191437_kanban-readable-id.sql). Unique per company. The BEFORE INSERT triggerset_kanban_readable_idassigns it fromget_next_sequencewhen the insert has none (creating the company'skanbansequence row first if it is missing, so no kanban is left unnumbered), so every insert path (form, MCP, datasets, fixtures) is numbered with no call-site code. An insert that names its own number keeps it, and thesync_advance_document_sequenceinterceptor moves the counter past it (20261028221530), so a later generated number cannot collide. The BEFORE UPDATE triggerprevent_kanban_readable_id_change(20261028221145) refuses changing a set number — it is printed on the card — and allows filling a NULL one.upsertKanbandrops akanbanIdthe caller sends. Nullable only because a restore loads rows with triggers off, and a pre-migration backup has no number. Not to be confused withstockTransfer.kanbanId, the FK tokanban.id— the samejob.jobId/jobMaterial.jobIdsplit.replenishmentSystemkanbanReplenishmentSystemenum ('Buy' | 'Make' | 'Transfer'), default'Buy'— retyped fromitemReplenishmentSystemin20260908143722_kanban-transfer.sql(Transfer is NOT added toitemReplenishmentSystem; that enum drives planning/MRP/demand)quantityINTEGER (reorder qty),locationIdFK→locationstorageUnitIdFK→storageUnit (nullable) — renamed fromshelfIdin20260417000100_storage-unit-rename.sql. For aTransferkanban this is the destination (to) bin.fromStorageUnitIdFK→storageUnit (nullable) — the source bin for aTransferkanban (20260908143722_kanban-transfer.sql)replenishmentLevelNUMERIC (nullable,>= 0) — arms aTransferkanban's level signal (20261012232517_kanban-replenishment-level.sql). NULL = scan-only.upsertKanbanwrites NULL when the form field is blank or the system is not Transfer (zod omits a blank optional field, so a plain spread would keep the old value on update). It also writesfromStorageUnitIdNULL for a non-Transfer kanban, so a switch to Buy or Make drops the stale source bin.- CHECK
kanban_transfer_distinct_storage_units_check— a Transfer kanban's From and To bins differ (the zod refine alone let an API write create a self-feeding kanban). supplierIdFK→supplier,purchaseUnitOfMeasureCodeFK→unitOfMeasure,conversionFactorNUMERIC default 1 (Buy fields)autoReleaseBOOL,autoStartJobBOOL,completedBarcodeOverrideTEXT,jobIdFK→job ON DELETE SET NULL (Make fields;jobId/auto-start added in20251001001426_kanban-jobs.sql)- audit:
createdAt/By,updatedAt/By
Indexes: kanban_itemId_idx, kanban_locationId_idx (companyId, locationId), kanban_companyId_idx, kanban_jobId_idx.
RLS: SELECT = any employee role; INSERT/UPDATE/DELETE = inventory_create/inventory_update/inventory_delete.
View kanbans (SECURITY_INVOKER) is the read source for services/UI. Joins item, location,
storageUnit s (destination), storageUnit fs (source), supplier su, and job j — exposing
name, readableIdWithRevision, jobReadableId (= j."jobId"), locationName, storageUnitName,
fromStorageUnitName, supplierName, thumbnailPath. Recreated with storageUnit refs in
20260417000300_storage-unit-recreate-dependents.sql, then with the source-bin join in
20260908143722_kanban-transfer.sql, and again for replenishmentLevel and kanbanId
(20261012232517, 20261028191437).
kanbanOutput setting (enum ('label','qrcode','url'), default 'qrcode') is a per-company column on
companySettings (migration 20251001021231_kanban-settings.sql), NOT a kanban-specific table. Beside it,
kanbanLabelSize (enum ('letter','label4x2','label3x2'), default 'letter',
20261028214508_kanban-label-size.sql) is what a label prints on; the thermal values are labelSizes ids
(@carbon/utils). Both are saved by updateInventorySettings from the Kanban Output card
(x+/settings+/inventory.tsx), which shows Label Size only while the output is label.
Code surfaces
- Validator
kanbanValidator:apps/erp/app/modules/inventory/inventory.models.ts. Fields match columns above; enum iskanbanReplenishmentSystemTypes(Buy/Make/Transfer, distinct from the item-levelreplenishmentSystemTypes)..refines require:supplierIdwhenBuy;fromStorageUnitId+storageUnitId(and that they differ) whenTransfer. - Services:
apps/erp/app/modules/inventory/inventory.service.ts—getKanbans(client, locationId, companyId, args),getKanban(client, kanbanId, companyId),getKanbanProjectedQuantities(client, companyId, kanbanIds)(RPCget_kanban_projected_quantities, used by the list's Projected (To) column),upsertKanban,deleteKanban. Reads go through thekanbansview; writes hitkanban. The view expandsk.*at creation, so a newkanbancolumn needs the view recreated. kanbanOutputTypes+ validator:apps/erp/app/modules/settings/settings.models.ts. Set viax+/settings+/inventory.tsx.- UI:
apps/erp/app/modules/inventory/ui/Kanbans/KanbanForm.tsxandKanbansTable.tsx. Form shows Buy fields (supplier/UoM/conversion), Make fields (autoRelease, autoStartJob — gated on autoRelease, completedBarcodeOverride), or Transfer fields (From Storage Unit + the reused storage-unit field relabeled "To Storage Unit") conditionally. Dropdown offersBuy/Make/Transfer. - Routes: list
x+/inventory+/kanbans.tsx(auto-selects location, loadskanbanOutput), pluskanbans.new.tsx,kanbans.$id.tsx,kanbans.delete.$id.tsx.
Path config (apps/erp/app/utils/path.ts)
api:kanban,kanbanCollision,kanbanComplete,kanbanStart,kanbanJobLink→/api/kanban[/sub]/:idfile:kanbanLabelsPdf(ids, action)→/file/kanban/labels/:action.pdf?ids=;kanbanQrCode(id, action)→/file/kanban/:id/:action.pngto:kanbans,kanban(id),newKanban,deleteKanban(id)under/x/inventory/kanbans
action is always "order" | "start" | "complete". One action per card, never several codes on one card — an operator would scan the wrong one. Create, Start and Complete are separate cards (and separate print links).
Replenishment / scan flow
API routes in apps/erp/app/routes/api+/: kanban.$id.tsx, kanban.collision.$id.tsx, kanban.start.$id.tsx, kanban.complete.$id.tsx, kanban.link.$id.tsx.
kanban.$id.tsx (the "order"/create scan) calls scanKanban (inventory.server.ts), which branches on replenishmentSystem and returns what it made; the route picks the page:
- Make — if a job is already linked (
jobReadableId) it returnscollisionand the route opens the collision page (no duplicate job); otherwise creates a job from the item and links it (updateKanbanJob). WithautoRelease,scanKanbanruns the release checks (getJobReleaseReadiness+jobReleaseProblems— nothing to make, manufacturing blocked, assemblies without operations, outside operations without a supplier, strict backflush lines with no storage unit), thenreleaseCheckedJobsas the system on behalf of the scanner (a system context built from the scan's own service-role client andpg), so a scanner without production update can still release (recalculate, MRP, Ready, outside-operation POs, release date; telemetrysource: "kanban"), thenrunLocationScheduleonce the job is Ready. UnlikereleaseJobs, a supplier's Draft PO is not a blocker — no one at a kanban card can choose one — so the outside operations go on the supplier's newest Draft PO (highestpurchaseOrderId), else a new one; otherwise the first scan's PO blocked every later scan. A job that fails the checks stays Draft, stays linked, and the scan returns amessage. So does a job whose Get Method (upsertJobMethod) failed, with or withoutautoRelease: it is never released; the route throwsredirect(jobPage, flash(…))with it. Returning the flash withdata()does not work: the root'sflashMiddlewareclears it on the same request. Only a released job sends the scanner to MES:autoStartJobopens its first operation's start, else the operation. Seeapps/erp/app/modules/production/AGENTS.md→ "Every path to Ready". - Buy — reuses an existing draft/planned PO for the supplier (or creates one), adds a PO line with the kanban qty (applying
conversionFactor/purchaseUnitOfMeasureCode/storage unit), redirects to the PO. - Transfer — calls
replenishKanban(inventory.service.ts, ported from thekanban-replenishserver function) withmode: "scan", which writes a Released stock transfer with one line:itemId,fromStorageUnitId→storageUnitId(to),quantity, and serial/batch flags fromitem.itemTrackingType(a serial line of qty > 1 splits into qty-1 lines,expandSerialTrackedLines). The transfer carriesstockTransfer.kanbanIdand a Tiptap note "Kanban replenishment — … Signal: scan by ." Redirects to the stock transfer, where the qty can be partially picked at pick time. Each scan makes a new transfer, with no level test. Storage rules are NOT evaluated (a QR scan can't show the acknowledge dialog the interactive wizard uses).scanKanbancalls it as the scanner (invokePostingwith the scanner's client and{ as: replenishKanbanPermission }): scan mode needscreate: "inventory", the same check thestockTransferRLS rule made when the route inserted directly. Never drop the client or theas— that lets any employee create transfers. The function re-checks that both bins belong to the company and the kanban's location (CWE-639). - Buy and Make — not a kanban option (the enum has no such value).
The collision page's "Remove Job" only unlinks the job (jobId: null; the job is unchanged) and redirects to the scan, which creates the next job.
start/complete resolve the linked job's active operation and redirect to the MES operation start/complete endpoints; link navigates to the job/operation.
Level signal (Transfer kanbans with replenishmentLevel)
Spec: .ai/specs/2026-10-06-kanban-internal-replenishment-level.md.
- Projected quantity = on-hand at the To bin (
item_ledger_on_hand_contribution, so Rejected tracked stock does not count) +outstandingQuantityof every stock transfer line into it whose transfer is not Completed (Draft counts: a reopened kanban transfer is still supply), manual or kanban. One function computes it:get_kanban_projected_quantities(company_id, kanban_ids). - Fires strictly below the level (
isBelowReplenishmentLevel,@carbon/database/stock-transfer). One level signal = one transfer ofn × quantity,n = ceil((level − projected) / quantity)(levelReplenishmentQuantity), so the level is reached in one signal. A scan moves onequantity. Kanbans sharing an item and To bin share supply within a call (addedInboundinreplenishKanban). - The open transfer counts as supply, so a second signal for the same shortfall writes nothing, and the pick moves stock from "inbound" to "on-hand" without changing the projected quantity.
- Three wake paths, all sending
carbon/kanban.level-check{ companyId, kanbanIds }and only for kanbans already below level:queue_kanban_level_checks— statement handler onitemLedger(any posting at the To bin).sync_kanban_level_check—afterinterceptor onkanban(arming or editing a level).util.sweep_kanban_levels()— pg_cronkanban-level-sweeperat7 * * * *, overutil.kanban_level_breaches(): covers a deleted transfer, a transfer completed short, a lost event. Both trigger bodies return early underapp.sync_in_progress(seeds, restores, test fixtures). All three need the Vault secretinngest_event_url.
kanbanLevelCheckFunction(functions/tasks/kanban-level-check.ts, concurrency 1 per company, nodebounce) callskanban-replenishwithmode: "level"("system"permission;kanbanIdsrequired).replenishKanbanlocks the kanbansFOR UPDATEin id order and re-reads the projected quantity inside its transaction, so a stale or duplicate event is a no-op.createdByis"system"on this path.- A kanban replenishment is a stock transfer with
kanbanIdset: the stock transfers list has a derived Source column (Kanban / Manual, filtered onkanbanId IS [NOT] NULLingetStockTransfers) and the header shows a Kanban badge linking to the kanban.
Labels & QR
- QR PNG route:
apps/erp/app/routes/file+/kanban+/$id.$action[.]png.tsx, 36px modules, color-coded by action: order=black#000000, start=emerald#059669, complete=blue#2563eb. (The old doc claiming "no color differentiation" was stale.) - Label PDF route:
apps/erp/app/routes/file+/kanban+/labels.$action[.]pdf.tsx—?ids=(comma-separated), one.in()read of thekanbansview scoped bycompanyId, rendered at the company'skanbanLabelSize(?labelSize=overrides). Thumbnails are fetched for the letter sheet only. - The card is defined once in
packages/documents/src/zpl/KanbanLabelZPL.tsx:KanbanLabelItem,kanbanLabelCode(the card's one code for itsaction, with a caption: CREATE, START or COMPLETE), the text helpers,canHoldKanbanLabel(3" x 2" and up; 100 x 50 mm passes),getKanbanLabelLayout(inches: the code on the right, as large as the label allows (at most 45% of its width), caption under it; a text column on the left — each field cut to the column — the part name up to two lines (wrapKanbanLabelText), every other field one line (fitKanbanLabelText): name, item ID, bins,QTYandMINon their own lines (kanbanLabelQuantityLines), supplier — with the kanban ID small at the bottom),KANBAN_LABEL_COLORSandgenerateKanbanLabelZPL(item, size, baseUrl, action). Text is cut by an estimated glyph width (fitKanbanLabelText) and escaped with^FH(zplFieldData,zpl/utils.ts). Pinned bykanbanLabelZPL.test.ts. KanbanLabelPDF(packages/documents/src/pdf/KanbanLabelPDF.tsx, via@carbon/documents/pdf): takes theaction; withoutlabelSize, a letter page, 2×3 grid = 6 labels/page — the action-colored code (like the PNG route) with the item thumbnail beside it, name, item readable id, storage unit/location,QTY: {quantity} {uom}(plusMIN: {replenishmentLevel}— no unit, becauseuomis the purchase unit and the level is in stock units), and a bottom row with thekanbanId(bold, left) and supplier (right). The code carries its caption (CREATE / START / COMPLETE, in the action's color) on the letter sheet too, since one sheet can hold all three cards of a kanban. With alabelSize, one card per page laid out bygetKanbanLabelLayout, so the PDF and the ZPL print alike; the PDF colors the code and caption by action (black Create, green Start, blue Complete), and the ZPL (black only) relies on the caption.- Print job:
resolveKanbanData(print-job/resolvers.ts) returns oneKanbanCardItemper action —order,start,completefor a Make kanban,orderonly for Buy and Transfer — so each card is its ownprintJob(description ends Create / Start / Complete) andrenderKanbanCard(print-job/renderers.tsx) renders the item'saction;kanbanUrl(BinderyPress data) is that action's scan URL fromkanbanLabelCode. A printer whose media size holds a card prints one at that size — ZPL, or a one-card PDF. A ZPL printer with smaller media fails the job; a PDF printer with smaller or no media prints the company'skanbanLabelSize.resolveKanbanDatauses thekanbanIdas the job's readable id. KanbansTablerenders Create/Start/Complete perkanbanOutput:label→PDF links (one card per action),qrcode→hover-card iframes (one open at a time:KanbanQrCodeHoverCardreads a table-levelOpenQrCodeContext),url→copyable API links; Start/Complete show for Make only. Bulk Print Labels (and the row menu's Print Label) prints each kanban's cards (all three for Make) whether it goes to a printer or falls back to the PDF (kanbanLabelsPdf(ids, "all"): the route'sallaction expands each Make kanban into Create, Start and Complete cards, eachKanbanLabelPDFcard carrying its ownaction): it opens a printer picker, pre-selecting the location'skanbanprinter context (Settings → Printing → Kanbans row, falling back to the location default), and POSTs oneKanbanprint job per kanban topath.to.manualPrintwhen the company has printer routes (the storage-unit list's pattern), else opens the PDF.createKanbanauto-prints the new kanban's cards throughautoPrint(inventory.service.ts, contextkanban) when the context's Auto-print is on — like a posted receipt or shipment. Update does not print.
Gotchas
- Newest migrations win:
shelfIdno longer exists — usestorageUnitId/storageUnitName. PK is composite, so queries/upserts scope bycompanyId. - Transfer kanbans only use the
order(create) scan — Start/Complete are Make-only. TheKanbansTablestorage-unit column rendersfromStorageUnitName → storageUnitNamefor Transfer.KanbanLabelPDFshows the samefrom → towhenfromStorageUnitNameis set (else the single destination bin); the field is threaded through BOTH label paths — the interactive route (labels.$action[.]pdf.tsx) and the print-job resolver/renderer (print-job/resolvers.tsKanbanCardItem+renderers.tsx). jobIdis auto-cleared (set NULL) when its job is completed/cancelled via thesync_job_complete_or_canceledevent interceptor (20260410031803_job-interceptors.sql). A populatedjobReadableIdin the view means an active job → "order" scan collides.