Welcome
An opinionated Hono framework for Cloudflare Workers.
Kata is a small, opinionated framework for backend services on Cloudflare Workers. It pairs Hono with a request-scoped DI container, type-safe modules, transactional services, queue producers and consumers, and a live devtools graph — without much weight on top of Hono.
The packages publish under the @katajs/* scope on npm; the framework itself goes by Kata.
What you get
A consistent project structure with one way to do each common backend task:
- Modules — group related routes + services; declare cross-module dependencies explicitly with
requires:. Boot validation fails if anything's wired wrong, with the exact missing key called out by name. - Request-scoped container —
c.var.resolve('postService')builds services lazily per request and disposes them at the end. No globals, no singletons that leak DB connections across requests. - Strict type-level autocomplete — every service key, module name, and route path is autocompleted by your editor. Typos are compile errors.
- Validation at the boundary —
validate({ body, query, param })wraps@hono/zod-validatorto throw a typedValidationErrorand preserves Hono RPC inference end-to-end. Clients get the exact validated input types. - Domain errors → HTTP responses —
throw new PostNotFoundError(id)becomes a structured JSON 404 viaerrorMapper. Status, code, and payload travel together. - Transactions across modules —
c.var.withTransaction(fn)gives you a sub-container where every repository is bound to the same transaction. Rolls back on throw. - Cloudflare Queues, first-class — modules can declare a
consumer:;createApp({ queues })declares producers with shared schemas. The same Worker exports bothfetchandqueuehandlers, or you split them acrossapps/apiandapps/workerin monorepo mode. - Drizzle adapter — wired through Hyperdrive. One line in
createAppandc.dbis your strongly-typed Drizzle client per request. - Devtools —
pnpm graphproduces a static HTML snapshot of your modules, edges, and routes.npx katajs-devtoolsopens a live React UI with a graph canvas, module drawer, routes table, queue producer/consumer view, and a Cmd+K palette. - Two scaffold shapes —
pnpm create katajs my-appfor a single-API project, or--monorepoforapps/*+packages/*with shared db / auth / queue Worker. Optional--authadds Better Auth wired in. - CLI mutators —
katajs add module|service|route|queuekeep yourapp.ts,types.d.ts, registry, and graph script in sync via anchored codemods. No hand-editing the wiring as your project grows.
Start here
- Intro — what Kata is, what it isn't, who it's for.
- Modules — the unit of organization:
provides,requires, routed vs services-only. - Container — request-scoped DI, lazy resolution, no global singletons.
- Devtools —
inspectModules()for static graphs andkatajs-devtoolsfor the live UI.
What you'll write
import { defineModule } from '@katajs/core';
export const postsModule = defineModule({
name: 'posts',
prefix: '/posts',
provides: {
postRepository: (c) => makePostRepository(c.db),
postService: (c) => makePostService(c),
},
requires: ['auditService'] as const,
routes: postsRoutes,
});Then createApp({ modules: [eventsModule, auditModule, postsModule] }) wires the container, validates the dependency graph at boot, and gives you a Hono app you can deploy.
Quickstart
pnpm create katajs my-app
cd my-app
pnpm devOpen src/modules/posts/ to see the example module. Open src/app.ts to see how it's wired in. Read the Intro for the longer story.