Scaffold Generator
The Scaffold Generator creates a complete set of files for a resource, including models, endpoints, contracts, pages, and templates. This is the most comprehensive generator for creating full CRUD functionality.
Usage
azu generate scaffold RESOURCE_NAME [OPTIONS]Description
The scaffold generator creates a complete set of files needed for a full-featured resource with CRUD (Create, Read, Update, Delete) operations. It generates models, endpoints, contracts, pages, templates, and tests all at once, providing a solid foundation for building resource-based features.
Options
RESOURCE_NAME- Name of the resource to scaffold (required)-d, --description DESCRIPTION- Description of the resource-a, --attributes ATTRIBUTES- Comma-separated list of attributes with types-t, --template TEMPLATE- Template to use (default: basic)-f, --force- Overwrite existing files-h, --help- Show help message
Examples
Generate a basic scaffold
This creates:
src/models/user.cr- The model classsrc/endpoints/users/- All endpoint filessrc/contracts/users/- All contract filessrc/pages/users/- All page filessrc/db/migrations/TIMESTAMP_create_users.cr- Migration filespec/- All test files
Generate a scaffold with attributes
Generate a scaffold with description
Generated Files
Model (src/models/RESOURCE_NAME.cr)
src/models/RESOURCE_NAME.cr)Migration (src/db/migrations/TIMESTAMP_create_RESOURCE_NAME.cr)
src/db/migrations/TIMESTAMP_create_RESOURCE_NAME.cr)Endpoints (src/endpoints/RESOURCE_NAME/)
src/endpoints/RESOURCE_NAME/)Index Endpoint (index_endpoint.cr)
index_endpoint.cr)Show Endpoint (show_endpoint.cr)
show_endpoint.cr)Create Endpoint (create_endpoint.cr)
create_endpoint.cr)Update Endpoint (update_endpoint.cr)
update_endpoint.cr)Destroy Endpoint (destroy_endpoint.cr)
destroy_endpoint.cr)Contracts (src/contracts/RESOURCE_NAME/)
src/contracts/RESOURCE_NAME/)Base Contract (contract.cr)
contract.cr)Pages (src/pages/RESOURCE_NAME/)
src/pages/RESOURCE_NAME/)Index Page (index_page.cr)
index_page.cr)Show Page (show_page.cr)
show_page.cr)New Page (new_page.cr)
new_page.cr)Edit Page (edit_page.cr)
edit_page.cr)Attribute Types
Supported Attribute Types
Attribute Options
Scaffold Patterns
Basic CRUD Scaffold
This creates a complete CRUD interface for users with:
User model with validations
Database migration
RESTful endpoints (index, show, create, update, destroy)
Validation contracts
Web pages (index, show, new, edit)
HTML templates
Test files
Blog Post Scaffold
This creates a blog post system with:
Post model with associations
Migration with indexes
Full CRUD endpoints
Form validation
Web interface
SEO-friendly URLs
E-commerce Product Scaffold
This creates a product management system with:
Product model with inventory tracking
Price and stock management
Category associations
SKU validation
Complete admin interface
Using Scaffolds
Route Registration
Register scaffold routes in your application:
Customizing Generated Code
After generating a scaffold, you can customize the generated files:
Adding Associations
Best Practices
1. Plan Your Attributes
Think carefully about your resource attributes before scaffolding:
2. Use Appropriate Data Types
3. Include Validations
4. Consider Performance
Testing Scaffolds
Model Testing
Endpoint Testing
Page Testing
Common Scaffold Patterns
1. User Management
2. Content Management
3. E-commerce
4. Event Management
Related Commands
azu generate model- Generate data modelsazu generate endpoint- Generate API endpointsazu generate contract- Generate validation contractsazu generate page- Generate web pagesazu generate migration- Generate database migrations
Templates
The scaffold generator supports different templates:
basic- Basic CRUD scaffold templateapi- API-only scaffold templateweb- Web-focused scaffold templateadmin- Admin interface scaffold template
To use a specific template:
Last updated