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:
- "packages/ee/**"
- "apps/erp/app/routes/x+/settings+/**"
- "apps/erp/app/modules/users/**"
Commercial Feature Licensing & Entitlement Pattern
How Carbon gates commercial (Enterprise/Business) features so they cannot be
unlocked by editing open-licensed code. Grounded against packages/ee/src/plan.ts,
plan.server.ts, entitlements.server.ts, and the reference implementations
(packages/ee/src/permissions.server.ts, console.server.ts, approvals/).
The license boundary
Carbon is open-core. The commercial license (root LICENSE) covers packages/ee
and every file whose name contains .ee (e.g. ApprovalRuleForm.ee.tsx). Everything
else is community-licensed. This is the same model as Twenty CRM (their marker is a
/* @license Enterprise */ header; ours is the packages/ee package + the .ee infix).
Each source file also states its license in a leading SPDX header, so the boundary is
readable per file: commercial files open with
// SPDX-License-Identifier: LicenseRef-Carbon-Commercial, everything else with
// SPDX-License-Identifier: AGPL-3.0-only. The spdx-license-header check
(@carbon/checks) enforces it, and the fixer (pnpm --filter @carbon/checks license-headers) writes it — the fixer is the source of truth for the full text, so do
not hand-type it. Location decides the license: a file moved into or out of
packages/ee, or renamed to gain or lose .ee., must have its header swapped — rerun
the fixer.
The bar this pattern hits (be honest about it)
You cannot make a machine refuse to run code its operator has edited. What the pattern
guarantees is: there is no route around the paywall that stays in open-licensed code.
Using a commercial feature requires either executing commercial code or editing commercial
code — both are license breaches. A deletable if in a community-licensed route is NOT a
lock; a check inside packages/ee is.
The three rules
- The feature body lives in
packages/ee. The service/engine that does the thing is commercial. Community code may call into it but must never reimplement it — so using the feature requires running commercial code. - The entitlement check lives INSIDE the ee function, via
requireEntitlement— not as a call in the open route. So stripping the gate requires editing commercial code. - UI is
.ee.tsxin the app module. Gated features stay VISIBLE with an upgrade OVERLAY — never hidden from the nav, never redirected away. The nav entry always renders; the gated list/editor route renders an upgrade overlay viausePlanGate({ feature })(if (isGated) return <FeatureUpgradeOverlay />), using the shared~/components/RulesUpgradeOverlay(blurred mock preview + copy) or the lower-level~/components/UpgradeOverlayprimitives. This is UX — the server ee check is the enforcement. Reference:x+/sales+/sales-rules.tsx+SalesRulesUpgradeOverlay.
The API — three helpers, know which to use
All in @carbon/ee. FEATURE_PLANS (plan.ts) is the source of truth for which plans
grant which Feature; every helper reads it.
| Helper | Shape | Where | Use for |
|---|---|---|---|
companyHasFeature(client, companyId, { feature }) |
Promise<boolean> |
plan.server |
RUNTIME paths that must DEGRADE (feature off = no-op), not throw |
requireEntitlement(client, companyId, feature) |
throws EntitlementError |
entitlements.server |
The LOCK. Top of every commercial AUTHORING function, inside packages/ee |
requireFeature({ request, client, companyId, redirectTo, feature }) |
throws a redirect |
plan.server |
UX only, in the open route loader/action — a friendly upgrade redirect |
companyHasFeaturesemantics: Community edition → false (blocked); Enterprise/Test self-hosted → true; Cloud → plan-based; bypass/carbon-owned → true. It is the ONE place the future license-key server plugs in (a signed, server-bound validity token) — so every feature inherits it without a call-site change.- Do NOT use
companyHasPlan/requirePlanfor community-gated features — those no-op off Cloud (a self-hosted feature toggle), so a self-hosted Community instance would pass. They remain only for features that are Cloud-paywall-only.
The two layers (both, deliberately)
- Route (open, UX):
requireFeature({ ..., feature: "X" })in the loader/action → redirect with an upgrade flash. Strippable, cosmetic. - ee (commercial, LOCK):
requireEntitlement(client, companyId, "X")at the top of the ee function → throwsEntitlementError. Un-strippable without editing commercial code.
Route wiring for the visible+overlay UX: the primary list/editor route's LOADER must NOT
requireFeature-redirect (that would hide the page) — let it load and render the overlay
client-side. Keep requireFeature on the WRITE routes/actions (new/$id/delete), which
are only reachable by direct URL when gated; a redirect there is fine. The write action
should catch EntitlementError or sit behind its requireFeature so the ee throw never
surfaces as a raw 500.
File-layout convention
packages/ee/src/<feature>/
├── models.ts # zod validators + const types (client-safe: @carbon/database, zod)
├── service.ts # the engine — requireEntitlement at the top of authoring fns (server)
├── types.ts # derived types (ReturnType<service>, input types) — type-only
└── index.ts # export * from "./models"; export type * from "./types"
Exports in packages/ee/package.json: @carbon/ee/<feature> → index.ts (client-safe),
@carbon/ee/<feature>.server → service.ts (server). Small features may be a single
<feature>.server.ts (see permissions.server.ts, console.server.ts).
UI stays .ee.tsx in apps/erp/app/modules/<module>/ui/ (coupled to ~/components/Form,
~/hooks — cannot move to the package, and does not need to). Routes stay in the app.
Refactor checklist (per feature)
- Add/confirm the
Featurekey inFEATURE_PLANS(plan.ts). - Move the feature's service/engine into
packages/ee/src/<feature>/(or a<feature>.server.ts). Fix~/deps:sanitize→@carbon/utils; redefine any~/utils/querytypes locally; keeptrigger()/notification calls in the ROUTE, not the ee function (@carbon/eedoes not depend on@carbon/jobs/@carbon/notifications). Moved files change license — rerunpnpm --filter @carbon/checks license-headersto swap their AGPL header for the commercial one (same for UI renamed to.ee.tsx). - Embed
requireEntitlement(client, companyId, "X")at the top of every authoring function. Runtime functions that must degrade usecompanyHasFeatureinstead. - Move the feature's validators/derived types with it; add the package exports.
- Repoint every call site from
~/modules/...to@carbon/ee/<feature>/.server. Remove the moved code from the community module's.service.ts/.server.ts. - UI →
.ee.tsx. Route → keeprequireFeaturefor the UX redirect + catchEntitlementError. - Verify:
pnpm --filter @carbon/ee typecheck,pnpm exec turbo run typecheck --filter=erp, Biome, and if an@mcpservice function leaves<module>.server.tsnote the MCP digest changes (pnpm run generate:mcp) — moving it out of the router removes it as an MCP tool, which is usually correct (an ungated MCP path would bypass the gate).
Rollout status (starter-only → new pattern)
Refactor one at a time; each PR should leave the tree green.
- ✅ Permissions authoring / console — body in
packages/ee(permissions.server.ts,console.server.ts);requireEntitlementembedded in every authoring function (employee-type CRUD,updateEmployee,updatePermissions,updateConsoleSetting). - ✅ Approvals — reference implementation (
packages/ee/src/approvals/);requireEntitlementinupsertApprovalRule/deleteApprovalRule, graceful degrade ingetApprovalRuleByAmount. - ✅ Sales rules / Storage rules — both families' authoring writes live in
packages/ee/src/rules/service.server.ts(@carbon/ee/rules.server):requireEntitlementembedded inupsertEnforcementRule/deleteEnforcementRule(feature chosen by thefamilydiscriminator),assignSalesRule/unassignSalesRule(SALES_RULES), andassignStorageRule/unassignStorageRule(STORAGE_RULES). The runtime evaluators (isSalesRulesEnabledForCompany/isStorageRulesEnabledForCompany) degrade viacompanyHasFeature; write routes gate withrequireFeature. The entitled writes are kept OUT of the client-safe@carbon/ee/rulesbarrel (which client components reach viauseRuleViolations) — the query getters stay there. - ✅ API keys —
upsertApiKey/deleteApiKeyinpackages/ee/src/api-keys.server.ts,requireEntitlement("API_KEYS"); routes gate withrequireFeature. - ✅ Webhooks — authoring in
packages/ee/src/webhooks.server.ts(requireEntitlement("WEBHOOKS"), includingrevealWebhookSigningSecret/rotateWebhookSigningSecret); delivery degrades at runtime viacompanyHasFeatureand signs with the ungatedgetWebhookSigningSecret. - ✅ Two-factor — the
requireMfacompany policy inpackages/ee/src/two-factor.server.ts,requireEntitlement("TWO_FACTOR")scoped to ENABLING only (a downgrade can still disable). - ✅ Forecast —
upsert/deleteDemandForecasts+upsert/deleteDemandProjectionsinpackages/ee/src/forecast.server.ts,requireEntitlement("FORECAST"). - ✅ Customer portals —
upsertCustomerPortal/deleteCustomerPortalinpackages/ee/src/customer-portals.server.ts,requireEntitlement("CUSTOMER_PORTALS"); the sharedupsertExternalLinkstays ungated (used by quote/RFQ finalize); public share pages degrade viacompanyHasFeature. - ✅ Audit log — engine moved to
packages/ee/src/audit/audit.ts(@carbon/ee/audit.server);enableAuditLogembedsrequireEntitlement("AUDIT_LOG"), skipped underCONTROLLED_ENVIRONMENT(ITAR audit is mandatory).auditConfig/types stay client-safe in@carbon/database(generic schema types consumed by CE packages). - ✅ Backups — engine is Inngest-coupled and CANNOT move to
packages/ee(it imports@carbon/jobs-internal../../../db+ the inngest client). Locked gate-in-place:requireBackupsEntitlement(companyId)(packages/ee/src/backups.server.ts→@carbon/ee/backups.server) is embedded at the top of every START-action durable function —companyExportFunction,companyRestoreFunction,companyImportFunction. Finalize/revert (companyRestore{Finalize,Revert}Function) are deliberately NOT gated: they only RESOLVE an already-started restore, so gating them would strand a pending restore (marker stuckready, snapshot orphaned) if BACKUPS lapsed while it sat pending. Local-dev exempt (IS_LOCAL_DEV— the service-role job path has no email for theisInternalEmailhatch); onboarding demo-template apply/revert callbuildCompanyBackup/wipeAndLoaddirectly and are NOT gated (import exemptsreferencedTemplate).canManageBackupsstays the route-level UX gate. - ✅ Email notifications — the email-channel decision moved to
@carbon/ee/email-notifications.server(emailNotificationsEnabled, DEGRADE);sendEmailtransactional transport stays ungated in@carbon/lib. - ✅ Workflows — the engine moved to
@carbon/ee/workflows(packages/ee/src/workflows/, was the standalone@carbon/workflows). Runtime gate isworkflowsEnabledForCompanyin@carbon/ee/workflows.server(DEGRADE — a non-entitled run settles Skipped, embedded in@carbon/jobsengine/execute.ts); authoring gate isrequireWorkflowsEntitlement(embedded in the ERP'spublishWorkflowVersion). The CE-safe wire contracts (runTriggerSchema/RunTrigger+ the moment contract) live in the leaf@carbon/workflows-coreso@carbon/libneed not depend on the commercial engine — that edge would be alib → ee → libcycle. (The job-side executors inpackages/jobs/src/workflows/stay in jobs — Inngest-coupled, like backups.) - ✅ MCP — protocol engine moved to
packages/ee/src/mcp/(@carbon/ee/mcppure logic;@carbon/ee/mcp.server=server.ts).serveMcpRequestembedsrequireEntitlement("MCP")(route catchesEntitlementError→ 402), replacing the former deletable in-routecompanyHasFeature. The dispatch, tool manifest and generatedtool-metadata.jsonSTAY in the app (derive from~/modules/*) and are INJECTED asdeps. - Note (context): Planning was NOT a gated feature — MRP + scheduling are now the
community
@carbon/planningpackage. - ⬜ Still on
requirePlan/companyHasPlan, pending an architecture/policy decision (integrations, AI agent) — migrate tocompanyHasFeature/requireEntitlement+ move bodies intopackages/eewhen unblocked.
Bundling gotcha — the .server client-graph boundary
The ee feature files import entitlements.server/plan.server (both .server), so
the ee service.ts is transitively server-only. The React Router build rejects any
.server module that reaches the client graph ("Server-only module referenced by
client"). Two edges commonly (and silently — typecheck won't catch it, only the dev
build does) pull the server file into the client:
- The client barrel deriving types from the server file. If
index.ts(@carbon/ee/<feature>) re-exports types fromtypes.ts, andtypes.tsdoesimport type … from "./service"(e.g.ApprovalRule = ReturnType<getApprovalRuleByAmount>), the client barrel transitively reachesservice.ts. Fix: derive those types from@carbon/databasedirectly (Database["public"]["Tables"|"Views"][…]["Row"]), sotypes.tsnever importsservice.ts. - A client file importing a module's
.service.tsor.server.ts. Both are server-only, so they MAY import@carbon/ee/<feature>.server. A component, hook,ui/, models, utils or types file that value-imports one pulls that graph into the client. Fix: move the helper the component needs into<module>.utils.ts. Theno-server-code-in-clientcheck (@carbon/checks) fails the import. (Routes MAY import.server— RR strips it from the client build.)
Anti-patterns
- A gate that is only a
usePlanGateclient check, or only arequireFeature/requirePlancall in an open route file, with the feature body in community code. That is UX, not a lock — deletable without breaching the license. - Reimplementing a commercial engine in community code "to avoid the import." That removes the moat.
- Putting
requireEntitlementin an open (apps/erp) file. It must live inpackages/ee. - Hiding a gated feature from the nav, or redirecting its page away. Gated features stay visible and show the upgrade overlay (rule 3). Hiding it makes the feature undiscoverable and gives the customer nothing to upgrade toward.