The one-file backend blueprint: Hono + Zod + Drizzle, mapped
My app is live in both stores and the backend is basically one file. I started with 7 "services"; I collapsed them into one Hono monolith (Zod validating every request, Drizzle talking to Postgres, deployed as a single serverless function) with 617 backend tests that run in seconds against it. That one file runs Settl for thousands of expenses.
The blueprint
backend/
index.ts ← THE file: one Hono app, all routes mounted
src/modules/ ← route groups, one folder per domain (users, orders, billing…)
packages/types/ ← Zod schemas, shared with the client
packages/db/ ← Drizzle schema + pg Pool
- One Hono app, one deploy unit. Everything mounts on a single app exported from one entry file. One function on Vercel, one cold-start story, one log stream, zero inter-service networking to debug.
const app = new Hono();
app.route('/users', users);
app.route('/orders', orders);
app.route('/billing', billing);
export default app; // Vercel Fluid Compute picks this up
- Zod on every request boundary. Every body, param, and query parses through a schema before
touching logic. The schemas live in a shared
typespackage so the client and server literally cannot disagree about shapes. - Drizzle straight to Postgres. No repository-pattern lasagna, just typed queries where they're used. The type system is the abstraction layer.
- Tests hit the app object, not the network. Hono's
app.request()runs the full stack (middleware, validation, DB) in-process. That's how 617 tests finish in seconds. No server boot, no port juggling:
const res = await app.request('/users', {
method: 'POST', headers: auth(user), body: JSON.stringify(payload),
});
expect(res.status).toBe(201);
- Modules are folders, not deployments. You still get code organization (a
modules/directory per domain); you just don't pay a network hop, a contract version, and a deploy pipeline per module. - Split only on a real fault line. Legit reasons: a dependency-heavy workload (headless Chrome, ffmpeg), a different scaling profile, a different language. "Feels cleaner" is not a fault line. Microservices solve org-chart problems; you don't have an org chart.
- Keep escape hatches config-shaped. Same Docker image can move to Fly/Fargate. The monolith is the opposite of lock-in: one thing is easy to move.
Bootstrap a new one
The blueprint above is what to do with a codebase you already have. This is the whole thing from zero — five files, running locally and deployed, with the test harness that makes the rest possible.
mkdir backend && cd backend && npm init -y
npm i hono zod drizzle-orm pg
npm i -D typescript vitest @types/pg drizzle-kit
src/db.ts — Drizzle schema and one pool. No repository layer; the types are the abstraction.
import {pgTable, serial, text, integer, timestamp} from 'drizzle-orm/pg-core';
import {drizzle} from 'drizzle-orm/node-postgres';
import {Pool} from 'pg';
export const expenses = pgTable('expenses', {
id: serial('id').primaryKey(),
payerId: integer('payer_id').notNull(),
cents: integer('cents').notNull(),
note: text('note'),
createdAt: timestamp('created_at').defaultNow().notNull(),
});
export const db = drizzle(new Pool({connectionString: process.env.DATABASE_URL}));
src/types.ts — the schemas the client imports too, so the two cannot disagree.
import {z} from 'zod';
export const NewExpense = z.object({
payerId: z.number().int().positive(),
cents: z.number().int().positive(),
note: z.string().max(140).optional(),
});
export type NewExpense = z.infer<typeof NewExpense>;
src/modules/expenses.ts — a module is a folder, not a deployment.
import {Hono} from 'hono';
import {db, expenses} from '../db';
import {NewExpense} from '../types';
export const expensesRoute = new Hono()
.post('/', async (c) => {
const parsed = NewExpense.safeParse(await c.req.json());
if (!parsed.success) return c.json({error: parsed.error.flatten()}, 400);
const [row] = await db.insert(expenses).values(parsed.data).returning();
return c.json(row, 201);
})
.get('/', async (c) => c.json(await db.select().from(expenses)));
src/app.ts — THE file. Every route mounts here; this is the one deploy unit.
import {Hono} from 'hono';
import {expensesRoute} from './modules/expenses';
export const app = new Hono();
app.route('/expenses', expensesRoute);
export default app;
api/index.ts — the only Vercel-specific file in the project.
import {handle} from 'hono/vercel';
import app from '../src/app';
export const config = {runtime: 'nodejs'};
export default handle(app);
src/app.test.ts — the unlock. app.request() runs middleware, validation and the DB
in-process, so there is no server to boot and no port to juggle. This is why hundreds of tests
finish in seconds.
import {expect, test} from 'vitest';
import app from './app';
test('rejects a bad body before it reaches the db', async () => {
const res = await app.request('/expenses', {
method: 'POST', headers: {'content-type': 'application/json'},
body: JSON.stringify({payerId: -1, cents: 0}),
});
expect(res.status).toBe(400);
});
test('creates an expense', async () => {
const res = await app.request('/expenses', {
method: 'POST', headers: {'content-type': 'application/json'},
body: JSON.stringify({payerId: 1, cents: 2400, note: 'Dinner'}),
});
expect(res.status).toBe(201);
expect(await res.json()).toMatchObject({cents: 2400});
});
Then:
npx vitest # the suite, in-process
npx drizzle-kit push # schema to Postgres
npx vercel # one function, one deploy unit
Adding a domain is a new file in src/modules/ and one app.route() line. That is the whole
growth story — no new pipeline, no new contract, no new cold start.
Steal this for your app
- Count your deploy units, then count your engineers. If units > engineers, you're paying enterprise coordination tax on a solo project.
- The real velocity unlock is test speed: in-process request tests against a monolith give you a full integration suite that runs on every save.
- Collapse first, extract later. Extracting a module from a monolith is a refactor; merging two microservices is an archaeology dig.
Run this on your codebase
Paste this into Claude Code in your repo:
Audit this repo for unnecessary service sprawl.
Count the deploy units: separate services, functions, containers, and CI pipelines. Compare that count to the team size.
For each service boundary, name the real fault line (dependency-heavy workload, different scaling profile, different language) or flag it as "feels cleaner."
Find request boundaries that skip schema validation, and shapes the client and server define separately instead of sharing.
Check how integration tests run: flag suites that boot servers or juggle ports instead of hitting the app object in-process.
Identify services that could collapse into one app with modules as folders, and note what coordination overhead disappears.
Report findings as a checklist before changing anything.