pnpm scaffold command auto-generates boilerplate code based on Entity definitions. It generates Model classes and test files in seconds, significantly reducing development time.
Basic Concept
Scaffold is an automation tool that converts Entities to code:- Entity-based: Understand types and structure from Entity definitions
- Type-safe: TypeScript types are auto-generated
- Consistent: All code follows the same pattern
- Customizable: Freely customize after generation
Commands
model - Generate Model Class
Generate a Model class for an Entity.src/models/TS
User.model.ts - User Model classsrc/models/User.model.ts
model_test - Generate Test File
Generate a test file for a Model.src/models/TS
User.model.test.ts - User Model testssrc/models/User.model.test.ts
View Scaffolding (In Development)
View component auto-generation is currently in development.
You can generate React components through Sonamu UI.
Generated Code Structure
Model Class
Generated Model classes have the following structure:- ✅ TypeScript types
- ✅ Entity connection
- ✅ BaseModel inheritance
- ✅ Basic CRUD methods
- Business logic methods
- Complex queries
- Data validation
- Relation loading
Test File
Generated test files include basic tests:- Add business logic tests
- Edge case tests
- Performance tests
- Integration tests
Development Workflow
1. Define Entity
src/entities/Product.entity.ts
2. Migration
3. Generate Model
4. Add Business Logic
src/models/Product.model.ts
5. Generate Tests
6. Write Tests
src/models/Product.model.test.ts
7. Add API
src/models/Product.model.ts