pattern-stack/codegen-patterns/codegen

Claude Code and agent skill by pattern-stack/codegen-patterns

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Load when working in a project that uses @pattern-stack/codegen to scaffold a NestJS + Drizzle backend from YAML — i.e. when the request is to add or change an entity / module / CRUD resource, generate code from `entities/*.yaml`, run the `codegen` (aka `cdp`) CLI, install or wire an infrastructure subsystem, or refresh the project after a package upgrade. This is the entry-point router; it points at the focused `entities`, `subsystems`, `jobs`, `events`, `bridge`, and `integration` skills for…

Install

npx vskill@latest install pattern-stack/codegen-patterns/codegen

SKILL.md

The same SKILL.md was published earlier as pattern-stack/codegen-patterns/codegen.

Using @pattern-stack/codegen in this project

This project generates its backend (domain entities, repositories, services, controllers, DTOs, use cases, Drizzle schemas, NestJS modules) from YAML entity definitions — one NestJS module folder per entity. You author small YAML files and run the codegen CLI; the generator owns a few directories and never touches the rest of your app.

The CLI binary is codegen (alias cdp). Every noun supports --json for machine-readable output and --cwd <path> to target another project root.

Mental model

  • You own: entities/*.yaml, events/*.yaml, app.module.ts, main.ts,

database.module.ts, codegen.config.yaml, and your hand-written use cases / adapters.

  • Codegen owns (don't hand-edit — regenerated every run):
  • src/generated/modules.ts — the GENERATED_MODULES barrel
  • src/generated/schema.ts — the Drizzle schema barrel
  • src/generated/app-config.ts — the config values your app reads at boot
  • the per-entity module tree (src/modules/<plural>/…)

If one of the generated barrels (including subsystems.ts / subsystems-schema.ts) cannot be written, the command exits 1 and names the file — fix that (a permission, a directory in the way) and re-run. Files that run already wrote (the entity module tree) stay; re-running converges.

  • Where the runtime comes from depends on runtime: in

codegen.config.yaml (ADR-037):

  • package (the default) — generated code imports the runtime straight from

@pattern-stack/codegen/subsystems and @pattern-stack/codegen/runtime/*. Nothing is vendored. Project-specific generated code, such as the typed event bus (TypedEventBus), comes from <paths.generated> (e.g. src/generated/events/bus), never from the package.

  • vendored — the package copies its runtime (base classes, types, the

DRIZZLE token, the Zod pipe, the OpenAPI registry) into src/shared/** and installed subsystems into <subsystems-root>/<name>/, imported via @shared/*. Treat those copies as generated output: don't hand-edit; subclass instead. codegen update refreshes them after a package bump.

Check which mode this project uses before writing an import. Don't flip modes by accident.

The generation pipeline: YAML → parse → analyze → templates → code. After any generation run the two barrels are rewritten and you wire them into app.module.ts exactly once — codegen never edits that file again. Installed subsystems get their own pair: src/generated/subsystems.ts (SUBSYSTEM_MODULES) and src/generated/subsystems-schema.ts. Wire each of those once as well.

Authentication (ADR-043, 0.30.0+)

The generated data plane is closed by default:

  • AuthModule.forRoot binds AuthenticatedGuard globally. Any route not

marked @Public() returns 401 when the request has no authenticated requester.

  • main.ts calls installRequesterContext(app) and refuses to start when

no IUserContext is bound under AUTH_USER_CONTEXT. auth.devAllowAnonymous: true in codegen.config.yaml bypasses this — after you regenerate (see below). It is for localhost only; never ship it.

  • Generated controllers do not read x-user-id / x-tenant-id headers.

Use cases get the actor from the request context (tryGetRequester()). Don't add header-sourced identity back.

  • To keep an entity internal (no REST/Electric/tRPC routes) while still

generating its service and use cases, set api: false (or api: { enabled: false }) at the top level of its YAML. The entity's module barrel then exports the module, service and types, but no controller.

Upgrading from before 0.30.0: after bumping the package, run codegen project update, then codegen project upgrade-auth. The latter is idempotent: it wires AuthModule plus the boot check into app.module.ts and main.ts. Then bind your own IUserContext, backed by your session or JWT scheme.

Routing — load the focused skill for deep work

TaskRead
Model a new app, feature or concept before any YAML: entities, parts, references, contextsthe modelling skill
Author / change an entity YAML (fields, families, queries, EAV, relationships)the entities skill
Install or wire an infrastructure subsystem; get the forRoot registration order rightthe subsystems skill
Write a background job (defineJob / jobFactory), configure pools, orderingthe jobs skill
Author a domain event, publish via the outbox, use the typed event busthe events skill
React to an event with a durable async job (the event-to-job bridge)the bridge skill
Pull/push data from an external system (IChangeSource / IIntegrationSink)the integration skill

Frontend generation (generate.frontend: true)

When on, entity new (and --all) ends with a whole-set frontend emitter (ADR-038): the complete data layer is rendered into locations.frontendGenerated (default apps/frontend/src/generated/) from the full entity set — REST api client, TanStack DB collections (per-entity sync: api | electric), createEntityHooks wiring, field metadata (<camel>Metadata carries the entity's context / surface, string | null), a plural-keyed createStore, config.ts, query-client.ts, root barrel. Every file is a complete write with a @generated banner; re-runs are byte-identical.

Non-obvious bits:

  • The dbEntities contract: generated files import the plain <Class> type

AND a <camel>Schema Zod schema from locations.dbEntities per entity. If the backend doesn't emit such a package (backend doesn't), the consumer provides a shim barrel re-exporting each module's Output DTO.

  • The consumer mounts two providers in the app root, both from generated

code: QueryClientProvider(queryClient) ▸ EntityStoreProvider(store) (EntityStoreProvider from @pattern-stack/frontend-patterns).

  • Version pairing: the emitted imports require

@pattern-stack/frontend-patterns + four TanStack packages — the exact ranges are listed in the generated index.ts header comment.

  • Path aliases are assumed: default imports use @/… (and your

locations.*.import values) — wire tsconfig paths + the bundler alias.

  • Providers catalog: when definitions/providers/ exists, the emitter also

renders providers.ts — PROVIDERS (flat) + PROVIDER_CATALOG (grouped by each provider's display.category into frontend.catalog.categories). Providers are gen-time knowledge: the catalog is emitted, never queried, and never hand-duplicated in the frontend. status: planned provider YAMLs are roadmap stubs — catalog tile only, no auth/client needed, skipped by all backend emission.

CLI quick reference

bash
# Project lifecycle
codegen init # scaffold this project's shared layer + config + skills
codegen project scan # detect framework/ORM/architecture → propose config
codegen project config # print the resolved codegen.config.yaml
codegen update # re-sync vendored runtime + subsystems + skills after a package bump
codegen project upgrade-auth # wire the ADR-043 auth guard + boot check (idempotent)
# Entities
codegen entity new entities/<file>.yaml # generate one entity
codegen entity new --all # regenerate every entity in entities/
codegen entity new --all --dry-run # preview
codegen entity list # tabular list
codegen entity validate --strict # validate YAML + cross-refs (warnings fail)
codegen relationship new --all # relationships/*.yaml — junction tables
codegen junction new --all # junctions/*.yaml — first-class M:N with role/temporal metadata
# Subsystems (see the `subsystems` skill for wiring + order)
codegen subsystem # summary: installed vs available
codegen subsystem install <name> # vendor a subsystem's runtime + inject its config block
codegen subsystem list
codegen subsystem remove <name>
# Skills
codegen skills install # (re)vendor these consumer skills into .claude/skills
codegen skills list

Junctions need their own command. entity new --all renders each parent's junction fan-out (attach… / …List on the parent service), but it does not write the junction modules themselves (entity, repository, service, module; between: [deal, contact] lands in <modules_dir>/deal-contacts/). Run codegen junction new --all as well, in either order. It writes the junction modules, re-renders both parents and regenerates the barrels and relations manifest, so the two commands together are idempotent. Each refuses to run over uncommitted generated output without --force, and the first command's output is exactly that, so a regenerate script passes --force to both:

bash
codegen entity new --all --force && codegen junction new --all --force

Non-obvious rules

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/pattern-stack/codegen-patterns/codegen/badge)](https://verified-skill.com/skills/pattern-stack/codegen-patterns/codegen)

Something wrong with this skill or its page? Tell us.