Backend Response Contracts
This frontend consumes multiple backend response contracts. Do not force every route into one JSON envelope.
Sources
clab-assistant-v1Django API returns successful application payloads as{"status": "ok", ...}for endpoints such as/preview,/measures,/measurements/chart,/patterns/available,/pattern/editable,/pattern/groups,/materials,/piece-codes, and/genders.clab-assistant-v1Django middleware can return auth errors as{"error": "..."}.clab-estimator-v1is the Nesting/Estimator service consumed throughNESTING_API_URL; frontend proxy routes should preserve its job/result payloads.Internal Next.js API routes can use the local
successResponse/errorResponseenvelope when they are not acting as compatibility adapters or transparent proxies.
Clab Estimator (clab-estimator-v1)
clab-estimator-v1)src/app/api/fabric-layout/v2/** proxies the estimator service. Keep these routes thin: authenticate the caller, issue the workspace-scoped estimator token, normalize local request fields only when needed, and preserve estimator success payloads.
Observed estimator shapes:
POST /api/v1/nesting/jobsreturns{"job_id": "...", "status": "queued"}with HTTP 201.GET /api/v1/nesting/jobs/:jobIdreturns job status fields such asid,status,progress, timestamps,duration_seconds,is_terminal,meta,metrics,error_message, andresult_url.POST /api/v1/nesting/jobs/:jobId/retry,POST /cancel, andPOST /jobs/cancel-allreturn job/cancel status payloads and can use non-200 statuses such as 202 or 409.GET /api/v1/nesting/resultsreturns the estimator/S3 results list payload, including pagination fields controlled bycursorandlimit.GET /api/v1/nesting/results/:jobIdreturns rawresult.json.GET /api/v1/nesting/results/:jobId/summaryreturns the summary object withjob_id,run_id,materials,materials_count,has_multiple_materials,meta,fabric, andmetrics.GET /api/v1/nesting/results/:jobId/export.hpglreturns an HPGL attachment, not JSON.Estimator errors can be
{"error": "..."},{"detail": "..."},{"description": "..."}, or{"message": "..."}with additional details that must be preserved for debugging.
Frontend guardrails:
src/lib/services/clabEstimatorApi.tsownsNESTING_API_URLvalidation and estimator error parsing.src/lib/services/clabEstimatorApi.test.tscovers helper behavior.src/app/api/fabric-layout/v2/estimator-contract.test.tscovers the proxy contract for job detail, history list, summary, HPGL attachments, and retry conflict errors.
Change Procedure
When a Django or Estimator response changes:
Update or add a contract case in
src/lib/services/clabApiClient.contract.test.ts,src/app/api/fabric-layout/v2/estimator-contract.test.ts, or the relevant route test.Update the frontend adapter/proxy boundary only. Do not change unrelated internal API envelopes.
Run
npm run check, the affected route/client tests, andnpm run build.Keep backward-compatible parsing when existing saved projects or deployed backend versions can still send the old shape.
Last updated