azu generate

The azu generate command is one of the most powerful features of Azu CLI. It creates various components for your application, following Azu conventions and best practices. This command helps you rapidly develop applications by generating boilerplate code, tests, and associated files.

Overview

azu generate <generator_type> <name> [attributes] [options]

Available Generators

Generator
Alias
Description

endpoint

e, controller

HTTP endpoints with full CRUD operations

model

m

CQL ORM models with validations

service

s

Business logic services following DDD patterns

middleware

mw

HTTP middleware components

contract

c

Request/response validation contracts

page

p

Page components for rendering HTML

component

comp

Live interactive components with real-time features

validator

v, val

Custom validation logic

migration

mig

Database migration files

scaffold

Complete CRUD resource (all of the above)

Global Options

Option
Description
Default

--force

Overwrite existing files without prompting

false

--skip-tests

Don't generate test files

false

--skip-routes

Don't register routes automatically

false

--help

Show help for the generator

Endpoint Generator

Generates HTTP endpoints (controllers) for handling web requests.

Usage

Examples

Generated Files

Example Generated Endpoint

Options

Option
Description

--api

Generate API-only endpoints (no pages/templates)

--actions <list>

Specify which actions to generate

Model Generator

Generates CQL ORM models with validations and relationships.

Usage

Examples

Field Types

Type
Crystal Type
Database Type

string

String

VARCHAR/TEXT

text

String

TEXT

integer

Int32

INTEGER

bigint

Int64

BIGINT

float

Float64

FLOAT

decimal

BigDecimal

DECIMAL

boolean

Bool

BOOLEAN

date

Date

DATE

time

Time

TIMESTAMP

json

JSON::Any

JSON/JSONB

uuid

UUID

UUID

Generated Files

Example Generated Model

Options

Option
Description

--validations

Add common validations

--timestamps

Add created_at/updated_at fields

--uuid

Use UUID as primary key

Service Generator

Generates service classes for encapsulating business logic.

Usage

Examples

Generated Files

Example Generated Service

Component Generator

Generates live, interactive components for real-time features.

Usage

Examples

Generated Files

Example Generated Component

Options

Option
Description

--websocket

Enable WebSocket support for real-time updates

--events <list>

Specify custom event handlers

Migration Generator

Generates database migration files.

Usage

Examples

Generated Files

Example Generated Migration

Migration Types

Based on the migration name, different templates are used:

  • create_*_table - Creates a new table

  • add_*_to_* - Adds columns to existing table

  • remove_*_from_* - Removes columns from table

  • add_index_* - Adds database index

Scaffold Generator

Generates a complete CRUD resource with all associated files.

Usage

Examples

Generated Files

The scaffold generator creates:

  • Model with validations

  • All CRUD endpoints

  • Request contracts

  • Page components

  • HTML templates

  • Test files

  • Database migration

Advanced Usage

Custom Templates

You can create custom generator templates:

Generator Hooks

Add custom logic before/after generation:

Batch Generation

Generate multiple components at once:

Troubleshooting

Common Issues

File Already Exists

Invalid Attribute Syntax

Generator Not Found

Best Practices

  1. Use descriptive names for generators

  2. Plan your attributes before generating

  3. Generate tests alongside code

  4. Use scaffold for rapid prototyping

  5. Customize generated code to fit your needs


Related Documentation:

Last updated