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.
Demo template part images — implementation plan
Spec / source: user description, this session. Supersedes the earlier storage-bucket
design in this same file; that approach is dead and must not be revived.
Branch: feat/onboarding-templates
The decision
The 132 part pictures are vector SVGs committed to the repo, one copy, living beside the
dataset data that names them. No Supabase storage, no bucket, no upload script, no
_templates/ storage-permission exception, no build-time copy step. The bundler emits them
into each app's build the same way it emits any other imported asset.
item.thumbnailPath keeps holding a string. For seeded demo items that string is
_templates/<industryId>/<readableId>.svg, and getPrivateUrl resolves that one prefix to
the bundled asset instead of to the storage proxy. Every existing thumbnail call site is
fixed by that single function, and an unknown path resolves to null so the component falls
back to the grey icon it shows today.
Counts: 4 datasets x 33 items = 132. NOTE: the generation prompts that produced the
current artwork were lost from .ai/plans/assets/ and would have to be regenerated to
re-render or extend the set.
Progress
- Task 1: Move the 132 SVGs into the database package and delete the scratch output
- Task 2: Add the
@carbon/database/dataset-assetsentry point - Task 3: Write
thumbnailPathincreateItem - Task 4: Resolve
_templates/paths in both apps'getPrivateUrl - Task 5: Fail soft in both
ItemThumbnailcomponents - Task 6: Update
packages/database/src/datasets/AGENTS.mdand the onboarding rule - Task 7: Full verification
Dependencies
Task 2 needs Task 1. Task 4 needs Task 2. Tasks 3 and 5 are independent of each other and of Task 4. Task 6 needs Tasks 1 to 5. Task 7 is last.
Task 1: Move the 132 SVGs into the database package and delete the scratch output
Depends on: none Files:
- Create:
packages/database/src/datasets/assets/<industryId>/<readableId>.svg(132 files) - Delete:
.ai/plans/assets/svg/(after the move),.ai/plans/assets/images/,.ai/plans/assets/generate-images.mjs
Steps:
- Create the four target directories:
cd /Users/aashu/work/carbon/carbon-feat-onboarding-templates mkdir -p packages/database/src/datasets/assets/{aerospace_satellite,robotics_oem,precision_manufacturing,automotive_precision} - Move only the four industry folders, not
samples/and not.preview/:for d in aerospace_satellite robotics_oem precision_manufacturing automotive_precision; do mv .ai/plans/assets/svg/$d/*.svg packages/database/src/datasets/assets/$d/ done - Delete the scratch output.
images/holds 33 MB of PNGs rendered from these same SVGs andgenerate-images.mjsis a throwaway generator that readsOPENAI_API_KEYout of.env; neither belongs in the repo.rm -rf .ai/plans/assets/svg .ai/plans/assets/images .ai/plans/assets/generate-images.mjs - Confirm no SVG carries a
<script>element or anon*handler. These are committed assets rendered through<img>, where scripts do not execute, but a generated file with script content in it should still not be committed:
If that prints any file path, STOP and report — do not strip it silently.grep -rlE "<script|\bon[a-z]+=" packages/database/src/datasets/assets/ || echo "clean"
Verify:
cd /Users/aashu/work/carbon/carbon-feat-onboarding-templates
find packages/database/src/datasets/assets -name '*.svg' | wc -l
# Expected: 132
ls .ai/plans/assets
# Expected: exactly one entry, demo-template-image-prompts.md
Out of scope: do not touch .ai/plans/assets/demo-template-image-prompts.md; do not
rename any SVG.
Task 2: Add the @carbon/database/dataset-assets entry point
Depends on: Task 1 Files:
- Create:
packages/database/src/datasets/assets.ts - Modify:
packages/database/package.json— add the./dataset-assetsexport and avitedevDependency - Copy from (precedent):
apps/erp/app/modules/agent/agent.kb.ts:20— the existing eagerimport.meta.globusage in this repo
Steps:
- Create
packages/database/src/datasets/assets.ts. AS SHIPPED (the original sample used/// <reference types="vite/client" />andimport.meta.glob<string>; see step 3 for why that was replaced by the inline cast):// Demo-template part artwork, bundled rather than uploaded. See // .ai/plans/2026-08-14-demo-template-part-images.md. // // The cast stands in for `vite/client` types: declaring `ImportMeta.glob` here // collides with the real vite types in the apps, and a `vite` devDependency // resolves a second vite tree against this package's older @types/node. The call // expression stays literal, which is what vite's glob transform matches on. const assets = ( import.meta as unknown as { glob( pattern: string, options: { eager: true; query: string; import: string } ): Record<string, string>; } ).glob("./assets/**/*.svg", { eager: true, query: "?url", import: "default" }); export const TEMPLATE_ASSET_PREFIX = "_templates/"; /** * Resolves `_templates/<industryId>/<readableId>.svg` to the bundled asset URL. * Returns null for any other path, and for a template path with no artwork, so the * caller can fall back instead of requesting a URL that does not exist. */ export function getDatasetAssetUrl(path: string): string | null { if (!path.startsWith(TEMPLATE_ASSET_PREFIX)) return null; const rest = path.slice(TEMPLATE_ASSET_PREFIX.length); if (rest.includes("..")) return null; return assets[`./assets/${rest}`] ?? null; } - In
packages/database/package.json, add toexports:"./dataset-assets": "./src/datasets/assets.ts" - DEVIATION, applied: no
vitedevDependency and no/// <reference types="vite/client" />. Both were tried first.vitein this package resolves against its older@types/nodeand installs a SECOND vite tree, churningpnpm-lock.yamlby ~500 lines; a localdeclare global { interface ImportMeta { glob... } }instead collides with the real vite types inside the apps (TS2300: Duplicate identifier 'glob'inmes). The shipped version castsimport.metainline, leaving theimport.meta.glob(...)call expression itself untouched, which is what vite's compile-time transform matches on. Verified by build, not by reasoning: 129 SVGs emitted as files, the 3 under 4 KB inlined as data URIs by vite's defaultassetsInlineLimit, andpnpm-lock.yamlunchanged.
Verify:
cd /Users/aashu/work/carbon/carbon-feat-onboarding-templates
pnpm exec turbo run typecheck --filter=@carbon/database
# Expected: succeeds, no error mentioning assets.ts or vite/client
SSR safety, verified. path.ts IS a server graph module (loaders and actions import it),
so this module is evaluated during SSR. That is safe because vite treats linked workspace
packages as non-external, so it BUNDLES assets.ts and transforms the glob at build time:
the literal asset map is present in both apps/erp/build/server/index.js and
apps/mes/build/server/index.js, and neither server bundle contains an unresolved
dataset-assets import or a runtime import.meta.glob call. Confirmed by grepping the built
output, not by reasoning. The fragility to know about: this relies on the package staying
non-external. Adding @carbon/database to ssr.external in either app would leave a bare
runtime import of a .ts file and crash the server on boot.
Out of scope: do not import this module from seed-dev.ts, the tiers, or
@carbon/jobs. Those run under plain Node/tsx with no bundler, so the glob is never
transformed and import.meta.glob is undefined at runtime.
Task 3: Write thumbnailPath in createItem
Depends on: none Files:
- Modify:
packages/database/src/datasets/helpers/items.ts— setthumbnailPathon theinsertId(ctx, "item", {...})call
Steps:
- In
createItem, inside theinsertId(ctx, "item", { ... })object, add:thumbnailPath: ctx.dataset.industryId ? `_templates/${ctx.dataset.industryId}/${spec.readableId}.svg` : null,industryIdisstring | nullonDataset(packages/database/src/datasets/types.ts:756); a dev-only dataset with no industry getsnulland keeps today's icon. - Do NOT add a flag to
ItemSpec. A path with no artwork resolves tonullin Task 2 and the component falls back, so an opt-in flag would be a second source of truth for the same fact. - Leave the early-return branch for an already-existing item untouched — it does not insert.
Verify:
cd /Users/aashu/work/carbon/carbon-feat-onboarding-templates
pnpm exec turbo run typecheck --filter=@carbon/database
# Expected: succeeds
grep -n 'thumbnailPath' packages/database/src/datasets/helpers/items.ts
# Expected: one match, inside the insertId call
Out of scope: do not backfill thumbnailPath for already-seeded companies, and do not
add a migration. This only affects newly seeded data.
Task 4: Resolve _templates/ paths in both apps' getPrivateUrl
Depends on: Task 2 Files:
- Modify:
apps/erp/app/utils/path.ts:2203—getPrivateUrl - Modify:
apps/mes/app/utils/path.ts:217—getPrivateUrl
Steps:
- In each file, add at the top of the import block:
import { getDatasetAssetUrl } from "@carbon/database/dataset-assets"; - Replace the body of
getPrivateUrlin each file with:
Doing it here rather than at each call site is deliberate: there are more than a dozen directexport const getPrivateUrl = (path: string) => { // Demo-template artwork ships with the app, so it never goes through the // storage proxy. Anything else is a real tenant file. return getDatasetAssetUrl(path) ?? `/file/preview/private/${path}`; };getPrivateUrl(x.thumbnailPath)callers across quotes, sales orders, purchase orders, supplier quotes, picking lists and kanban cards, and this fixes all of them at once. - Confirm
@carbon/databaseis already a dependency of both apps. It is (apps/erp/package.jsonandapps/mes/package.jsonboth list it), so no package.json change is needed here.
Verify:
cd /Users/aashu/work/carbon/carbon-feat-onboarding-templates
pnpm exec turbo run typecheck --filter=erp --filter=mes
# Expected: both succeed. Note the erp app package is named `erp`, not `@carbon/erp`.
Out of scope: do not change getStoragePath, getRawModelUrl, or the
apps/*/app/routes/file+/preview+/$bucket.$.tsx routes. The storage authorization check
stays exactly as it is; nothing is being widened.
Task 5: Fail soft in both ItemThumbnail components
Depends on: none Files:
- Modify:
apps/erp/app/components/ItemThumbnail.tsx - Modify:
apps/mes/app/components/ItemThumbnail.tsx
Steps:
- In each component, add local state so a failed image load falls back to the existing icon
branch rather than rendering a broken-image glyph:
Importconst [failed, setFailed] = useState(false);useStatefrom"react". - Change the render condition from
thumbnailPath ? (tothumbnailPath && !failed ? (and addonError={() => setFailed(true)}to the<img>. - Reset on a path change so a row reused by a virtualized table does not stay failed:
give the
<img>key={thumbnailPath}and keep the state keyed off it by declaringconst [failedPath, setFailedPath] = useState<string | null>(null);instead of a boolean, settingsetFailedPath(thumbnailPath ?? null)inonError, and testingthumbnailPath && failedPath !== thumbnailPath. Use this variant, not the boolean, in both files. - Keep both components' existing
cvavariants, sizes, icon colours and the MESonClick/cursor-pointerbehaviour exactly as they are.
Verify:
cd /Users/aashu/work/carbon/carbon-feat-onboarding-templates
pnpm exec turbo run typecheck --filter=erp --filter=mes
# Expected: both succeed
Out of scope: apps/erp/app/components/ItemThumnailUpload.tsx (note the misspelling in
the real filename) is the editor, not the display. It already handles a null path with a
"No image" placeholder and picks up the new behaviour through getPrivateUrl for free.
Task 6: Update the docs that describe this
Depends on: Tasks 1 to 5 Files:
- Modify:
packages/database/src/datasets/AGENTS.md - Modify:
.claude/rules/onboarding-company-templates.md
Steps:
- In
packages/database/src/datasets/AGENTS.md, under "Two layers, and the boundary matters", add a row or paragraph forassets/<industryId>/<readableId>.svg: part artwork, one SVG per item, shipped with the app and resolved by@carbon/database/dataset-assets. State that adding an item to a dataset means adding its SVG, and that a missing SVG degrades to the type icon rather than breaking. - In
.claude/rules/onboarding-company-templates.md, add a short section stating that part thumbnails are bundled SVGs keyed onindustryIdandreadableId, thatitem.thumbnailPathholds_templates/<industryId>/<readableId>.svgfor seeded items, and that this path is NOT a storage object. Explicitly note that thecompany-templatesbucket andTEMPLATE_ASSET_PREFIXinpackages/jobs/src/inngest/functions/tasks/company-backup.tsremain dormant and are not part of this path, so a future reader does not connect them. - Do not edit
packages/database/supabase/backups/README.md; its dormancy notes are still accurate.
Verify:
cd /Users/aashu/work/carbon/carbon-feat-onboarding-templates
grep -n "assets/" packages/database/src/datasets/AGENTS.md
# Expected: at least one line describing the assets directory
Out of scope: no changes under docs/ — this is internal, not customer-facing.
Task 7: Full verification
Depends on: Tasks 1 to 6 Files: none
Steps:
- Typecheck every package this touched.
- Run Biome. Per the repo's standing note, fix only error-severity findings and leave the pre-existing warnings alone.
- Run the database and workflows tests.
- Build the ERP to prove the glob resolves and the SVGs are emitted as assets. If the build
fails with the glob left untransformed, or the SSR bundle errors on
import.meta.glob, add"@carbon/database"tossr.noExternalinapps/erp/vite.config.tsandapps/mes/vite.config.tsand rebuild. If it still fails, STOP and report — do not improvise a different asset strategy. - Browser check, which needs the user's local stack running and a demo company seeded. Do not rebuild or reseed the database without asking. Confirm the parts list, an item detail page, a job, a quote line and a kanban card all show artwork in both light and dark mode, in the ERP and in MES.
Verify:
cd /Users/aashu/work/carbon/carbon-feat-onboarding-templates
pnpm exec turbo run typecheck --filter=@carbon/database --filter=@carbon/workflows --filter=@carbon/jobs --filter=erp --filter=mes
pnpm exec biome check
pnpm --filter @carbon/workflows exec vitest run src/seed-workflows.test.ts
pnpm exec turbo run build --filter=erp
pnpm exec turbo run build --filter=mes
Evidence, as run:
- typecheck, all five packages:
Tasks: 5 successful, 5 total. pnpm exec biome check:Found 399 warnings, zero errors. All 399 are pre-existing (lint/suspicious/noConsolein the dev seed CLI and similar). One error DID appear and was fixed: an external formatter had added trailing commas throughoutpackages/database/src/datasets/helpers/items.ts, failing the repo format check;biome check --writeon that one file restored repo style.pnpm --filter @carbon/workflows exec vitest run src/seed-workflows.test.ts:Tests 30 passed (30).- ERP build: succeeded, 129 SVGs emitted to
apps/erp/build/client/assets/. - MES build: succeeded, 129 SVGs emitted to
apps/mes/build/client/assets/. - The 132 minus 129 gap is not a failure:
MCH-END-CAP.svg,SEAL-ORING-224.svgandHW-DOWEL-8.svgare each under 4 KB, so vite's defaultassetsInlineLimitinlined them into the lookup table as data URIs. All 132 resolve. - Client-side cost, measured on
apps/erp/build/client/assets/path-DymyPk0E.js: the glob map is 23.3 KB raw / ~5.0 KB gzipped, of which 13.1 KB is those 3 inlined SVGs. The other 1.8 MB of artwork is fetched per-image on demand, never on page load. - SSR: the transformed asset map is present in both apps'
build/server/index.js(see Task 2).
There is no @carbon/database test suite — the package has no test script and no
*.test.ts files, so "run the database tests" is not a real step. The seed path's coverage is
@carbon/workflows' seed-workflows.test.ts, which is what ran above.
NOT DONE — browser check. Step 5 was never performed. It needs the user's local stack running and a demo company seeded, and the repo rule forbids reseeding without asking. So artwork has been proven to build, bundle and resolve, but has NOT been seen rendering in the ERP or MES, in either light or dark mode. Treat that as open.
Out of scope: do not commit. Report and wait for an explicit instruction.