Code Generation
Andurel v2 does not scaffold models, controllers, or CRUD. andurel generate has exactly one subcommand, migration. Every application file is written by hand from a reference pattern, and files that can be derived are refreshed with andurel sync.
Create a migration
1andurel generate migration create_products_table
2andurel db migrate up
The command creates a timestamped goose SQL file under migrations/. Write both directions, then apply it. The migration is the schema source of truth; the domain entity and its queries follow it.
1-- +goose Up
2create table products (
3 id uuid primary key default gen_random_uuid(),
4 name text not null unique,
5 price_cents bigint not null default 0,
6 created_at timestamptz not null default now(),
7 updated_at timestamptz not null default now()
8);
9
10-- +goose Down
11drop table if exists products;
Write the rest from patterns
andurel patterns is read-only. It prints the reference file, the placement rules, and a checklist for the layer you are about to write:
1andurel patterns list
2andurel patterns show domain
3andurel patterns show service
4andurel patterns show handler
5andurel patterns show route
6andurel patterns show job
7andurel patterns show email
8andurel patterns show composition
| Need | Pattern | Where the code goes |
|---|---|---|
| Entity, validation, persistence | domain |
domains/<entity>.go and domains/<entity>.sql |
| Cross-domain workflow or transaction | service |
services/ |
| HTTP adapter | handler |
handlers/ |
| Route name, path, URL builder | route |
routes/ |
| Background job | job |
queue/jobs/ and queue/ |
| Email template | email |
email/*.templ |
| Wiring and lifecycle | composition |
internal/runtime/ |
| Tests | test-domain, test-handler, test-integration |
Colocated test files |
patterns show domain --entity Product --table products prints a per-entity manifest. When queries.ProductRow already exists in domains/internal/queries/models.go, the manifest includes the entity, receiver, Validate stub, and CRUD SQL; otherwise it includes a migration skeleton.
The generate, sync, verify loop
- Read the pattern and write the source files.
- Refresh the derived files for what changed.
- Run
andurel verify.
1andurel patterns show domain
2# write domains/product.go and domains/product.sql
3andurel sync queries
4# construct domains.NewProducts(db) in internal/runtime
5andurel verify
After adding or changing a route under routes/, regenerate the frontend helpers:
1andurel sync routes --json
After changing handler payload or bind structs:
1andurel sync payloads --json
After changing email templates or email CSS:
1andurel sync email
Authored and derived files
Keep this split in mind when editing:
| Authored | Derived |
|---|---|
domains/*.go, domains/*.sql |
domains/internal/queries/ |
services/, handlers/, routes/, middleware/ |
resources/js/routes.ts |
queue/, email/*.templ, migrations/ |
resources/js/types/payloads.ts |
resources/js/Pages/, css/ |
email/*_templ.go, assets/dist/ |
Derived files are written by andurel sync or the toolchain. Do not hand-edit them; edit the source and refresh. andurel verify reports stale generated output under the generated rule, and andurel doctor --json lists the same drift as checks.
Keep the layer rules green
andurel verify also enforces the boundaries that the patterns describe: only domains/** imports generated queries, only domains and wiring layers name the database connection, transactions stay in services/domains, and domains/** never imports HTTP or Inertia packages. Each violation includes a fix.
1andurel verify --json
2andurel inspect domains --json
3andurel inspect handlers --json