generate_resource
Generates a complete CRUD module for any resource with REST endpoints, service layer, database operations, Zod validation, auto-registered routes, and tests. Supports relations and interactive field prompts.
Instructions
Generates a full CRUD module for a resource — controller with 5 REST endpoints (GET /:id, GET /, POST, PATCH /:id, DELETE /:id), service layer with business logic, repository with database operations, Zod validation schemas, TypeScript interfaces, route definitions auto-registered in the Express app with Swagger/OpenAPI docs, and a test file. If fields are not provided, the CLI will prompt interactively (use non-interactive mode by passing fields directly). Relations create foreign key columns in the database and populate the Prisma/Drizzle/Mongoose schema with the correct association types (belongsTo for singular, hasMany for plural relation names). Run add_plugin first if you need auth protection on the generated endpoints.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Resource name in PascalCase, 2+ characters, must start with an uppercase letter. Examples: 'Product', 'OrderItem', 'MedicalRecord'. This becomes the module directory name, database table name, and all class/file names. | |
| fields | No | Comma-separated field definitions in "name:type" format. Supported types: string, number, boolean, date. Examples: "name:string,price:number,isActive:boolean" or "email:string,age:number". Can be omitted for interactive mode. | |
| relations | No | Comma-separated relation definitions in "name:RelatedResource" format. Singular names (e.g., "doctor:Doctor") create a belongsTo foreign key. Plural names (e.g., "patients:Patient") create a hasMany inverse. Examples: "doctor:Doctor,patient:Patient" or "category:Category". The related resource must already exist. | |
| dir | No | Absolute or relative path to the BackGen-generated project directory where the resource module will be created. Defaults to current working directory. Example: '/home/user/projects/my-api'. |