/bett3r-pv3-ai-skills:create-schemafrom bett3r-pv3-ai-skills
Scaffold schemas, types, and events for a new DDD domain using @bett3r-dev/jsonschema-definer. Use when defining the schema layer for a new module.
Ships in bett3r-pv3-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Scaffold type definitions, event schemas, and aggregate schemas for a PV3 DDD module.
Read ddd-patterns → SCHEMAS.md before writing the files — the jsonschema-definer conventions, the two-file domain split, the event factory shape, and (load-bearing on any existing module) why renaming or removing a persisted field is schema evolution, not a rename.
The scaffolder cannot help here, and that is structural. An BLUEPRINT node carries a label, a
subdomain and a resource key — it has no fields. So every schema is hand-written, and a
scaffolded artifact carries a placeholder schema until you write the real one: <Name>CommandSchema
for a generated command fragment, <Name>EventSchema for a generated event fragment,
<Name>ReadmodelSchema for a generated read model. The scaffold emits each as S.shape({}) (a read
model gets id and accountId), marked TODO(scaffold) and listed in STILL OWED, so the commit
builds. Those names are the contract. Finishing one depends on where the placeholder sits:
TODO(scaffold) marker.TODO(scaffold) marker; there is no import to switch. If its anchor says INFERRED, confirm
the module first. The fragment's target is a guess in one of two ways: the events file's sibling
name, when the events file imports no .types module, or the domain package directory, when the
subdomain has no events file in the graph at all and so no types module to name.Run this skill straight after scaffold-from-design; it is
the first item in every generated file's STILL OWED block.
When the scaffold already wrote the placeholder schemas (the prose above), skip generating the files and the exports. Keep every export name, label-derived name and subdomain it
wrote: they are the contract the command, event or read model imports them by. Each fragment stays in the types module its command or event imports. Work only the TODO(scaffold) markers and
the file's STILL OWED block, and delete each marker as you satisfy it. Finish each placeholder as the two bullets above say: replaced in place for a companion fragment, rewritten in the domain package for an inline one. The rest of this
skill still governs the content you write and the Final Checklist.
This skill resolves the following placeholders from your repo's .blueprint.config.json:
| Placeholder | .blueprint.config.json field | Example value |
|---|---|---|
<domainEventsPath> | domainEventsPath | src/packages/shared/teselly-domain |
<domainEventsPackageName> | domainEventsPackageName | @bett3r-dev/teselly-domain |
<serverPath> | serverPath | src/services/server |
The framework packages @bett3r-dev/pv3-types, @bett3r-dev/jsonschema-definer, and the
ports module are PV3 framework — identical in every PV3 repo — and appear verbatim below.
Use @bett3r-dev/jsonschema-definer (imported as S):
import S, { omitFromSchema } from '@bett3r-dev/jsonschema-definer';
NOT Zod. This project uses jsonschema-definer exclusively.
<domainEventsPath>/src/<domain>/<domain>.types.tsimport S, { omitFromSchema } from '@bett3r-dev/jsonschema-definer';
// Value Objects (reusable shapes)
export const AddressSchema = S.shape({
line1: S.string().optional(),
city: S.string().optional(),
state: S.string().optional(),
country: S.string().optional(),
postalCode: S.string().optional()
});
export type AddressType = typeof AddressSchema.type;
// Event Schemas
export const MyEntityCreatedEventSchema = S.shape({
name: S.string(),
status: S.string(),
count: S.number().minimum( 0 ),
address: AddressSchema.optional(),
tags: S.array().items( S.string() ).optional()
});
export const MyEntityEditedEventSchema = MyEntityCreatedEventSchema.partial();
export const MyEntityStatusChangedEventSchema = S.shape({
status: S.string(),
previousStatus: S.string().optional()
});
<domainEventsPath>/src/<domain>/<domain>-integration.types.tsContains aggregate state schemas, command schemas, and readmodel schemas — everything the server modules and client library need beyond events.
import S, { mergeSchemas, omitFromSchema } from '@bett3r-dev/jsonschema-definer';
import {
MyEntityCreatedEventSchema,
MyEntityEditedEventSchema
} from './<domain>.types';
//*******************************************
// MyEntity Aggregate
//*******************************************
export const MyEntityAggregateSchema = S.shape({
accountId: S.string(),
name: S.string(),
status: S.string(),
count: S.number().minimum( 0 )
});
export const CreateMyEntityCommandSchema = MyEntityCreatedEventSchema;
export const EditMyEntityCommandSchema = MyEntityEditedEventSchema;
//*******************************************
// MyEntity Readmodel
//*******************************************
export const MyEntityReadmodelSchema = mergeSchemas( MyEntityCreatedEventSchema, S.shape({
id: S.string(),
accountId: S.string()
}));
export type MyEntityReadmodelType = typeof MyEntityReadmodelSchema.type;
Key conventions:
<domain>.types.ts (which holds event schemas and value objects)export const XCommandSchema = XEventSchema;mergeSchemas() to compose from event schemas + extra fields (id, accountId)//*****...) to visually separate aggregates, commands, and readmodels<domainEventsPath>/src/<domain>/<entity>.events.tsimport { Event } from '@bett3r-dev/pv3-types';
import {
MyEntityCreatedEventSchema,
MyEntityEditedEventSchema,
MyEntityStatusChangedEventSchema
} from './<domain>.types';
export const MyEntityCreated = () => Event({
schema: MyEntityCreatedEventSchema,
friendlyName: {
es: 'Entidad fue creada',
en: 'Entity was created',
pt: 'Entidade foi criada'
}
});
export const MyEntityEdited = () => Event({
schema: MyEntityEditedEventSchema,
friendlyName: {
es: 'Entidad fue editada',
en: 'Entity was edited',
pt: 'Entidade foi editada'
}
});
export const MyEntityStatusChanged = () => Event({
schema: MyEntityStatusChangedEventSchema,
friendlyName: {
es: 'Estado de la entidad fue cambiado',
en: 'Entity status was changed',
pt: 'Estado da entidade foi alterado'
}
});
<domainEventsPath>/src/<domain>/index.tsimport * as MyEntityEvents from './<entity>.events';
export { MyEntityEvents };
export * from './<domain>.types';
export * from './<domain>-integration.types';
omitFromSchema( Schema, ['field'] ) — NOT .omit()Schema.partial() for edit/update event schemasS.shape({}) for object schemas — NOT z.object({})typeof Schema.type — NOT z.infer<typeof Schema>OrderPlaced, EntityCreated, StatusChangedSalesOrderPlaced not just OrderPlacedexport const MyEvent = () => Event({...})| Type | Method |
|---|---|
| String | S.string() |
| Number | S.number() |
| Boolean | S.boolean() |
| Array | S.array().items( S.string() ) |
| Object | S.shape({...}) |
| Map / Record | S.array().items( S.shape({ key, value }) ) — jsonschema-definer has no S.record() |
| Optional | .optional() |
| Enum | S.string().enum(['a', 'b']) |
| UUID | S.string().format( 'uuid' ) |
S.string().format( 'email' ) | |
| Date (ISO-8601) | S.string().format( 'date' ) — required when the field is compared lexicographically (e.g. monotonicity invariants) |
| DateTime | S.string().format( 'date-time' ) |
| Min/Max | S.number().minimum( 0 ).maximum( 100 ) |
| Partial | Schema.partial() |
| Additional props | S.shape({}).additionalProperties( true ) |
| Freeform JSON | new BaseSchema<any>() (import from @bett3r-dev/jsonschema-definer) |
IMPORTANT: Never use S.any(). It bypasses all validation and is never appropriate. For fields that accept arbitrary JSON objects, use new BaseSchema<any>() instead. If types don't match, fix the schema — don't escape with S.any().
Map / Record indexing caveat: the { key, value }[] array-map is the only way to model Record<string, T>, but the database layer cannot index a field nested inside it — only flat, top-level fields are indexable. A parent readmodel that holds children as a nested array-map therefore cannot serve an indexed query that filters on a child field. When a policy or query must scan or filter a subset of those children, project a separate flat readmodel keyed by the child entity, carrying the filter fields at top level, and drive the scan from there (e.g. a contractId-keyed flat readmodel with a compound status + termEnd index alongside the nested parent, so a renewal/recurring-run policy gets an indexed scan instead of a full table load).
If a module has multiple aggregates/entities, use separate event files:
<domainEventsPath>/src/my-domain/
my-domain.types.ts # All schemas for the domain
entityA.events.ts # Events for entity A
entityB.events.ts # Events for entity B
index.ts # Barrel exports all
Events MUST have friendlyName with at least es, en, pt translations.
Events without user-visible names (internal/system events) can omit friendlyName.
<domainEventsPath>/src/ in your repo for a working reference of types (<domain>.types.ts) and events (<domain>.events.ts).<domainEventsPath>/src/<domain>/
<domain>.types.ts # Event schemas, value objects
<domain>-integration.types.ts # Aggregate, command, readmodel schemas
<entity>.events.ts # Event factory functions
index.ts # Barrel exports all
S from @bett3r-dev/jsonschema-definertypeof Schema.typeomitFromSchema() used (not .omit())() => Event({...})friendlyName with es/en/pt<domainEventsPackageName>index.ts exports both .types and -integration.typesid fieldS.any() usage — use new BaseSchema<any>() for freeform JSON fieldsWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub bett3r-dev/bett3r-ai-workflow --plugin bett3r-pv3-ai-skills11 skills in this plugin
/create-aggregateSkill: Create AggregateScaffold a new event-sourced aggregate with PV3 AggregateBuilder pattern. Use when adding a new aggregate to handle commands and emit events./create-integration-testSkill: Create Integration TestScaffold a full-pipeline in-process integration test suite for a server module using createIntegrationHarness. Use when you want to exercise the real command → aggregate → eventstore → outbox → readmodel pipeline for a subdomain (choreography, policies, gateway callbacks), not mocked unit tests./create-moduleSkill: Create ModuleOrchestrate complete DDD module creation including schemas, aggregate, policies, read models, and tests. Use when scaffolding a new bounded context or feature module./create-policySkill: Create PolicyScaffold an event-driven policy that reacts to events and triggers commands. Use when adding event reactions or sagas./create-readmodelSkill: Create ReadmodelScaffold an event-driven read model (projection) for querying. Use when adding query-side projections from events./create-testsSkill: Create TestsGenerate tests using Given/When/Then pattern for PV3 DDD components. Use when adding tests for aggregates, policies, and readmodels.