{"success":true,"name":"define-shared-vocabulary-once-status-strings-and-enums-must-","description":"The same status/type strings are hand-typed in backend, frontend, and DB code","category":"ai-brimind","path":"ai-brimind/define-shared-vocabulary-once-status-strings-and-enums-must-/SKILL.md","file":"SKILL.md","content":"---\nname: define-shared-vocabulary-once-status-strings-and-enums-must-\ndescription: \"The same status/type strings are hand-typed in backend, frontend, and DB code\"\n---\n\n# Define Shared Vocabulary Once: Status Strings and Enums Must Not Be Retyped Per Layer\n\n## When to use\nValues that multiple layers must agree on — status enums, role names, category codes — are typed as string literals separately in schemas, endpoints, and components, with nothing keeping the copies identical.\n\n## Example request\nBackend saves status 'canceled' (one L), frontend filters for 'cancelled' (two Ls) → the filter silently matches nothing forever; no error, no crash, just an empty list and a mystery. Role 'admin' checked in middleware, 'Admin' rendered in a component's if → one capital letter splits the app's opinion of who is admin; string literals retyped per layer WILL drift, because typing is copying by hand. One constants module (STATUSES.ACTIVE, ROLES.ADMIN) imported by schema enum, route checks, and React components alike → in a Next.js monorepo the layers share the codebase, so sharing the definition costs one import; the typo becomes impossible instead of undetectable. A value used in exactly one file → a local literal is fine; the discipline is for vocabulary CROSSING layers.\n\n## Instructions\nAct as a developer who treats cross-layer string values as a contract written in a language with no compiler — the DB stores 'active', the backend checks 'active', the frontend filters 'active', and nothing anywhere verifies the three spellings match, so a one-letter drift produces the worst kind of bug: no error, no log, just a filter that matches nothing or a permission check that quietly always fails. For any enum-like vocabulary used by more than one layer, do this: (1) Create the single source: one constants module (e.g. lib/constants.js exporting MEMBERSHIP_STATUS = { ACTIVE: 'active', EXPIRED: 'expired', ... } and derived arrays like Object.values(...) for validation lists) — in a Next.js project, frontend and backend share the same codebase, so BOTH sides can literally import the same file; the monorepo is handing you this for free, take it. (2) Make every layer consume the source instead of retyping: the Mongoose schema's enum option takes the derived array (your state-machine discipline plugs in here — the legal states come FROM this module), route handlers and middleware compare against the constants, validation schemas whitelist from the same array, and React components render and filter using the imported values — a grep for the raw string literal should find the constants file and almost nowhere else; stray literals are the smell to hunt. (3) Attach the display layer without polluting the storage layer: human labels and translations ('active' → 'Actif') live in a mapping keyed by the same constants, so the stored value stays a stable machine word while the UI stays free to reword — storage vocabulary and display vocabulary are different jobs, per your normalize-vs-display instincts. (4) When vocabulary changes, you now change one file — but remember the values already sitting in the database: adding a status is additive and free; renaming one is a data migration plus this file, with your blast-radius discipline applied (aggregations and queries hold these strings too). (5) Verify with the drift test: grep each enum value's raw string across the repo — every hit outside the constants module and the migration scripts is a future typo waiting for its moment. Only call the vocabulary managed when both layers provably import their words from the same line of code — two layers that merely happen to agree today are one hurried Friday commit away from disagreeing silently for months.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #239\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}