Skip to content

Generator Commands

Generator commands scaffold new files from FORGE's Tera templates. Each generator creates properly structured, wired-up code — models, migrations, handlers, pages, and components — so you spend less time on boilerplate.

forge make:model

Generate a new model struct with optional associated files. You can define fields inline to generate fully typed migrations, Rust structs, DTOs, and admin forms in one step.

Usage

bash
forge make:model <NAME> [FIELDS...] [OPTIONS]

FIELDS... are optional positional arguments using name:type syntax. See Field Types Reference for all supported types.

Options

OptionTypeDefaultDescription
--migration, -mflagfalseAlso generate a database migration.
--all, -aflagfalseGenerate migration, handler, and admin CRUD pages — the full resource stack.
--translatableflagfalseAdd translation support with a _translations table and Translatable trait implementation.
--interactive, -iflagfalseLaunch an interactive field builder that prompts for each field name and type.

Examples

Model only (no fields):

bash
forge make:model Category

Model with inline fields and migration:

bash
forge make:model Product -m title:string price:decimal is_active:boolean

Full resource stack with fields:

bash
forge make:model Product --all title:string price:decimal status:lookup category:belongs_to

This generates the model, migration (with columns), handler, and admin CRUD pages — all wired with the field definitions you specified.

Translatable model:

bash
forge make:model Article --all --translatable title:string body:text

Interactive field builder:

bash
forge make:model Product --all --interactive

The interactive mode prompts you for each field one at a time:

Interactive field builder (enter empty name to finish)
Available types: string, text, integer, bigint, decimal, boolean,
                 date, datetime, uuid, json, lookup, belongs_to

  Field name (or press Enter to finish): title
  Field type for 'title': string
  ✓ Added: title → string (SQL: VARCHAR(255))

  Field name (or press Enter to finish): price
  Field type for 'price': decimal
  ✓ Added: price → decimal (SQL: DECIMAL(10,2))

  Field name (or press Enter to finish):
Total fields: 2

TIP

--all is the recommended option for new entities. It generates the full stack — model, migration, handler, and admin CRUD pages — in one step, keeping the codebase consistent.


forge make:migration

Generate a new SQL migration file. Like make:model, you can pass inline field definitions to generate a migration with typed columns.

Usage

bash
forge make:migration <NAME> [FIELDS...] [OPTIONS]

Options

OptionTypeDefaultDescription
--createstringGenerate a CREATE TABLE migration for the given table name.
--tablestringGenerate an ALTER TABLE migration for the given table name.

Examples

bash
# Create a new table (no fields — empty migration body)
forge make:migration create_categories_table --create=categories

# Create a table with typed columns
forge make:migration create_products_table title:string price:decimal is_active:boolean

# Add a foreign key column
forge make:migration add_category_to_products category:belongs_to

# Alter an existing table
forge make:migration add_slug_to_products --table=products

Generated files follow the numbered naming convention:

migrations/
  00018_create_categories_table.sql

Field Types Reference

When you pass FIELDS... to make:model or make:migration, each field uses the name:type syntax. FORGE maps each type to the correct SQL column, Rust type, TypeScript type, and admin form component.

Supported Types

TypeSQL ColumnRust TypeTS TypeForm ComponentExample
stringVARCHAR(255)StringstringInputtitle:string
textTEXTStringstringTextareabody:text
integerINTEGERi32numberInput (number)quantity:integer
bigintBIGINTi64numberInput (number)views:bigint
decimalDECIMAL(10,2)BigDecimalnumberInput (number)price:decimal
booleanBOOLEANboolbooleanSwitchis_active:boolean
dateDATENaiveDatestringInput (date)birth_date:date
datetimeTIMESTAMPTZDateTime<Utc>stringInput (datetime)published_at:datetime
uuidUUIDUuidstringInputexternal_id:uuid
jsonJSONBserde_json::ValueRecord<string, unknown>Textareametadata:json
lookupUUID (FK → lookups)UuidstringSelectstatus:lookup
belongs_toUUID (FK → related table)UuidstringSelectuser:belongs_to

Type Aliases

Several aliases are accepted for convenience:

