Skip to content

Blog API

A fast, typed blog API built for real-world delivery.

Purpose-built backend for a blog platform with a focus on speed, correctness, and a clean developer story. It is intentionally small, highly typed, and safe to extend.

  1. src/server.ts loads env config and builds a Fastify instance with Zod type providers.
  2. registerPlugins() wires CORS, database, auth, and routes under /api/v1.
  3. Requests flow: route -> controller -> service -> Drizzle ORM -> Turso.
  4. The server listens on 0.0.0.0:${PORT} (default 51214).
  5. In tests (NODE_ENV=test), the server does not auto-start.
Client -> /api/v1 -> routes -> controllers -> services -> db (Drizzle -> Turso)

Fastify

Lean request path and explicit plugin registration to keep latency predictable.

Clerk

Auth is delegated so the API never stores passwords and stays stateless.

Zod

Typed input/output contracts keep validation consistent at every boundary.

Turso + Drizzle

Edge-friendly SQLite with a type-safe query layer that is safe to evolve.

High-level endpoints and example requests live in the API surface page.

  • GET /api/v1/posts list posts with query support
  • GET /api/v1/posts/:slug fetch a post by slug
  • POST /api/v1/posts create a post (auth required)
  • GET /api/v1/categories list categories
  • GET /health health check
  • Typed validation at the edge with Zod
  • Public reads, protected writes with Clerk JWTs
  • Plugin order is explicit to keep startup predictable
  • Tests with Vitest + Supertest
Terminal window
npm install
npm run dev

See Run it locally for env vars, database tasks, and tests.