Imported from luisnoresv/books-api (
AGENTS.md). Install upstream withnpx skills add luisnoresv/books-api. Copyright stays with the author.
AGENTS.md
Repo facts
- This repo is a Bun + Hono + Drizzle + libSQL API for books.
- App entrypoint:
src/index.tsstarts the server withserve({ fetch: app.fetch, port }). - Main app wiring:
src/app.tsmounts routes under/apiand configures OpenAPI docs. - Route boundary: feature routes live in
src/routes/books/*; root route lives insrc/routes/index.route.ts. - Database schema is in
src/db/schema.ts; it includes both thebookstable and Better Auth tables. - Runtime alias: TypeScript path alias
@/*resolves to./src/*viatsconfig.jsonandvitest.config.ts.
Required setup
- Install deps:
bun install - Create a local
.envbefore running the server or Drizzle commands. The required runtime config is enforced insrc/env.ts:NODE_ENV(defaultdevelopment)PORT(default3000)LOG_LEVEL(must be one offatal|error|warn|info|debug|trace|silent)DATABASE_URL(required; usefile:dev.dblocally)DATABASE_AUTH_TOKENonly required whenNODE_ENV=production
- Example env file is
.env.example.
Commands that matter
- Start dev server:
bun run dev - Run all tests:
bun test(this script runsLOG_LEVEL=silent vitest) - Run one test file:
bunx vitest run src/routes/books/books.test.ts - Generate migrations:
bun run db:generate - Apply migrations:
bun run db:migrate - Push schema directly:
bun run db:push - Full DB setup shortcut:
bun run db:setup(this script currently callsnpm run db:push) - OpenAPI docs:
/api/docand/api/referenceonce the app is running
Architecture notes
src/lib/create-app.tsis the central app factory: it wires the favicon, logger, 404 middleware, global error handler, and auth passthrough for/api/auth/*.src/lib/configure-open-api.tsexposes the OpenAPI spec and Scalar reference UI.src/routes/books/books.routes.tsdefines the public route contracts;src/routes/books/books.handlers.tsimplements the actual CRUD logic.src/lib/error-handler.tscontains custom error classes and catch wrappers; keep route handlers consistent with these patterns.drizzle.config.tspoints at./src/db/schema.tsand usesdialect: 'turso'withcasing: 'snake_case'.
Working conventions
- Prefer changes that keep the OpenAPI route schema and the handler aligned; those files are intentionally split.
- When touching routes, update the matching Zod schema in
src/db/schema.tsand the route contract insrc/routes/books/books.routes.tstogether. - Tests are route-level checks, not DB integration tests; they validate status codes and schema validation behavior with Hono
testClient. - Do not assume the project is a typical Express app; it is built on Hono and uses
@hono/zod-openapiheavily. - If a change affects environment loading, verify
src/env.tsand.env.exampletogether; this repo validates env at startup.