Minimal Bun + React Router + React Query + Hono + Drizzle template.
- Install dependencies:
bun install-
Choose an app name and D1 database name, using lowercase letters and dashes.
-
Fill out
package.json:
- Set
nameto your package name. - Replace
DATABASE_NAMEindb:migrate:localanddb:migrate:remotewith your D1 database name.
- Fill out
wrangler.jsonc:
- Set
nameto your Worker name. - Set
database_nameinwrangler.jsoncunderd1_databasesto your D1 database name. - Create the database and copy the returned id into
database_idunderd1_databases:
bun x wrangler d1 create <database-name>- Regenerate Worker types after changing
wrangler.jsonc:
Git hooks and Worker types are installed/generated automatically during bun install. If needed, rerun them manually:
bun run prepare
bun run postinstallbun install
bun run dev- Use
src/lib/api-client.tsfor internal API calls from the client. - Use
apiQueryOptions(...)with React Query for reads. - Use
apiJson(...)for JSON mutations. - Avoid raw
fetch("/api/...")in pages/components unless the API client cannot cover the case. - Keep route modules in
src/pages. - Keep global providers and document shell in
src/root.tsx. - Keep API entrypoint wiring in
src/server/api.ts. - Add small API endpoints directly in
src/server/api.ts; when a domain grows, move it tosrc/server/<domain>.tsand mount it fromsrc/server/api.ts. - Return minimal API payloads. Prefer
{ data: ... }for success and{ error: { message } }for failures. - Read server bindings from Hono context (
c.env) and create DB clients withgetDb(c.env.DB). - Keep Drizzle schema in
src/server/db/schema.tsand DB setup insrc/server/db/index.ts. - Generate migrations with
bun run db:generate; do not hand-edit generated migrations unless intentionally reviewing generated output. - Keep styling simple in
src/globals.css; add design tokens only when the app actually needs them. - Add reusable components only when reuse exists; otherwise keep route-specific UI in the page file.
bun run dev— start local dev serverbun run build— build the appbun run lint— fix lint and formatting issues with Oxlint/Oxfmtbun run lint:check— check lint with Oxlintbun run format:check— check formatting with Oxfmtbun run prepare— install Lefthook Git hooksbun run postinstall— generate Worker typesbun run typecheck— run TypeScriptbun run db:generate— generate Drizzle migrationsbun run deploy— build and deploy with Wrangler
src/pages/home.tsx— stub home pagesrc/lib/api-client.ts— React Query-friendly API clientsrc/server/api.ts— base API routesrc/server/db/schema.ts— empty Drizzle schemasrc/worker.ts— Cloudflare Worker entry