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/User.model.ts
model_test - Generate Test File
Generate a test file for a Model.src/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
Customization
Adding Model Methods
Add business logic to generated Models:Extending Tests
Add more test cases:Batch Generation for Multiple Entities
Using Scripts
Batch Test Generation
Practical Tips
1. Complete Entity First
2. Incremental Extension
3. Follow Conventions
4. Git Management
Troubleshooting
Regenerating Model
Problem: Want to regenerate Model Solution:Syncing After Entity Change
Problem: Update Model after Entity change Solution:Next Steps
Model
Learn more about Model classes
Testing
Write tests