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:
initwrites a new app in the layout.addadds a feature or an endpoint to an app, in the same layout.checkchecks that an app still follows the layout's rules.
Run it with any package manager:
bun x hono-bento --helpadd 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
notesfeature, withlist,createandretrieveroutes; - its schemas, its tests, and a
structure.test.tsthat runshono-bento check; - an
AGENTS.mdwith the layout's rules, for you and your agents.
The package is named after the folder.
| Option | What it does |
|---|---|
--db prisma | Keeps 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. |
--monorepo | Puts 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 @acme | Names the workspace packages (@acme/schemas). Only with --monorepo. It defaults to @ plus the folder's name. |
--force | Writes 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 prismahono-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:
| File | What's in it |
|---|---|
<schemas>/<name>.ts | The 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.ts | The feature's contracts and spec, under /v1/<name> (or the prefix the other features use). |
features/<name>/<operation>.ts | One handler per route. |
features/<name>/store.ts | The feature's queries. With a list route, a list query that returns an empty list until you write it. |
features/<name>/<name>.test.ts | One it.todo per route. |
specs.ts | Gets 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>).
| Option | What it does |
|---|---|
--routes | The routes to start with, from list, create, retrieve, update and delete. Default list. Add any other route afterwards with add endpoint. |
--model | The 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 answers501until you write it; - adds the contract to
contractsand the route toroutesinspec.ts, with their imports; - adds an
it.todoto the feature's test file.
| Option | What it does |
|---|---|
--method | The route's method: get, post, put, patch or delete. |
--path | The 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:
| Operation | Method | Path | Response | Body |
|---|---|---|---|---|
list | GET | / | 200, <model>ListSchema | |
create | POST | / | 201, <model>Schema | <model>CreateSchema |
retrieve | GET | /:id | 200, <model>Schema | |
update | PATCH | /:id | 200, <model>Schema | <model>UpdateSchema |
delete | DELETE | /:id | 200, <model>Schema | |
| anything else | POST | /: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 archiveAdd 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 --rulesChecks 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.
| Option | What it does |
|---|---|
--config <file> | The config to read. Default hono-bento.config.ts in the current folder. |
--rules | Lists 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().