Sub-entity (child) generator
December 9, 2025 · View on GitHub
For relational database (PostgreSQL + TypeORM)
Use the command below to generate a sub-entity interactively (no JSON schema required):
npm run generate:sub-entity
Prompts:
- Parent: name of the parent entity (required)
- Name: name of the sub-entity (required)
The generator will scaffold the sub-entity across domain, DTOs, service/controller, and persistence (entities, repositories, mappers) following the project’s hexagonal structure.
Using a JSON schema file (Cursor AI prompt template)
If you want to define your sub-entity in advance using a structured schema, you can use Cursor AI to help generate the schema JSON. You can then use this schema to generate the full sub-entity without any interactive prompts.
⚠️ Important: This command can take only one JSON object at a time.
Save the JSON at the following path relative to the project root:
.hygen-entities-generator/<sub-entity-name-kebab-case>.json
Sample file:
.hygen-sample-files/sample-sub-entity-generator.json
Example structure:
{
"parent": "ParentEntityName",
"name": "ChildEntityName",
"functionalities": ["create", "findAll", "findAllWithSearch", "findOne", "update", "delete"],
"fields": [
{
"name": "field_name",
"type": "int | float | double | decimal | boolean | varchar | text | uuid | timestamp | date | json | custom",
"optional": true,
"customType": "CustomTypeName (optional if type is 'custom')",
"example": "example_value",
"dto": true,
"unique": true
}
]
}
Note: You can include either "findAll" or "findAllWithSearch" in the functionalities array. If both are present, findAllWithSearch will be preferred and findAll will be automatically removed.
👇 Prompt Template (for Cursor AI)
Copy and paste the following into Cursor. Replace the placeholders with your SQL CREATE TABLE statement (and parent entity) or a natural language description of your sub-entity and its fields:
Click to expand the prompt
You are helping generate a JSON schema file for a codegen CLI that uses Hygen templates. Follow the instructions precisely and do not add extra explanations or UI formatting. Output a JSON file only in the structure described below.
---
### INPUT
I will provide one of the following:
- A raw SQL `CREATE TABLE` statement for a child entity and its parent name
- A natural language description of the child entity, its parent, and its fields
You will extract the schema and create a JSON object matching the exact structure below. Skip the fields id, created_at, and updated_at as they will be added automatically.
Ensure both `parent` and `name` are PascalCase (capitalize each word, no underscores/spaces). For example, tempuser becomes TempUser, product_order becomes ProductOrder.
Then save the file at the given location and remind me of the correct CLI command to run.
---
### OUTPUT FORMAT
{
"parent": "ParentEntityName",
"name": "ChildEntityName",
"functionalities": ["create", "findAll", "findAllWithSearch", "findOne", "update", "delete"],
"fields": [
{
"name": "field_name",
"type": "int | float | double | decimal | boolean | varchar | text | uuid | timestamp | date | json | custom",
"optional": true,
"customType": "CustomTypeName (optional if type is 'custom')",
"example": "example_value",
"dto": true,
"unique": true
}
]
}
> Notes:
> - `parent`: PascalCase (e.g. `User`)
> - `name`: PascalCase (e.g. `Address`)
> - `functionalities`: Array of strings. You can include either `"findAll"` or `"findAllWithSearch"` (or both, but `findAllWithSearch` will be preferred and `findAll` will be removed automatically)
> - `fields[].name`: snake_case
> - `type`: must be one of the allowed values
> - `optional`: true if nullable or optional
> - `example`: valid example for the field
> - `dto`: true if it should be included in DTOs
> - `unique`: optional boolean, set to `true` to add a unique constraint to the database column
---
### FILE OUTPUT
Once you've built the correct JSON, **save the file to this path relative to the project root**:
.hygen-entities-generator/<sub-entity-name-kebab-case>.json
Example:
.hygen-entities-generator/user-address.json
Samples for reference are available under `.hygen-sample-files/`, e.g. `sample-sub-entity-generator.json`.
---
### FINAL INSTRUCTION
Once the file is saved, tell me:
✅ Schema file generated successfully.
Now run:
DATA_FILE=.hygen-entities-generator/<sub-entity-name-kebab-case>.json npm run generate:sub-entity
---
### NOW GO AHEAD
Here is my input:
[Paste your SQL CREATE TABLE statement or natural language description here]
✅ After generating the file
Once the JSON file is created (e.g. .hygen-entities-generator/user-address.json), run:
DATA_FILE=.hygen-entities-generator/user-address.json npm run generate:sub-entity
This will generate the full sub-entity without further prompts.
Previous: Resource generator
Next: Relationship generator