frgen
v0.4.2
Published
helper generator
Maintainers
Readme
🧰 FRGEN and Regen — CLI CRUD Generator
Backend
frgen is a Command Line Tool that automatically generates boilerplate files such as models, controllers, services, validations, and resources based on your database table structure.
📦 Installation
npm install frgen --save-dev⚙️ General Options
| Option | Description | Example |
|--------|--------------|----------|
| --table=<table_name> | The table name used as the generation base | --table=users |
| --schema=<schema_name> | (Optional) Database schema, default public | --schema=my_schema |
| --path=<output_folder> | (Optional) Output file path | --path=modules/user |
| --prisma | Use Prisma ORM | --prisma |
| --pg | Use PostgreSQL client | --pg |
| --mysql | Use MySQL client | --mysql |
🧩 Available Actions
1. make:model
Generates a model file based on the database table structure.
npx frgen make:model --table=users --schema=publicProcess:
- Reads the table structure from the database
- Generates a PascalCase model name
- Saves it in the default path or the specified
--path
2. make:resource
Generates a resource file (usually a DTO or response mapper).
npx frgen make:resource --table=products3. make:controller
Generates a complete set of files including:
- Controller
- Service
- Validation
- Resource
npx frgen make:controller --table=users --path=modules/usersSteps performed:
generateController()generateService()generateValidation()generateContent()
4. make:crud
Generates a full CRUD structure at once, including:
- Model
- Controller
- Service
- Validation
- Resource
npx frgen make:crud --pg --schema=publicUse this to generate the full CRUD boilerplate automatically.
5. make:validation
Generates an automatic validation file based on table structure.
npx frgen make:validation --table=orders6. make:service
Generates a service layer file for business logic.
npx frgen make:service --table=users --path=modules/users🧠 Internal Explanation
Key Variables
| Variable | Description |
|-----------|--------------|
| action | Main command (make:model, make:crud, etc.) |
| tableName | Target table name |
| _path | Output path for generated files |
| schema | Database schema (default: public) |
| client | Database client (pg or mysql) |
| prisma | Boolean, whether Prisma ORM is used |
| pool | Active database connection |
Execution Flow of frgen
- Parse CLI arguments
- Set
DB_CLIENTaccording to the option (pgormysql) - Create a database connection using
db.createPool() - Check database connectivity with
checkDatabaseConnection() - Execute action based on the command:
make:model→generateModelContent()make:controller→generateController(),generateService(), etc.make:crud→generateAll()
- Close the database connection (
pool.end()/pool.releaseConnection())
💡 Full Examples
PostgreSQL
npx frgen make:controller --table=users --schema=public --pg --path=modules/usersMySQL
npx frgen make:crud --mysql --path=modules/userWith Prisma
npx frgen make:service --table=products --path=modules/products --prisma🧱 Internal Dependencies
| File | Description |
|------|--------------|
| ./db.js | Database connection utility |
| ./utils.js | Utility functions: checkDatabaseConnection, removePluralSuffix, toPascalCase |
| ./make:model.js | Model generator |
| ./make:controller.js | Controller generator |
| ./make:service.js | Service generator |
| ./make:validation.js | Validation generator |
| ./make:resource.js | Resource generator |
| ./make:crud.js | Full CRUD generator |
🧨 Error Handling
| Error Message | Cause |
|----------------|--------|
| ❌ action undefined. | No command provided |
| ❌ table undefined. | Table name missing |
| ❌ ERROR: | Internal error (e.g. DB connection failure) |
regen CLI Tool
Frontend
regen is a Node.js-based code generator designed to create pages, forms, routes, services, validation schemas (Zod), dummy data, and TypeScript definitions based on a JSON Schema file. It supports customizable templates and MUI components.
Converting Prisma Schema to JSON Schema
If you are working with Prisma, you can automatically convert your Prisma schema into a JSON Schema using the following package:
🔗 https://www.npmjs.com/package/prisma-json-schema-generator
Steps
1. Install the generator
npm install -D prisma-json-schema-generator2. Add the generator configuration to your schema.prisma
generator jsonSchema {
provider = "prisma-json-schema-generator"
includeRequiredFields = "true"
}This setup enables Prisma to generate a well-structured JSON Schema based on your models.
You can then use the generated schema with the regen CLI to automate creation of pages, forms, services, validations, and more.
📦 Installation
You can run it directly using npx:
npx regen <action> [options]🚀 Usage
Basic Command Format
npx regen <action> [options]🛠 Available Actions
1. make:page
Generates all pages and services for every definition inside json-schema.json.
This includes:
- Service file
- Validation file
- Form component
- Index page
- Create page
- Update page
- View page
- Dummy data
- TypeScript definitions
npx regen make:page2. make:dummy
Generates only dummy data based on schema.
npx regen make:dummy3. make:route
Generates route file for all schema definitions.
npx regen make:route4. make:validation
Generates validation files only.
npx regen make:validation5. make:form
Generates form components only.
npx regen make:form6. --help
Shows help message.
npx regen --help⚙ Options
--file=<path>
Specify JSON schema file.
Default: ./json-schema.json
npx regen make:page --file=./schema/user.json--mui
Use MUI templates (default).
npx regen make:page --muiCustom Template Options
| Option | Description |
|--------|-------------|
| --index-template=<path> | Custom index page template |
| --form-template=<path> | Custom form template |
| --view-template=<path> | Custom view template |
| --create-template=<path> | Custom create page template |
| --update-template=<path> | Custom update page template |
| --template=<dir> | Directory containing all templates |
Example:
npx regen make:page --template=./custom-templatesThis expects:
custom-templates/
index-template.js
form-template.js
view-template.js
create-template.js
update-template.js--ignore=<templates>
Comma-separated list of templates to skip.
Options:
- create
- update
- view
- form
- index
- service
- validation
- dummy
Example:
npx regen make:page --ignore=form,view📂 JSON Schema Requirements
Your json-schema.json must have:
{
"definitions": {
"User": {
"properties": { ... },
"required": [ ... ]
}
}
}Each key inside definitions is treated as a module to generate.
🛑 Error Handling
Errors will be shown as:
❌ ERROR: <message>🧾 License
This script is internal & open for customization, and can be modified freely for project needs.
