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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
@carbon/lib
Shared server utilities — event system, Inngest client, trigger dispatch, SMTP email, Slack messaging, and Twenty CRM.
Always
- Use
trigger(taskId, payload)for dispatching background jobs — typed helper that maps task IDs to Inngest event names; drop-in replacement for oldtasks.trigger() - Add new events to the
Eventstype inevents.ts— every Inngest event needs a typed payload here - Add new task mappings to
taskToEventintrigger.ts— maps human-readable task IDs tocarbon/*event names carbon/send-pushhas no task on purpose — only thenotifyjob sends it (step.sendEvent), because browser push mirrors the in-app row; app code never pushes directly- Guard external calls —
email.server.tsno-ops when no SMTP config is set (SMTP_*, with a legacyRESEND_API_KEYfallback via smtp.resend.com);slack.server.tsskips sends on localhost - Add new work events to
src/telemetry/events.ts— theWorkEventstype map is the contract;captureWorkEventis typed off it, so an unlisted name will not compile
Ask First
- Adding new Inngest event types (coordinate with
packages/jobs/function registration) - Changing the Inngest client ID (
"carbon")
Never
- Send emails or Slack messages directly from app routes — dispatch via
trigger("send-email", ...)ortrigger("send-slack", ...) - Import this package on the client — all exports are server-only (
.server.tsconvention)
Validation Commands
pnpm --filter @carbon/lib typecheck # tsc --noEmit
pnpm --filter @carbon/lib test # vitest run
Key Patterns
- Inngest client:
src/inngest/client.ts— singletonnew Inngest({ id: "carbon", logger: createInngestLogger() }). Thelogger(from@carbon/logger/inngest) routes every job'sctx.loggerinto LogTape under the["carbon","jobs"]category. - Trigger helper:
trigger(taskId, payload)/batchTrigger(taskId, items)— typed dispatch - Events:
src/events.ts— fullEventstype map (carbon/notify,carbon/send-email,carbon/send-slack, etc.) - Exports:
./events,./inngest,./trigger,./telemetry,./email.server(SMTPsendEmail,DEFAULT_FROM,EMAIL_DOMAIN),./resend.server(marketing contacts only),./slack.server,./twenty.server,./party-contact+./party-contact.server(checkPartyContactRequirement— the require-a-contact-and-location rule, shared by the ERP's post routes and the invoice automation job; the ERP'ssettings/party-contact*.tsre-export it),./sales-invoice-document.server(loadSalesInvoiceDocument+renderSalesInvoicePdf— one read of a sales invoice for its PDF and email, shared by the ERP PDF route, the manual post route and the invoice automation job; a pure function of aSupabaseClient, no request) - Work-event telemetry:
src/telemetry/—trackWorkEvent()records work done on the platform (jobs released, quotes sent, POs issued) as a PostHog event, over a barefetchwith no SDK. Three rules it must keep: it never throws into the caller (same contract asraiseMoment— a lost measurement beats a failed action), the eventuuidis deterministic from (companyId, event, recordId, discriminator) so a retry collapses instead of double-counting, and it emits only whenPOSTHOG_PROJECT_PUBLIC_KEYis set andCONTROLLED_ENVIRONMENTis off — the same gateapps/erp/app/entry.client.tsx:31puts on the browser SDK. Deliberately not named.server: MES service files are in the client graph (React components import their types), so a.serverspecifier fails the React Router build — which is also why the hash is plain TypeScript rather thannode:crypto. Seesrc/telemetry/README.mdfor the coverage gaps andVERIFICATION.mdfor the post-deploy runbook - Workflow moments:
src/workflows/raise-moment.ts—raiseMoment()announces a business moment (as opposed to a row change) to the workflow matcher. Two rules it must keep: it never throws into the caller (a failed announcement must not fail the business operation that raised it — it logs instead), and themomentIdit mints is used twice, as the Inngest event id and as the matcher'ssourceEventId, which is what makes a redelivery idempotent. See.claude/rules/workflow-matcher.md
Cross-References
packages/notifications/—NotificationEvent/NotificationDestinationenums used in event payloadspackages/jobs/— Inngest function implementations that consume these eventspackages/env/—SLACK_BOT_TOKEN,SMTP_*, and other env varspackages/logger/—createInngestLogger()wired as the Inngest client'slogger