Skip to main content
In the Scaffolding tab, you can auto-generate Model and test code based on Entities. It provides the CLI pnpm scaffold command through a visual interface.

Scaffolding Tab Structure

Scaffolding Selection
Scaffolding Options
Scaffolding Generation Result
Scaffolding Complete
The Scaffolding tab consists of two main areas:
  • Left Sidebar: Entity list and selection checkboxes
  • Right Content: Code generation options (Model Class, Model Test, View)

Available Code Types

View component generation is currently under development. You can generate React components through other Sonamu UI features.

Generating Model Class

1. Select Entity

Select the Entity to generate a Model for from the left Entity list. Single selection:
Multiple selection:

2. Select Generation Option

Check the ☑ Model Class checkbox.

3. Run Generate

Click the [Generate] button to create the following file:

Generated Code

src/application/user/user.model.ts
Auto-generated features:
  • ✅ TypeScript type definitions
  • ✅ Entity connection
  • ✅ BaseModel inheritance
  • ✅ Basic CRUD methods

Generating Model Test

1. Select Entity

Select Entity same as for Model.

2. Select Generation Option

Check the ☑ Model Test checkbox.
Generate Model and Test together: You can select both Model Class and Model Test to generate them at once.

3. Run Generate

Click the [Generate] button to create the following file:

Generated Code

src/application/user/user.model.test.ts
The generated test starts as describe.skip. Remove .skip once you have written real assertions.
What is generated:
  • ✅ A bootstrap(vi) call (Sonamu init + per-test transaction wrapping)
  • ✅ An empty describe.skip block — you write the actual cases

Batch Generation

Generate for All Entities

  1. Click [Select All] button
  2. Select generation options
  3. Click [Generate]
Result:

Select Specific Entities Only

For all Entities during initial project setup:
For new Entity only when adding:

Checking Generation Results

Success Message

File Conflict

When trying to generate files that already exist, a confirmation modal appears:
Options:
  • Cancel: Cancel generation
  • Backup & Overwrite: Backup existing files as .bak then overwrite
  • Overwrite: Overwrite directly (caution!)
Code loss caution: Overwriting existing files may delete your business logic. Backup or avoid overwriting customized Models.

View Generation

The TemplateKey list on the Scaffolding tab includes View templates in addition to the Model ones.
The same templates are available from the CLI: pnpm scaffold view_list, pnpm scaffold view_form.

Post-Generation Workflow

1. Add Model Methods

Add business logic to the generated Model:
src/application/user/user.model.ts

2. Add Tests

Add more tests to the generated test file:
src/application/user/user.model.test.ts

3. Add API

Add API endpoints using the @api decorator on the Model:

Practical Tips

1. Initial Project Setup

2. Adding New Entity

3. When Regeneration is Needed

When Entity structure changes significantly and Model needs regeneration:

Next Steps

Model

Learn more about Model classes

scaffold CLI

Generate code via CLI