Skip to Content
hono-bento

Introduction

An opinionated framework for Hono APIs, with one folder per feature and schemas shared across your monorepo.

hono-bento builds Hono APIs from declarative specs, and it has firm opinions about where code goes. Think of a bento box:

  • Each feature is a compartment. It's one self-contained folder: a routing table (spec.ts), one handler file per route, and the data access only it uses. Nothing spills into its neighbours.
  • specs.ts is the box. It's the one list of features. hono-bento mounts the routes from it and generates the OpenAPI 3.1 document from it, so what you serve and what you document can't drift apart.
  • The shared schemas package is the lid. Request and response schemas live in a workspace package. The API validates with them, and your web app, CLI or SDK parse responses with the same ones.

Why the opinions

Most API code sprawls in two ways. Routes are registered in one place while their handlers, validation, docs and permissions live in others. And the client copies the server's types by hand. Both make every change wider than it should be.

hono-bento keeps each change small and in one place:

  • Adding an endpoint means adding a contract to the feature's spec.ts, writing a handler file typed from it, and maybe a schema.
  • Adding a feature means creating a folder and adding one line to specs.ts.
  • Changing a schema shows up as a type error in every app that uses it.

That suits people reviewing a diff, and it suits coding agents especially. An agent working in a hono-bento app knows where everything goes. A test fails with a message that says what to move if the layout drifts. And these docs are served as /llms.txt.

What you get

  • A spec-driven router. For each route, hono-bento runs authentication and authorization, then validation, then your handler. Errors are serialized into a consistent { error, status } response.
  • Checked handlers. Each handler takes its types from its route's contract: a validated body, query and params, the caller's identity, and a respond that only sends the statuses and shapes the route documents. If a handler drifts from its route, it's a type error.
  • Secure defaults. Routes require authentication unless they opt out, and internal errors never reach clients. With validateResponses, every response is checked against its schema in tests, so an undocumented field can't leak.
  • Pluggable auth. You bring the strategies (JWT, API keys, sessions) and an authorizer (roles, scopes).
  • OpenAPI 3.1 from the same specs, with Zod schemas as components and every error response documented.
  • Startup guardrails. mountSpecs refuses duplicate routes and operation ids, scopes with no authorizer or on anonymous routes, and unknown strategy names.
  • It runs anywhere Hono runs: Node, Bun, Deno and edge runtimes. CI runs the published package on Node 22 and 24, Bun, Deno 2 and Cloudflare's workerd.

Compared with @hono/zod-openapi

@hono/zod-openapi also builds Hono routes and an OpenAPI document from Zod schemas, with the same generator underneath. If that's all you need, it's the smaller choice. hono-bento adds auth that's enforced from each route's contract rather than only documented, a layout that hono-bento check keeps in shape, handlers typed from their contracts, runtime response checks, tests generated from the specs, and one error shape everywhere.

When not to use it

  • A small, single-app API or a prototype. The monorepo, the shared schemas package and one file per route cost more than they give back until the API and the apps calling it grow. Use Hono on its own, or @hono/zod-openapi.
  • You want your own layout. Most of the value is in the layout being the same everywhere and checked. If you'd organize code differently, you'd be working against it.
  • APIs that are mostly WebSockets. Contracts, errors and checks cover HTTP requests with JSON bodies, and JSON, file or streamed responses. Mount WebSocket routes on the Hono app directly, next to mountSpecs.

On this page