Monorepo setup
Put your schemas in a workspace package that the API and every other app import.
An API on its own fits in one package. Move to a
monorepo when another app needs the API's schemas: a web client, a CLI, a
second service. Then the apps live in apps/, and the schemas in a workspace
package, packages/schemas, that every app depends on. It exports TypeScript
source directly, so it needs no build step. hono-bento init --monorepo
starts in this shape.
Workspace root
{
"private": true,
"type": "module",
"workspaces": ["apps/*", "packages/*"]
}The schemas package
The wildcard export makes each src/<feature>.ts importable as
@todos/schemas/<feature> as soon as the file exists, with no package.json
edit. Rename @todos to your own scope.
{
"name": "@todos/schemas",
"private": true,
"type": "module",
"exports": { "./*": "./src/*.ts" },
"dependencies": {
"hono-bento": "^0.1.0",
"zod": "^4.0.0"
}
}The package imports only zod and hono-bento/zod. It never imports app
code, so a web app, a CLI or a generated SDK can depend on it without pulling
in your server.
Apps
Every app that speaks the API's contract depends on the package:
{
"name": "@todos/api",
"private": true,
"type": "module",
"dependencies": {
"@todos/schemas": "workspace:*",
"hono": "^4.11.0",
"hono-bento": "^0.1.0",
"zod": "^4.0.0"
}
}TypeScript
Share one base config, and use "moduleResolution": "Bundler" so TypeScript,
Bun and bundlers follow the package's exports map into its source:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"skipLibCheck": true,
"noEmit": true
}
}Each app and package then has a tsconfig.json that extends it:
{
"extends": "../../tsconfig.base.json",
"include": ["src"]
}A root tsconfig.json that includes apps/*/src and packages/*/src
typechecks the whole monorepo in one pass.
Using Node without a bundler?
Node can't import .ts files from node_modules on its own. Run your apps with Bun or tsx, or bundle them. If you
publish the schemas package to npm, add a build step and point exports at the compiled .js and .d.ts files
instead.
Moving from one package
The rules are the same in both shapes, and code already imports the schemas by name, so the move is mechanical:
- Move the app into
apps/api(itssrc/,package.json,hono-bento.config.tsandtsconfig.json), and add the workspace root andtsconfig.base.jsonabove. - Move
src/schemas/*.tstopackages/schemas/src/, and add itspackage.json. - Replace
#schemas/with@todos/schemas/in every import, drop#schemas/*from the app'simports, and add"@todos/schemas": "workspace:*"to its dependencies. - Point
hono-bento.config.tsat the package:schemas: { dir: '../../packages/schemas/src', package: '@todos/schemas' }.
The database can stay in the app as #db, or move to packages/db the same
way, imported as @todos/db. Then run your tests: structure.test.ts runs
hono-bento check, which names any import still pointing at the old place.
Use the schemas from another app
See Consuming schemas for a typed client that validates requests and parses responses with the same schemas the API uses.