Contract Kit
Define your API contract once. Get type-safe servers, typed clients, and runtime validation — no codegen.
import { createContractGroup } from "contract-kit";
import { z } from "zod";
const todos = createContractGroup().namespace("todos");
export const getTodo = todos
.get("/api/todos/:id")
.pathParams(z.object({ id: z.string() }))
.responses({ 200: z.object({
id: z.string(),
title: z.string(),
completed: z.boolean(),
}) });
Contract Kit is a contract-first TypeScript framework. You define a contract — the shape of an HTTP endpoint — and reuse it across your server, client, and validation layer. Everything stays in sync through TypeScript inference. No build step, no code generation.
How it fits together
- Define contracts for your HTTP surface.
- Implement routes with the server runtime. Requests and route-owned responses are validated against the contract.
- Keep infrastructure concerns in hooks and providers. Auth, logging, rate limits, and unexpected errors stay outside each route's business response union.
- Call the same contracts from the client. Use
call()for thrownContractErrors orsafeCall()for explicit result handling. - Put reusable business operations in the application layer when the same workflow needs to run from HTTP, jobs, scripts, or tests.
- Works with any Standard Schema library (Zod, Valibot, ArkType)
- First-class Next.js support via
@contract-kit/next - Optional React Query and React Hook Form integrations
- Provider system for databases, caching, auth, mail, and more
- OpenAPI generation is Zod-only
Contract Kit is pre-1.0. APIs may change between releases.