# monk-code-screen Billing/subscriptions/invoicing backend skeleton. Bun + Hono + `bun:sqlite` (zero network deps at runtime; TS runs natively, no build step). ## ⚡ START COMMAND (sticky) ```sh bun run dev # http://localhost:3000, hot reload ``` Other commands: ```sh bun run start # no watch bun run db:reset # wipe data.db and reseed bunx tsc --noEmit # typecheck ``` ## Layout ``` src/index.ts Hono app + routes src/db.ts opens data.db, applies schema, seeds if empty (runs on import) src/schema.sql customers / plans / subscriptions / invoices (idempotent) ``` DB is `data.db` at repo root (WAL, FK on). Boot always re-applies schema, so adding a table = edit schema.sql + restart. ## Routes ```sh curl localhost:3000/health curl localhost:3000/customers curl localhost:3000/customers/cus_ada/invoices curl -X POST localhost:3000/subscriptions \ -H 'content-type: application/json' \ -d '{"customer_id":"cus_grace","plan_id":"plan_basic"}' ``` `POST /subscriptions` is the happy path: validates with zod, creates subscription + first invoice in one transaction, returns both (201). ## Seed data - customers: `cus_ada`, `cus_grace` - plans: `plan_basic` ($10/mo), `plan_pro` ($50/mo) - `cus_ada` has an active `sub_1` on pro with open `inv_1` ## Extension cheatsheet (interview) - New route: add to `src/index.ts`, `db.query(...).all()/get()`, `db.run(sql, [params])` - Multi-write: `db.transaction(() => { ... })()` - Validation: `z.object({...}).safeParse(await c.req.json())` - New table: append `CREATE TABLE IF NOT EXISTS` to schema.sql, restart (or `db:reset` if changing existing tables)