AliasResolves To
str, varcharstring
longtexttext
int, i32integer
big_int, i64bigint
float, double, moneydecimal
boolboolean
timestamp, timestamptzdatetime
jsonbjson
belongsto, relation, fkbelongs_to

Special Types: Lookup and BelongsTo

Lookupstatus:lookup

Creates a foreign key to the lookups table, using the field name as the parent slug. The column becomes status_id and the admin form renders a <Select> populated from the lookup values for the "status" slug.

BelongsTouser:belongs_to

Creates a foreign key to the related model's table (derived from the field name). user:belongs_to produces a user_id column referencing the users table, and the admin form renders a <Select> populated from that table.


forge make:seeder

Generate a new database seeder file.

Usage

bash
forge make:seeder <NAME>

Example

bash
forge make:seeder categories

Creates:

seeders/
  08_categories.sql

forge make:handler

Generate HTTP handler functions for a resource.

Usage

bash
forge make:handler <NAME> [OPTIONS]

Options

OptionTypeDefaultDescription
--apiflagfalseGenerate API-only handlers (no admin panel routes).
--onlystringComma-separated list of actions to generate: index, show, create, update, delete.

Examples

bash
# Full CRUD handler set
forge make:handler Product

# API-only, limited to index and show
forge make:handler Product --api --only=index,show

forge make:middleware

Generate a new Axum middleware.

Usage

bash
forge make:middleware <NAME>

Example

bash
forge make:middleware rate_limit

Creates:

src/middleware/
  rate_limit.rs

The generated file includes the middleware function signature, a request extractor, and a placeholder for your logic.


forge make:page

Generate a Next.js page (or full CRUD page set) for the web or admin app.

Usage

bash
forge make:page <NAME> [OPTIONS]

Options

OptionTypeDefaultDescription
--appstringwebTarget application: web or admin.
--crudflagfalseGenerate a complete CRUD page set: list, create, edit, and view.

Examples

bash
# Single web page
forge make:page about --app=web

# Admin CRUD pages
forge make:page Product --app=admin --crud

When --crud is used with --app=admin, the following pages are created:

admin/app/(dashboard)/products/
  page.tsx          # List view with data table
  create/page.tsx   # Create form
  [id]/page.tsx     # Detail view
  [id]/edit/page.tsx # Edit form

forge make:component

Generate a React component.

Usage

bash
forge make:component <NAME> [OPTIONS]

Options

OptionTypeDefaultDescription
--appstringwebTarget application: web or admin.
--sharedflagfalsePlace the component in a shared directory accessible by both apps.

Examples

bash
# Web-specific component
forge make:component hero-banner --app=web

# Shared component
forge make:component data-table --shared

Complete Workflow Example

The following example demonstrates a typical feature workflow using generators. Starting from a single command with inline fields, FORGE creates every file needed for a fully functional Product resource.

bash
# 1. Generate the full resource stack with fields
forge make:model Product --all --translatable \
  title:string price:decimal sku:string \
  is_active:boolean status:lookup category:belongs_to

This creates:

api/src/models/product.rs          # Model struct with typed fields + Translatable trait
api/src/dto/product.rs             # Request/response DTOs
api/src/handlers/admin/products.rs # Admin CRUD handlers
api/src/services/product.rs        # Business logic service
migrations/00018_create_products_table.sql   # With columns for every field
migrations/00019_create_product_translations_table.sql
seeders/08_products.sql
admin/app/(dashboard)/products/page.tsx          # List page
admin/app/(dashboard)/products/create/page.tsx   # Create form with inputs
admin/app/(dashboard)/products/[id]/edit/page.tsx # Edit form

The migration includes typed columns, foreign keys, and defaults — all derived from the field definitions:

sql
CREATE TABLE products (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    title VARCHAR(255) NOT NULL,
    price DECIMAL(10,2) NOT NULL,
    sku VARCHAR(255) NOT NULL,
    is_active BOOLEAN NOT NULL DEFAULT false,
    status_id UUID REFERENCES lookups(id),
    category_id UUID REFERENCES categories(id),
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
bash
# 2. Run the migration
forge migrate:run
bash
# 3. Seed initial data
forge seed --class products
bash
# 4. Start development
forge serve

TIP

Combine generators with Database Commands and Development Commands to go from idea to running feature in under a minute.


See Also

Released under the MIT License.