Docs

Guide 08

CLIreeve

08. reeve

reeve is the Avelon CLI. It creates apps, writes code into the right folders, syncs routes, and checks your project.


Running It

From an app with @avelonjs/cli in its devDependencies:

bunx --no-install reeve --help

Scripts in package.json can call reeve directly. From this repo's root, use bun packages/cli/src/bin.ts instead.

  • reeve with no arguments opens the TUI
  • reeve help make:model prints a command's usage, flags, and an example
  • reeve make:model --help does the same

Asking for help never runs the command.


Create an App

bunx --package @avelonjs/cli reeve new my-app
cd my-app
bun install
bun run dev

The app needs no database or credentials. From a framework checkout, bun run create:app ../my-app does the same thing.


Your App's Config

These load avelon.config.ts from the current folder before they run:

  • migrate, db:seed, and ward:sync
  • config:show, capabilities, and about
  • event:list, tinker, and doctor
  • the TUI header

So run them from the app root. Without the file, migrate, config:show, capabilities, ward:sync, and event:list stop and name the file they looked for. The rest run without it.

A config loaded earlier in the same process still counts, for example one loaded with bun --preload.


The TUI

┌─ avelon ────────────────────────────── my-app · supabase · next · local ─┐
│                                                                           │
│   Make        model, controller, request, policy, ward, event, listener,  │
│               errand, action, command, middleware, view, driver, package  │
│   Database    migrate, rollback, fresh, seed, schema:pull                 │
│   Wards       list, sync, check, explain                                  │
│   Routes      list, sync                                                  │
│   Errands     work, failed, retry, flush                                  │
│   Inspect     event:list, config:show, capabilities, about                │
│   Doctor      doctor, bailiff, docs:check                                │
│                                                                           │
│   ↑↓ navigate · ⏎ select · ? help · / search · q quit                     │
└───────────────────────────────────────────────────────────────────────────┘
  • Before it runs anything, the TUI prints the plain command, so you learn the scriptable version as you go
  • ? shows the highlighted command's usage and example. Escape goes back to the list
  • The header shows the app, database driver, adapter, and environment from avelon.config.ts. "Which database am I pointed at" is the question that comes before most disasters
  • AVELON_APP, AVELON_DATABASE, and AVELON_ADAPTER override what the header shows
  • Any command with arguments skips the TUI. So do --no-tui and a non-interactive terminal, which keeps CI free of prompts

Generate Code

A whole resource in one command:

reeve make:model Post -mfcp --resource

That writes the model, its ward, a migration, a factory, a policy, and a resource controller with its requests and pages. Then it registers the ward and policy.

The flags:

  • -m migration
  • -f factory
  • -c controller, and --resource gives it the 7 resource actions
  • -p policy

There's no flag for the ward. Every model gets one, because Bailiff fails a model without it.

Every Generator

CommandWrites
make:model PostThe model and its ward
make:controller Post --resource7 actions, 2 requests, and 4 pages
make:controller DashboardA controller and the page its index action renders
make:request StorePostRequestA request validator
make:policy PostPolicyA policy. --model=Post names the model
make:ward PostWardA ward. --model=Post names the model
make:event PostPublishedAn event
make:listener NotifySubscribersA listener. --event=PostPublished types and registers it. --queued makes it a queued listener with retries
make:errand GenerateThumbnailA queued errand
make:action PublishPostAn action
make:middleware EnsureSubscribedKernel middleware
make:command PruneDraftsA command. Run it with bun app/Commands/PruneDrafts.ts
make:view posts/IndexA React view at resources/views/posts/Index.tsx
make:authA session controller, sign-in and sign-out requests, and a sign-in page
make:migration add_slug_to_postsA timestamped migration
make:driver storage r2A driver package with its conformance suite wired up
make:package billingA package README in the house style

Every generated file type-checks and passes Bailiff in a fresh app. bun run scaffold:check in this repo runs every generator to keep it that way.

What Gets Wired Up

Generators also register what they write:

  • Wards and policies get defineWard or definePolicy in registerApp(), which lives in app/Providers/AppProvider.ts
  • A listener made with --event gets Events.listen there too, and the event is created if it's missing
  • Errands get registerErrand
  • Migrations get added to database/migrations/index.ts, which is created if it's missing

reeve new creates the provider and avelon.config.ts calls it. If the provider or registerApp() is missing, reeve prints the line to add instead. Routes and middleware are yours to place, so reeve prints those lines too.

When a File Exists

