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.
PRD — MES Execution Views (Operation / Assembly / Inspection)
Status: implemented (branch feat/mes-assembly) · Owner: MES execution-views
Single consolidated spec for the MES execution-view work: the operationKind classification,
the mobile Assembly view, part/tool ↔ step linking, step reference images ("slides"), and the
planned Inspection view. Supersedes the earlier per-topic docs (CONTEXT.md, MES-FEEDBACK-STATUS.md,
MES-PHASE2-DONE.md, MES-PHASE2-TEST-PLAN.md, PRD-step-reference-images.md, docs/adr/0001–0005 —
all removed from the branch; recoverable from git history).
1. Problem & goal
Operators on the shop floor execute three fundamentally different kinds of work from the MES: machining/processing (the existing Operation view), assembly (step-by-step build instructions with per-step parts, tools, and reference imagery), and inspection (executing a quality plan and recording actuals). Today the MES has one execution screen built around the first mode. This work introduces a per-operation classification that routes the operator to the right view, builds the Assembly view (mobile-first), scopes materials/tools/reference images to individual build steps, and lays the schema groundwork for the Inspection view.
2. Glossary (ubiquitous language)
jobOperation
A single step of a job's routing (the live name for "BOP" — bill of process). The unit of work an
operator executes. Each jobOperation is copied from a methodOperation template by the
get-method edge function when a job is created.
operationType (formerly operationKind — superseded)
Superseded by 2026-07-20-operation-type-consolidation.md:
operationKindwas collapsed into a singleoperationTypeenum (Process | Assembly | Inspection | Outside Processing, NOT NULL defaultProcess), shared withprocess.processType. The per-operation classification that decides which execution view an operator sees:Assembly→ assembly view,Inspection→ inspection view (falls through to Operation until Phase 3), everything else → Operation view. Subcontract logic keys on= 'Outside Processing'; in-house logic on<> 'Outside Processing'. Orthogonal to tracking type. Stored onmethodOperation(template) and copied verbatim tojobOperation/quoteOperationbyget-method. The process's own type is the authoring default (picking a process seeds the operation's type).
tracking type
The item's itemTrackingType — Serial | Batch | Inventory | Non-Inventory. Decides per-unit
vs. batch cadence inside a view, never which view. requiresSerialTracking /
requiresBatchTracking are derived in code from the item's itemTrackingType
(=== "Serial" / === "Batch"); they are not stored columns on jobMakeMethod.
unit axis
The list of units an operator pages through ("Unit X of N"). Quantity-centric: length =
operationQuantity for every tracking type. Unit i carries trackedEntities[i] ?? null.
Serial binds a tracked entity per unit; Batch binds one lot entity to unit 0 only;
Inventory/Non-Inventory bind none. This is the shared module (FIX-1) used by Assembly and
(per-sample) Inspection.
Record-index convention: jobOperationStepRecord.index = the unit's position i on the unit
axis, for all tracking types (Serial = entity position in trackedEntities;
Batch/Inventory = 0…N-1). Identical to what the Operation view already writes, so the three
views agree on per-unit done-state and no record backfill is needed. Relies on trackedEntities
being returned in a stable, deterministic order.
slide
One reference image attached to a step, with an optional caption and a sortOrder. The atomic
unit operators page through. Slides are reference media on the step, not a step type.
inspection plan
The quality definition for a part: an inspectionDocument (ballooned drawing) holding
inspectionFeature rows (features with nominal ± tolerance and unit). Today an ERP-only
definition with no link to a job/operation and no result-capture. The Inspection view executes a
plan against a jobOperation, linked by an explicit nullable inspectionDocumentId FK on the
operation (picker defaults via resolve-by-item: the part's sole inspectionDocument if exactly
one exists).
variable / attribute feature
An inspectionFeature is variable (numerically evaluated for pass/fail against
nominalNumeric ± tolerance) iff its numeric columns are populated; otherwise it is an
attribute feature the inspector marks pass/fail by hand (thread fits, surface-finish
callouts, GD&T, visual). Numeric columns (nominalNumeric, tolerancePlusNumeric,
toleranceMinusNumeric) are added alongside the existing TEXT, which is retained for display and
non-numeric specs. See §5.3.
pass/fail evaluator
A pure function (actual, nominalNumeric, tolerance±, unit) → pass | fail | out-of-tolerance,
run only for variable features. Records actuals into the inspection result record.
result record
The planned jobOperationInspectionRecord table — one row per inspectionFeature per
unit/sample, keyed (jobOperationId, inspectionFeatureId, index). Modeled column-for-column on
jobOperationStepRecord (numericValue = actual; value/booleanValue/userValue for
attribute features); index from the unit-axis module; optional gaugeId; a result
(pass | fail | out-of-tolerance) frozen at record time for as-inspected evidence. A failing
row links a nonConformance via the existing association. It is not a jobOperationStepRecord
— inspection features are inspectionFeature rows, never synthetic procedure steps.
See §5.4.
3. Delivered functionality
Phase 1 — Mobile/touch Assembly UI ✅
- Primary operator actions (Complete, Flag issue, timer Start/Pause) sized
lg; material issue/scan tap targets enlarged 20px → 36px. - "Assy" label renamed to "Completed item".
- Fullscreen reference-image viewer with pinch/wheel zoom and pan (
ImageZoomViewer.tsx).
Phase 2 — Part/Tool ↔ Step ✅ (end to end)
The idea in one line: a material/tool is owned by an operation and may be optionally
assigned to one step of that operation. The assignment is a nullable FK — NULL = applies to the whole operation (shown on every step, the legacy behavior). The link is authored on the
method template (ERP) and copied to the job by the get-method edge function, exactly
like steps, slides, tools, and parameters already are. The MES then filters per step.
methodOperationStep (a step of an operation)
▲ ▲
│ methodOperationStepId │ methodOperationStepId (NULL = whole operation)
│ │
methodMaterial methodOperationTool ← authored in ERP (BoM / BoP editors)
│ │
│ get-method copy (method-step → job-step map)
▼ ▼
jobMaterial.jobOperationStepId jobOperationTool.jobOperationStepId
│ │
▼ ▼
MES assembly view filters materials & tools to the current step
Data model. Six nullable FK columns (3 tiers × {material, tool}), each indexed:
| Table | Column | References | On delete |
|---|---|---|---|
methodMaterial |
methodOperationStepId |
methodOperationStep(id) |
SET NULL |
jobMaterial |
jobOperationStepId |
jobOperationStep(id) |
SET NULL |
quoteMaterial |
quoteOperationStepId |
quoteOperationStep(id) |
SET NULL |
methodOperationTool |
methodOperationStepId |
methodOperationStep(id) |
SET NULL |
jobOperationTool |
jobOperationStepId |
jobOperationStep(id) |
SET NULL |
quoteOperationTool |
quoteOperationStepId |
quoteOperationStep(id) |
SET NULL |
- Backward compatible: every existing row stays
NULL(operation-level). ON DELETE SET NULLis deliberate — the material/tool belongs to the operation and is only assigned to a step. Deleting the step must revert the link to operation-level, not delete the material/tool.
Authoring (ERP).
- Part → step: the BoM editor's operation row gains a Step picker listing the selected
operation's steps; changing the operation clears the step
(
apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx;methodMaterialValidatorgains optionalmethodOperationStepId). - Tool → step: the BoP editor's tool add and edit forms render the same optional Step picker
(
apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx). The tool routes readmethodOperationStepIdstraight fromformData(notvalidation.data) so the sharedoperationToolValidatorstays tier-agnostic — job/quote tools use a different column name.
Copy to the job (get-method edge function). Both job-copy paths (itemToJob,
itemToJobMakeMethod) build a method-step → job-step map when steps are inserted (a bulk
insert preserves order, so insertedSteps[i] ↔ methodOperationStep[i]).
jobMaterial.jobOperationStepId and jobOperationTool.jobOperationStepId are set from that map;
unmapped → null. Key fix for tools: the operation loop previously inserted tools before
steps, so the step map didn't exist yet — the jobOperationTool insert was moved to after the
step insert in both job paths. Tools on procedure-based operations (no steps) still copy, with
jobOperationStepId: null. The accumulating step map is safe across operations because step ids
are globally unique. The get_method_tree RPC surfaces methodMaterial.methodOperationStepId
on material tree nodes, including top-level (root assembly) materials.
MES per-step filtering. getToolsByProcessId (which looked up any method operation by
processId) was replaced by getToolsByOperationId, which reads the job's own
jobOperationTool rows and carries jobOperationStepId
(apps/mes/app/services/operations.service.ts). In AssemblyView.tsx, materials and tools are
filtered to the current step with the identical rule:
// applies to this step if unscoped (null) or scoped to this step
m.jobOperationStepId == null || m.jobOperationStepId === (step?.id ?? null)
Serial/batch scan-at-step falls out for free: the per-step material list drives the "Scan Part" pre-selection, so the operator scans the tracked part on the step where it's used.
Phase 3 — Behavioral ✅
- Auto-start job + operation on production-event Start (
startProductionEvent→autoStartJobAndOperation, status-guarded; both start paths). Gated by thecompanySettings.autoStartOperationTimerflag. - MES preview from the BOP tab with no live job (
OperationPreviewread-only per-step view: image + step text + per-step tools, in the BillOfProcess "Preview" tab). - Realtime refresh of BOP steps on a live job without closing (realtime channel on
jobOperationStep/jobOperationStepRecord→ revalidate in JobBillOfProcess).
Operation Type + Kind merge ✅ (columns physically collapsed)
Done — see 2026-07-20-operation-type-consolidation.md.
One enum Process | Assembly | Inspection | Outside Processing on operationType
(operations AND process.processType — same Postgres type; the old processType and
operationKind enums are gone). All three BOP editors (Item, Job, Quote) share the same
single Operation Type picker; the classification shim (operationClassifications +
mapping helpers) was deleted; every === "Outside" site was rewritten to
=== 'Outside Processing' and every === "Inside" site to !== 'Outside Processing'.
"Standard" was renamed to "Process"; "Batch" stays dropped (tracking type's job).
4. Step reference images ("slides")
Problem
Operators need reference imagery per build step — "here's what this looks like when done /
where this part goes." Previously there was no first-class way to attach one: images were
embedded inside the step's rich-text description (TipTap image nodes) and scraped back out at
render time by an extractImages() heuristic, so image order/captions weren't data and reference
art was tangled with instruction prose.
Model
A slide is a first-class child of a step holding one image plus optional caption and
order. A step has zero or more slides; execution views render them as a per-step carousel.
Slides are authored on the method (template) and copied to the job/quote operation by
get-method, exactly like steps, materials, tools, and parameters.
Three tables mirroring the step-copy chain: methodOperationStepSlide (authored in ERP),
jobOperationStepSlide (copied per job), quoteOperationStepSlide (copied per quote). Columns:
id (id('slide')), stepId FK → matching *OperationStep ON DELETE CASCADE, imagePath
(private-bucket storage path; nullable since the step-model-slides migration), modelUploadId
(nullable FK → modelUpload ON DELETE CASCADE — a slide is image XOR model, enforced by a
CHECK), caption (nullable), sortOrder (double precision), size (display size, default
medium), annotations (JSONB, default []; image slides only), companyId, standard
audit columns. RLS: identical policies to the parent step tables.
3D model slides (added 2026-07-19, 20260719221229_step-model-slides.sql): a slide can be
a 3D model instead of a picture. The editors upload the file to {companyId}/models/… in the
private bucket and register it via /api/model/upload with convert — which fires the
assembly-convert Inngest task (assembler service STEP → GLB) when the source is STEP and the
assembler is healthy. The MES assembly view renders model slides with ModelViewer, preferring
modelUpload.glbPath and falling back to the raw modelPath (parsed client-side), so the
feature degrades gracefully when the assembler is not deployed. get-method copies
modelUploadId verbatim alongside imagePath.
Assembly → BOP sync (added 2026-07-20, 20260720025847_assembly-bop-sync.sql): a
Published assemblyInstruction's steps can be copied into a BOP operation ("Sync to BOP"
on the instruction header) — target is a Draft method operation (jobs inherit via
get-method) or an unlocked job operation. Synced steps carry an
assemblyInstructionStepId provenance marker so re-sync updates/deletes only its own
steps, per-step BOM parts become material↔step links, and the instruction's model is
attached as a model slide per step. See syncAssemblyInstructionToOperation
(production.service.ts).
Step-aware 3D playback in the MES assembly view (added 2026-07-20): when the job
operation carries assemblyInstructionId and the model has converted artifacts, the
loader resolves getAssemblyPlaybackByOperationId and the view mounts the animated
AssemblyPlayer (@carbon/viewer) pinned to the operator's current step — mapped via
the step's assemblyInstructionStepId marker. It is the default media for mapped steps
(a ▶ 3D carousel entry); picture and static-model slides remain selectable. get-method
carries assemblyInstructionId onto job operations, so jobs made from a synced method
get playback automatically. This supersedes the earlier note that the animated player
stays out of the assembly view.
Non-goals
- Replacing the rich-text
description(prose stays; slides are separate reference media). - Video slides. (3D model slides shipped 2026-07-19 — see above; originally a non-goal.)
- Animated per-step assembly playback (
AssemblyPlayer/assemblyInstruction) inside the assembly view — model slides are static/orbitable models per step. - Operator-captured photos at run time (that's the existing File step-record type).
Acceptance criteria
- An engineer can attach N slides (image + caption + order) to a BOP step in the ERP.
- Creating a job copies the step's slides into
jobOperationStepSlidewith order preserved. - The assembly view shows the current step's slides as a carousel; "No reference image" only when a step truly has none.
- Captions render; ordering respects
sortOrder. - Description prose no longer needs embedded images.
- RLS: an operator can only read slides for operations in their company/assignment.
5. Architecture decisions (consolidated ADRs)
5.1 Separate MES route per execution view, with redirect guards (accepted)
Each execution view gets its own route:
/x/operation/:id → JobOperation (operationType = Process / Outside Processing, the default)
/x/assembly/:id → AssemblyView (operationType = Assembly)
/x/inspection/:id → InspectionView (operationType = Inspection — shipped 2026-07-26)
(Originally keyed on operationKind; re-keyed on the consolidated operationType —
see 2026-07-20-operation-type-consolidation.md. The value reaches the routes via
get_job_operation_by_id.)
Each route's loader returns one shape and renders one view. Every route opens with a
redirect guard: it reads the operation's operationKind and, if the kind doesn't belong to
that route, throws a redirect to the correct one (preserving search params) — so any URL
self-corrects and a reclassified operation's saved link still lands on the right screen.
This reverses an earlier decision to have one route (/x/operation/:id) switch on
operationKind with a discriminated-union loader. Reversed because: a route shouldn't return
three different response shapes (polymorphic-route smell); the three modes diverge over time
(Assembly gains CAD-driven instructions, Inspection executes a quality plan); and the URL should
communicate the mode. The deep-link-stability argument that justified the single route is
preserved by the guards, at the cost of an occasional extra redirect hop.
Consequences: the work queue navigates to /x/operation/:id and the guard redirects Assembly
ops (one hop) — routing the queue directly by kind would need operationKind in the work-queue
RPC (deferred optimization). Until the Phase-3 inspection route exists, Inspection ops fall
through to JobOperation (no redirect) to avoid a loop. Guards must not create loops: a route
only redirects kinds it does not serve, and only to routes that exist.
5.2 One shared MES execution core for all three views (accepted)
The Operation view (JobOperation.tsx, ~2,400 lines) and the Assembly POC (AssemblyView.tsx,
~1,800 lines) independently re-implement timers/productionEvent, quantity reporting, material
issue, NCR, realtime, completion, and unit navigation — and the two copies already drift. We
extract a single execution core all three views consume.
Direction: lift the core out of the working Operation view, and re-point the Operation view at
it first, as a behavior-preserving refactor verifiable against main. Only after Operation
consumes the extracted core (same screen, zero behavior change) do we re-point Assembly and build
Inspection on it. Boundary: shared core = hook(s) + shared modal components + a layout shell
(timer/productionEvent, quantity, material issue, NCR affordance, realtime channel,
completion/finish, unit-axis navigation); view-specific body = Operation's procedure/step
rendering, Assembly's build-step + static model, Inspection's feature list + record +
pass/fail + gauge. Sequencing: unit-axis module first → extract the core while wiring Assembly,
Operation re-pointed to prove parity → Inspection last. Rejected alternatives: a fresh core
(no parity gate, discards proven behavior) and keeping Assembly's copy (guarantees drift).
5.3 Numeric tolerance columns alongside TEXT on inspectionFeature (accepted)
Pass/fail needs numbers, but inspectionFeature.nominalValue / tolerancePlus / toleranceMinus / unit are TEXT — deliberately, since not every feature is numeric (thread fits like H7,
≤Ra 1.6, GD&T, visual go/no-go). We add nullable numeric columns (nominalNumeric,
tolerancePlusNumeric, toleranceMinusNumeric, DOUBLE PRECISION) alongside the TEXT rather
than replacing it or parsing at evaluation time. A feature is a variable feature iff
nominalNumeric is non-null; otherwise attribute (manual pass/fail). No featureType enum
in v1 — numeric-presence is the mode. The balloon-extraction/save path emits numeric for new
features; a one-time lenient backfill parses existing TEXT where clean and leaves null otherwise
(the backfill must never fail the migration). Numeric is authoritative for pass/fail, TEXT for
display; consistency is the extraction/save path's responsibility.
5.4 Inspection execution: explicit plan link and a dedicated result record (plan link accepted; result record SUPERSEDED)
Superseded (result record), 2026-07-26. The
jobOperationInspectionRecordtable was never built. After this spec, the quality module's inspection system was unified and made source-generic (20260722132135_inspections-refactor.sql:inspection/inspectionSample/inspectionSamplingPlan/inspectionMeasurementwithsourceDocument= 'Receipt' | 'Job Operation'). The shipped MES Inspection view executes against those tables — a lot per job operation created lazily on first open (getOrCreateJobOperationInspectionin@carbon/database/quality), per-feature AQL sampling, measurements ininspectionMeasurement, Accept/Partial/Reject disposition. Since 2026-07-27 the disposition carries its production outcome (one-shotrequireOpenclose, then Accept completes the remainder while Reject/Partial allocate the failed set per-unit between Scrap and Rework — the rework path viatrigger-rework's routing clone, which re-inspects automatically; provenance links onproductionQuantity.inspectionId/inspectionSampleIdguard double-posting); the NCR is optional documentation only. The plan-link half of this ADR stands:inspectionDocumentIdFK on method/quote/job operations, propagated by get-method. See.claude/rules/inspection-system.mdfor the live model. Plan link — explicit FK, not resolve-by-item. A nullableinspectionDocumentIdFK is added tomethodOperation/jobOperation/quoteOperationand propagated throughget-method(added in the Inspection workstream, not theoperationKindmigration, to keep the keystone classification migration independent). Resolve-by-item is ambiguous — a part can have multipleinspectionDocuments and different ops may inspect different feature subsets. The BOP-editor picker defaults via resolve-by-item; the stored FK is the source of truth.
Result record — a new table mirroring jobOperationStepRecord, not synthetic steps.
Inspection features are inspectionFeature rows, not jobOperationStep rows, so writing
into jobOperationStepRecord would require synthesizing fake steps. Instead
jobOperationInspectionRecord is keyed (jobOperationId, inspectionFeatureId, index), one row
per feature per unit/sample, with index from the shared unit-axis module, an optional
gaugeId, and a result frozen at record time (as-inspected evidence that survives later
tolerance edits; the numeric columns of §5.3 remain the source for re-evaluation). A failing row
links a nonConformance via the existing association.
Consequence: operationKind and inspectionDocumentId share the same get-method copy-lists —
omitting either silently breaks propagation.
6. Known gaps & backward compatibility
quoteLineToJobpath: the quote → job conversion copies neither part→step nor tool→step (parity with the part-link scope). Jobs created directly from an item's method (the common path) are fully covered.- Legacy jobs: rows created before this work carry
NULLstep links, so all materials/tools show on every step — the legacy behavior, no regression. - Procedure-based operations (no steps): tools copy with
jobOperationStepId = NULL; no errors. - Deleting a step reverts its materials/tools to operation-level (
ON DELETE SET NULL) — it never deletes them. - Type regen caveat (this branch only): a full
generate:typesrun against the restored dev DB is polluted; new columns were hand-added topackages/database/src/types.tsandpackages/database/supabase/functions/lib/types.ts. Regenerate cleanly before merge.
7. Remaining work (Phase 4 roadmap)
Job/Quote BOP editors: mirror the unified Type picker; physical✅ Done — 2026-07-20-operation-type-consolidation.md.operationType+operationKindcolumn collapse- Production: shortage flag → close without consuming stock → auto-raise a future job; passive step timer (cycle time); manager complete-all override; step overview screen.
- Content authoring: image resize/grid in the editor; annotation; tool hotspots.
- MES UX: navigate/filter incomplete steps; swipe between serials; hands-free advance.
- Quality: NCR → step link; parts/tools on NCR.
Inspection view (Phase 3 of the execution-views plan): route + guard, plan link, result record, pass/fail evaluator, gauge picker.✅ Shipped 2026-07-26 on the unified inspection tables (see §5.4 supersession note); gauge picker deferred.- Suggested (low priority): revision history, copy/clone steps, operator dashboard, step sign-off, rework flag, NCR trend, first-pass rate.
8. Verification
pnpm --filter mes typecheckandpnpm --filter erp typecheck→ 0 errors.- All schema changes live in the single squashed migration
packages/database/supabase/migrations/20260705143722_mes-assembly-view.sql. - Manual end-to-end check: author a method with an Assembly-kind operation, 3 steps, materials
and tools assigned to specific steps (one of each left operation-level), slides on two steps;
create a job from it; verify in the DB that
jobMaterial.jobOperationStepId/jobOperationTool.jobOperationStepIdcarry the mapped step ids (operation-level rows NULL); open/x/assembly/{jobOperationId}and confirm parts/tools/slides filter per step, operation-level items show on every step, scan-at-step pre-selects the tracked part on its step, and per-unit step completion tracks the unit pager.
-- parts per step on a job
SELECT jm."itemId", jos."name" FROM "jobMaterial" jm
LEFT JOIN "jobOperationStep" jos ON jos."id" = jm."jobOperationStepId"
WHERE jm."jobId" = '<JOB_ID>';
-- tools per step on a job
SELECT jot."toolId", jos."name" FROM "jobOperationTool" jot
LEFT JOIN "jobOperationStep" jos ON jos."id" = jot."jobOperationStepId"
WHERE jot."operationId" IN (SELECT "id" FROM "jobOperation" WHERE "jobId" = '<JOB_ID>');