Skip to Content
hono-bento

The CLI

hono-bento init starts an app, hono-bento add grows it, and hono-bento check keeps it in the layout.

The hono-bento command comes with the package. It has three jobs:

  • init writes a new app in the layout.
  • add adds a feature or an endpoint to an app, in the same layout.
  • check checks that an app still follows the layout's rules.

Run it with any package manager:

bun x hono-bento --help

add and check read the app's hono-bento.config.ts, so they need a runtime that runs TypeScript: Bun, or Node 22.18 and later. check also imports the app's own modules. If those imports leave out file extensions, as the apps init writes do, run check with bun --bun hono-bento check. The check script init writes does that for you.

hono-bento init

hono-bento init [dir] [--db prisma] [--monorepo [--scope @acme]] [--force]

Writes a new app into dir (default: the current folder). The app has:

  • one notes feature, with list, create and retrieve routes;
  • its schemas, its tests, and a structure.test.ts that runs hono-bento check;
  • an AGENTS.md with the layout's rules, for you and your agents.

The package is named after the folder.

OptionWhat it does
--db prismaKeeps the data in Postgres through Prisma, with a Docker Compose file for a local database and a Postgres schema per test run. Without it, the data lives in memory.
--monorepoPuts the schemas (and, with Prisma, the database client) in workspace packages, so other apps can import them. Without it, everything is one package. See Monorepo.
--scope @acmeNames the workspace packages (@acme/schemas). Only with --monorepo. It defaults to @ plus the folder's name.
--forceWrites into a folder that isn't empty, replacing any files with the same names. Without it, init refuses a folder with files in it.

When it's done, it prints the next steps: install, then setup with Prisma, then dev.

bun x hono-bento init my-api --db prisma

hono-bento add feature

hono-bento add feature <name> [--routes list,create,retrieve,update,delete] [--model <singular>] [--config <file>]

Adds a feature. Its name is lowercase words joined by dashes, like invoices or invoice-items. It writes:

FileWhat's in it
<schemas>/<name>.tsThe model's schema and its list schema, with a TODO where the fields go. Kept as it is if it already exists.
features/<name>/spec.tsThe feature's contracts and spec, under /v1/<name> (or the prefix the other features use).
features/<name>/<operation>.tsOne handler per route.
features/<name>/store.tsThe feature's queries. With a list route, a list query that returns an empty list until you write it.
features/<name>/<name>.test.tsOne it.todo per route.
specs.tsGets the feature's import and its entry in specs.

Where features/ and the schemas go comes from hono-bento.config.ts, so the same command works in one package (imports from #schemas/<name>) and in a monorepo (imports from @acme/schemas/<name>).

OptionWhat it does
--routesThe routes to start with, from list, create, retrieve, update and delete. Default list. Add any other route afterwards with add endpoint.
--modelThe singular, when dropping the s gets it wrong: --model person for people. It names the schemas (personSchema) and the type (Person).
--config <file>The config to read. Default hono-bento.config.ts in the current folder.

list answers straight away with an empty list. Each of the other routes answers 501 not_implemented until you write its handler. The routes ask for the scopes <name>.read (for GET) and <name>.write (for everything else). No caller has those yet, so grant them in auth.ts. The command prints the scopes when it's done:

bun x hono-bento add feature invoices --routes list,create
  wrote   src/features/invoices/create.ts
  wrote   src/features/invoices/invoices.test.ts
  wrote   src/features/invoices/list.ts
  wrote   src/features/invoices/spec.ts
  wrote   src/features/invoices/store.ts
  wrote   src/schemas/invoices.ts
  edited  src/specs.ts

Next:
  Grant 'invoices.read', 'invoices.write' to the callers that need them (auth.ts).
  Fill in the TODOs, then run your tests and hono-bento check.

Add a feature walks through the same files by hand.

hono-bento add endpoint

hono-bento add endpoint <feature> <operation> [--method post] [--path /:id/archive] [--config <file>]

Adds a route to an existing feature. The operation is camelCase, like archive or markPaid. It names the route's contract and its handler's file. The command:

  • writes <operation>.ts, a handler typed from the contract that answers 501 until you write it;
  • adds the contract to contracts and the route to routes in spec.ts, with their imports;
  • adds an it.todo to the feature's test file.
OptionWhat it does
--methodThe route's method: get, post, put, patch or delete.
--pathThe route's path, after the feature's basePath, like /:id/archive.
--config <file>The config to read. Default hono-bento.config.ts in the current folder.

A standard operation gets its usual method, path and response. Any other gets POST /:id/<operation> unless you pass --method or --path:

OperationMethodPathResponseBody
listGET/200, <model>ListSchema
createPOST/201, <model>Schema<model>CreateSchema
retrieveGET/:id200, <model>Schema
updatePATCH/:id200, <model>Schema<model>UpdateSchema
deleteDELETE/:id200, <model>Schema
anything elsePOST/:id/<operation>200, <model>Schema

The model comes from the spec's model. The response schema must already be exported from the feature's schemas file. A body schema that isn't is added there, with a TODO for its fields. A route that takes any other body needs validation: { body } added to its contract by hand.

bun x hono-bento add endpoint invoices archive

Add an endpoint covers what's still yours to write: the schema changes, the query in store.ts, and the test.

How add edits your files

add parses each file it changes and inserts its lines at the right spot: the end of contracts, routes or specs, and next to the other imports. The rest of the file, with its formatting and comments, stays as it was. It finds those spots in the shape that init and the guides write. If a file is in another shape, say specs built by a function call, add prints the lines to paste and where they go, and exits with code 1. Anything else that would stop it, like an operation that already exists or a missing response schema, stops it before it writes anything.

hono-bento check

hono-bento check [--config <file>]
hono-bento check --rules

Checks the app in this folder against the layout's rules. For each problem, it prints the file, the line and what to change. It exits with code 1 when it finds any. --rules lists the rules and what each checks.

OptionWhat it does
--config <file>The config to read. Default hono-bento.config.ts in the current folder.
--rulesLists the rules, and checks nothing.

Enforce it with hono-bento check covers the config file, the rules and how to run them from your tests with check().

On this page