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 class

  • src/endpoints/users/ - All endpoint files

  • src/contracts/users/ - All contract files

  • src/pages/users/ - All page files

  • src/db/migrations/TIMESTAMP_create_users.cr - Migration file

  • spec/ - All test files

Generate a scaffold with attributes

Generate a scaffold with description

Generated Files

Model (src/models/RESOURCE_NAME.cr)

Migration (src/db/migrations/TIMESTAMP_create_RESOURCE_NAME.cr)

Endpoints (src/endpoints/RESOURCE_NAME/)

Index Endpoint (index_endpoint.cr)

Show Endpoint (show_endpoint.cr)

Create Endpoint (create_endpoint.cr)

Update Endpoint (update_endpoint.cr)

Destroy Endpoint (destroy_endpoint.cr)

Contracts (src/contracts/RESOURCE_NAME/)

Base Contract (contract.cr)

Pages (src/pages/RESOURCE_NAME/)

Index Page (index_page.cr)

Show Page (show_page.cr)

New Page (new_page.cr)

Edit Page (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

  • azu generate model - Generate data models

  • azu generate endpoint - Generate API endpoints

  • azu generate contract - Generate validation contracts

  • azu generate page - Generate web pages

  • azu generate migration - Generate database migrations

Templates

The scaffold generator supports different templates:

  • basic - Basic CRUD scaffold template

  • api - API-only scaffold template

  • web - Web-focused scaffold template

  • admin - Admin interface scaffold template

To use a specific template:

Last updated