Andurel
Use this skill when working in an Andurel project or adding Andurel code. It helps place code in the right layer and use the andurel CLI safely.
Andurel is Go-native: net/http through pkg/anduin, explicit constructor injection (no DI container), and Inertia for the UI. There is no Echo, no Fx, and no server-side template page layer.
Agent Invariants
- Prefer
andurel --agent --help,andurel commands --json, andandurel commands --checkfor discovery. - Read references/cli-catalog.md for group layout and workflows.
- Read references/http-and-routing.md for the
pkg/anduinHTTP model. - Read references/testing.md for race-detector setup, deterministic clocks, real-PostgreSQL test databases, rollback fault injection, and read-only or isolated transactions.
andurel skill show <reference>printscli-catalog,http-and-routing,layer-placement, ortestingwithout installing the skill; the same files ship in<harness skills dir>/andurel/references/afterandurel skill install.- Run
andurel inspect project --jsonbefore changing code. - Use
--jsonor--jqwhen extracting data. andurel generatedoes not write application code. Read a pattern withandurel patterns show <kind>and write the files yourself. Onlyandurel generate migrationcreates a file.- Run
andurel verifyafter a change: it checks formatting,go fix,go vet, the typed layer rules, thepackage.jsontypecheck script, and generated-code drift. The rules are listed under Verify. Pass Go package patterns to scope the Go checks, and add--with-teststo also run the test suite. - Prefer the local project pattern over a generic Rails, Echo, Bun, server-side templating, or frontend convention.
- Keep handlers as thin HTTP adapters: parse input, call a domain or service, map errors, render a response.
- Create a service only when there is real cross-domain orchestration, not just because code exists.
Read When Placing Code
Read references/layer-placement.md before adding or moving behavior across domains, services, handlers, payloads, routes, middleware, queue jobs, config, clients, or app packages. It is the one place the placement table, the hard rules per layer, and the decision checklist are written down.
Read When Testing
Read references/testing.md before writing a test that uses the clock, a test database, a capability token, a transaction option, or a fault-injected rollback. Real PostgreSQL integration tests are the core of verification; a skip is reported, never treated as a pass.
First Pass
- Inspect the existing resource closest to the requested change.
- Identify the delivery surface: Inertia page, API endpoint, background job, email, or CLI/command.
- Identify the domain object or workflow being changed.
- Keep changes in the smallest layer that can own the behavior honestly.
- Use
andurel patterns show <kind>andandurel inspect … --jsonbefore writing.
Verify
With --json or --agent, a failed andurel verify writes its report to stderr and leaves stdout empty; read the failure report from stderr.
Host fallback policies are checked at app startup, not by a static verify rule. Use andurel verify --with-tests to run the app startup tests that catch a host with routes but no fallback policy.
andurel verify runs the setup preflight, gofmt, go fix, go vet, the typed layer rules, the frontend stage (the package manager's typecheck script when package.json defines one, plus the route-usage rule), the generated-code drift stage, and the content stage (andurel.content.toml invariants, which are skipped when the project declares none). It reports each violation as {rule, file, line, message, fix}. Apply the fix and re-run. Every independent stage runs even after another fails, and the summary lists all failed stages. andurel verify [packages...] scopes the Go checks and generated drift to package patterns (for example ./app/...); the frontend typecheck stays whole-project. If the generated step fails in a scoped run, rerun with --only listing the stages you need to skip it. --no-frontend skips the typecheck. With --with-tests, packages that ran no tests are listed under skipped_packages and t.Skip calls under skipped_tests with their reason. Each violation's rule is one of these (andurel verify --help also prints each rule's fix):
<!-- andurel:verify-rules:begin: generated from the verify rule catalog by 'just docs-sync'; do not edit -->
| Rule | Checks |
| --- | --- |
| gofmt | every Go file is gofmt-clean |
| go fix | go fix reports no automatic rewrites |
| queries-import | only domains/** imports domains/internal/queries |
| db-handle | outside domains no SQL methods or SQL drivers; Connection/Transaction are persistence wiring |
| tx-unwrap | storage.Unwrap is referenced only under domains/** |
| tx-escape | a storage.AtomicOps callback uses only dependencies bound inside the transaction |
| tx-public-call | a storage.AtomicOps callback does not call an exported method on its own receiver |
| tx-layer | storage.AtomicOps and storage.Transactor are used only in services, domains, and app |
| payloads-import | payloads/** imports only the standard library and mappable types; no app packages, storage, anduin, inertia, or net/http |
| domain-transport | domains/** imports no HTTP, Inertia, routing, handler, middleware, or route package |
| route-host | a route declared on a non-primary host is registered with rt.Route(route), not rt.Get(route.Pattern()) |
| entity-columns | every automatic generated query column maps to an exported andurel tag on its domain entity |
| setup | project setup is complete: managed tool binaries and frontend dependencies are installed |
| frontend | the package.json typecheck script passes when the scaffold defines one |
| frontend-route-usage | frontend modules do not call full-URL route helpers at module initialization; use .path() or call while rendering |
| content-config | andurel.content.toml parses, declares a supported schemaVersion, and its include/exclude globs are valid |
| content-catalog | every declared content catalog entry resolves to an included Markdown file |
| content-slug | content catalog slugs are non-empty, match the declared pattern, and are unique |
| content-required | every path listed in andurel.content.toml required exists |
| content-link | local Markdown links and images resolve inside the project; configured anchors exist |
| content-checker | each declared content checker exits 0 within its timeout from its declared working directory |
| generated | generated email, queries, routes, and payload output is up to date |
| missing-tool | a required generation binary is installed; run 'andurel tool sync' |
<!-- andurel:verify-rules:end -->
Output Modes
Use structured output by default when automating:
| Flag | Use |
|------|-----|
| --json | Full {ok,data,summary,breadcrumbs} envelope |
| --agent | Structured output with non-essential human progress suppressed |
| --jq '.field.path' | Built-in simple field-path extraction |
| --quiet | Suppress human-only output |
| --md | Markdown output where supported |
Structured failures include ok:false, a stable code, error, optional hint, and exit_code. Prefer the hint and breadcrumbs fields over guessing the next command.
Common Workflows
Inspect a project:
andurel inspect project --json
andurel inspect config --json
andurel inspect routes --json
andurel inspect handlers --json
andurel inspect domains --json
andurel inspect migrations --json
andurel commands --json
Read a pattern before writing code:
andurel patterns list --json
andurel patterns show domain
andurel patterns show handler --json
andurel patterns show middleware
andurel patterns show page
Add a domain (type-driven: change the Go type first, then let SQL and queries follow):
andurel patterns show domain— read the placement rules and checklist.- Write
domains/<entity>.go(entity + receiver + rules) anddomains/<entity>.sql. - Preview with
andurel sync queries --dry-run --json, then runandurel sync queries --jsonto regeneratedomains/internal/queries. Generation may also change sharedgo.modandgo.sum; coordinate with other writers and review changes. A preview is not a lock, and a failed apply may leave partial changes. - Write the migration with
andurel generate migration <name>.
Keep hand-written SQL in domains/<entity>.sql and generated code in domains/internal/queries/. Only domains should import that internal package. Each receiver has New<Plural>(db) (constructed in app) and InTx(tx storage.Tx). A receiver whose own method writes more than once, or reads, modifies and writes a row, holds a storage.Transactor; that method locks the row before saving and joins a caller's transaction when bound. Services take a storage.Transactor, their receivers, and the queue individually, and run multi-domain writes in storage.AtomicOps, binding receivers with InTx(tx) at the top of the callback.
Add a background job:
andurel patterns show job— read the args, worker, and registration rules.- Put the args in
queue/jobs/and the worker inqueue/; call domain or service code, not SQL. - Register the worker in
queue/workers.go. For recurring work, return ariver.NewPeriodicJob(...)fromqueue.PeriodicJobs();app.NewQueuepasses it to River.
Add an HTTP resource:
andurel patterns show handlerandandurel patterns show route.- Add route data to
routes/. - Write the handler in
handlers/usingpkg/anduin. - Wire the handler in
app. - Run
andurel sync routes --jsonso Inertia pages can importresources/js/routes.ts.
To build the frontend before the handler exists, write the route values and payload structs first, run andurel sync routes --json and andurel sync payloads --json, then build the page. The generated helpers come only from Go that already exists. See layer-placement.md.
Port onto an existing database:
andurel patterns show migration— read the rules on the scaffold'susersandtokensmigrations.- Inspect existing schema, dependencies and goose history on a disposable clone before applying anything. Unrecorded existing tables can conflict; recorded versions or a manual baseline do not establish schema equivalence. Keep River and required bootstrap system migrations.
- Reconcile the scaffold auth contracts and data before retaining
00008/00009; preserve scaffold auth with compatible additive migrations. Alternatively replace those unapplied migrations only alongside affected domains, SQL, generated queries and auth consumers. Never rewrite deployed migration history. - Follow the migration pattern's bounded existing-
usersexample where its assumptions hold; plan data, cutover and rollback separately. Validate migrations,andurel sync queries --json,andurel verifyand auth behavior on the clone before any real cutover.
Generate Inertia route helpers:
andurel inspect routes --json
andurel sync routes --json
andurel sync routes reads routes/*.go as the source of truth and writes resources/js/routes.ts for routes marked routing.TypeScriptRoute() (routing.InertiaRoute() is a deprecated alias). Import helpers from that file in Inertia pages instead of hard-coding URLs. Helpers are flat and keyed by the route variable in lower camelCase (UserIndex → routes.userIndex), not by the route's declared name. Helpers include the route host and return absolute URLs once configureRouteHosts has run; call routes.name.path() when a relative path is required.
Call helpers at render time (href={routes.widgetShow(id)}), not in a module-scope constant such as const url = routes.widgetShow(id): configureRouteHosts runs after the app boots, so a constant captured at import time keeps an empty origin (or the server's request-time value under SSR).
Generate Inertia payload types:
andurel sync payloads --json
payloads/ is the single source of resources/js/types/payloads.ts, just as routes/ is the source of routes.ts. andurel sync payloads emits every exported struct declared in payloads/ and follows nested named structs in that package. json:"-" is omitted and omitempty makes a field optional. A non-omitempty slice or []byte is nullable in TypeScript because a nil Go value encodes as JSON null.
Keep payload fields to standard-library types, time, and the stdlib uuid package the scaffold imports: payloads/ may not import application packages, pkg/storage, pkg/anduin, pkg/inertia, or net/http (the payloads-import rule). Use pointer fields such as *string for optional scalars; database/sql Null* structs encode as objects and are rejected. Untagged embedded structs flatten like encoding/json, while an embedded field with an explicit JSON name stays nested (a pointer embed makes its promoted fields optional). Handlers import payloads for page props and request bodies and pass them with inertia.FromStruct(payloads.SomeProps{...}). Import the generated types from @/types/payloads instead of hand-writing them, and run the command after editing payloads/.
Generate a named database seed:
- Inspect the relevant domains and existing seeds in
seeds/. - Add a seed function to
seeds/, using only exported domain/storage primitives. - Register it in
seeds.Registrywith a stable lowercase name. - Verify the seed is discoverable:
andurel db seed --list
andurel db seed development
andurel db seed test
A seed that writes more than one table must be atomic: either every row lands or none does. Build a storage.NewTransactor(db) in the seed and run the writes in storage.AtomicOps, binding each receiver with InTx(tx) inside the callback:
func Demo(ctx context.Context, db storage.Connection) error {
transactor := storage.NewTransactor(db)
users := domains.NewUsers(db)
products := domains.NewProducts(db)
return storage.AtomicOps(ctx, transactor, func(ctx context.Context, tx storage.Tx) error {
users, products := users.InTx(tx), products.InTx(tx)
if _, err := users.Create(ctx, pepper, domains.CreateUserData{ /* … */ }); err != nil {
return err // rolls back every earlier write
}
_, err := products.Create(ctx, domains.CreateProductData{ /* … */ })
return err
})
}
The scaffold's Development and Test seeds write one table through the domains receivers and need no transaction. Use AtomicOps only when a seed writes several tables. Keep seeds idempotent: look up an existing row before creating it, as createUser does.
Check project health and verify a change:
andurel doctor --json
andurel verify
In Inertia projects, doctor checks whether resources/js/routes.ts matches the current routes/*.go manifest and whether resources/js/types/payloads.ts matches the exported structs in payloads/. If the routes.ts check fails, run andurel sync routes --json. If the payloads.ts check fails, run andurel sync payloads --json.
When annotated narsilc queries exist, doctor also checks generated code for drift. If the narsilc generate check fails, run andurel sync queries --json.
Update standalone Andurel packages in go.mod (github.com/mbvlabs/andurel/pkg/*):
andurel packages list --json
andurel packages update --dry-run --json
andurel packages update --json
This updates required package versions to the latest published releases. It does not change framework-owned files. andurel upgrade pins required packages to the versions verified with the installed CLI.
Validation
Follow the target repository's local validation guidance. Run andurel verify for the framework checks. Do not assume that a command is permitted merely because it is common in another Andurel project.