If the main file is already there, the generator writes nothing and exits 1. Supporting files that already exist, like a request a resource controller reuses, are kept as they are.

Custom Templates

reeve stub:publish

Copies the generator templates into stubs/. A file there replaces the built-in stub with the same name, so a team can change what generated code looks like without forking the framework.


Database

reeve migrate
reeve migrate:status
reeve migrate:rollback
reeve migrate:fresh --seed
reeve make:migration create_posts_table
reeve db:seed
  • migrate:fresh rolls back up to 100 migrations, then applies them again. Outside the local environment it needs --confirm=<environment>
  • --seed runs database/seeds afterward
  • schema:pull writes an empty Database interface to database/types.ts

Wards

reeve ward:list
reeve ward:check
reeve ward:explain Post
reeve ward:sync
  • ward:list shows each model and its ward file
  • ward:check fails when a model has no ward
  • ward:explain shows the SQL each ward rule adds to queries
  • ward:sync turns wards into row-level security on drivers that support it

Debugging Row Access

ward:explain reads app/Wards/PostWard.ts and compiles each rule twice, once for a guest and once for a signed-in actor:

$ reeve ward:explain Post read --actor=42
PostWard on posts. Each row shows the SQL condition a query receives.

read
  guest     "published_at" IS NOT NULL
  actor 42  ("published_at" IS NOT NULL OR "user_id" = $1)  $1 = "42"

That condition gets added to every query on the table. Leave off the action to see all 4.

Syncing to the Database

ward:sync calls the driver's syncWards() when the driver declares rowSecurity: true, like Supabase does. Postgres and Neon apply wards inside each query instead, so for them ward:sync says there's nothing to sync.


Routes

reeve route:list
reeve route:sync
reeve route:sync --check
  • route:list prints the method, path, name, action, and middleware. --json prints the same for scripts
  • route:sync regenerates pages, server actions, API handlers, and typed URLs from routes/web.ts
  • route:sync --check reports missing, changed, and stale files without writing anything, and exits 1 if anything drifted

Run --check in CI if your app commits its router. After changing a route locally, run reeve route:sync.

Typed URLs

Views and client components can build links without booting the router:

import { url } from '@/framework/routing/urls.generated'

const href = url('posts.show', { post: 42 }) // /posts/42

TypeScript checks the route name and its required params against routes/web.ts. Each value is encoded as one path segment. For writes, use the generated server actions.


Events

reeve event:list
EVENT          LISTENER           DELIVERY  QUEUE          TRIES  PRIORITY
PostPublished  NotifySubscribers  queued    notifications  3      10

It loads avelon.config.ts, and if that registers no listeners it calls registerApp() from app/Providers/AppProvider.ts. Listener names come from the exports in app/Listeners/. --json prints the same rows.


Errands

reeve errand:work
reeve errand:failed
reeve errand:retry <id|all>
reeve errand:flush

errand:work drains the queue and prints how many errands ran.

Queued errands wait on the job board of the process that dispatched them. So these commands only see errands queued in that same process - for example, a script that dispatches errands and then calls runReeve.


Doctor

reeve doctor
Doctor

  ok    Bailiff      clean
  ok    Wards        every model has a ward
  ok    Config       gazette (avelon.config.ts)
  ok    Router       up to date
  info  Environment  local

It exits 1 when:

  • Bailiff reports an error
  • a model has no ward
  • avelon.config.ts fails to load

An out of date router is only a warning, since apps that keep generated files out of Git won't have them until bun run generate. Doctor ends with the capability matrix.

The SaaS starter has its own bun run doctor that checks its environment and services.

Capabilities

reeve capabilities

Prints what your drivers can and can't do. It's the fastest way to find out why a driver has no transaction().


Inspect

reeve tinker
reeve tinker --execute 'await Post.query().count()'
reeve config:show
reeve about
  • tinker opens a REPL with your app, its models, DB, Events, and Route loaded. You can await a promise right on the line, and const posts = await Post.query().get() keeps posts for later lines. Type .exit to leave
  • config:show prints the app name, adapter, and the driver for each contract as JSON
  • about shows the app, environment, drivers, and installed package versions

Documentation

reeve docs:check
reeve docs:check packages/orm
reeve docs:check --workspace

Lints package READMEs against the house style in 10-conventions.md. A package fails when:

  • a required section is missing
  • a TypeScript or JSON code block doesn't parse
  • a public export is missing from the Method Reference table

To waive one, add <!-- docs:check-waiver: section Testing --> or <!-- docs:check-waiver: export name -->. make:package writes a README that already passes.