Andurel

From mbvlabs/andurel · View interactive version

Andurel is an AI agent skill from the GitHub repository mbvlabs/andurel. Use this skill for Andurel framework projects when deciding where code belongs, adding or changing domains, services, handlers, routes, app middleware, background jobs, migrations, config, clients, or framework-adjacent packages. Focuses on project structure, layer placement, the read-only pattern l

How to use this skill

Skill file

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

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

  1. Inspect the existing resource closest to the requested change.
  2. Identify the delivery surface: Inertia page, API endpoint, background job, email, or CLI/command.
  3. Identify the domain object or workflow being changed.
  4. Keep changes in the smallest layer that can own the behavior honestly.
  5. Use andurel patterns show <kind> and andurel inspect … --json before 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):

  1. andurel patterns show domain — read the placement rules and checklist.
  2. Write domains/<entity>.go (entity + receiver + rules) and domains/<entity>.sql.
  3. Preview with andurel sync queries --dry-run --json, then run andurel sync queries --json to regenerate domains/internal/queries. Generation may also change shared go.mod and go.sum; coordinate with other writers and review changes. A preview is not a lock, and a failed apply may leave partial changes.
  4. 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:

  1. andurel patterns show job — read the args, worker, and registration rules.
  2. Put the args in queue/jobs/ and the worker in queue/; call domain or service code, not SQL.
  3. Register the worker in queue/workers.go. For recurring work, return a river.NewPeriodicJob(...) from queue.PeriodicJobs(); app.NewQueue passes it to River.

Add an HTTP resource:

  1. andurel patterns show handler and andurel patterns show route.
  2. Add route data to routes/.
  3. Write the handler in handlers/ using pkg/anduin.
  4. Wire the handler in app.
  5. Run andurel sync routes --json so Inertia pages can import resources/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:

  1. andurel patterns show migration — read the rules on the scaffold's users and tokens migrations.
  2. 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.
  3. 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.
  4. Follow the migration pattern's bounded existing-users example where its assumptions hold; plan data, cutover and rollback separately. Validate migrations, andurel sync queries --json, andurel verify and 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:

  1. Inspect the relevant domains and existing seeds in seeds/.
  2. Add a seed function to seeds/, using only exported domain/storage primitives.
  3. Register it in seeds.Registry with a stable lowercase name.
  4. 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.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.