Skip to main content

Overview

This section contains detailed API documentation for all Contract Kit packages. Each package has comprehensive documentation of its exports, types, and usage patterns.

Core API

contract-kit (meta package)

  • createContractGroup(), createClient(), createUseCaseFactory(), definePorts()
  • Re-exports core, client, application, domain, ports, errors, config, and OpenAPI helpers
View Meta Package →

@contract-kit/core

  • createContractGroup() - Create a group of related contracts
  • Contract builders - .get(), .post(), .put(), .patch(), .delete()
  • Schema methods - .path(), .query(), .body(), .response(), .errors()
  • Metadata methods - .meta(), plus OpenAPI helpers like .summary() and .tags()
View Core Package →

@contract-kit/server

  • createServer() - Create a framework-agnostic server
  • Middleware - Request pipeline and middleware support
  • Context - Request-scoped context creation
  • Error handling - Global and route-level error handlers
View Server Package →

@contract-kit/client

  • createClient() - Create a typed HTTP client
  • Request methods - Type-safe API calls
  • Response handling - Typed response handling
  • Configuration - Global and per-request options
View Client Package →

Server Adapters

@contract-kit/next

  • createNextServer() - Next.js server initialization
  • Route handlers - App Router and Pages Router support
  • Configuration - Next.js adapter options
View Next.js Adapter →

Architecture APIs

@contract-kit/application

  • createUseCaseFactory() - Create a typed use case factory
  • useCase.command() / useCase.query() - Define use cases
  • run() - Execute a use case
  • Validation - Input/output validation
View Application Package →

@contract-kit/ports

  • definePorts() - Define application ports
  • Provider registration - Register provider implementations
  • Type safety - Fully typed dependency injection
View Ports Package →

React APIs

@contract-kit/react-query

  • createRQ() - Create the React Query adapter
  • rq(contract).queryOptions() - Typed query options
  • rq(contract).mutationOptions() - Typed mutation options
  • Configuration - Query client setup
View React Query Integration →

@contract-kit/react-hook-form

  • rhf(contract) - Create a React Hook Form adapter
  • useForm() - Form hook with validation
  • Schema integration - Standard Schema resolver generation
View React Hook Form Integration →

Provider APIs

Each provider package exports:
  • create[Provider]Provider() - Factory function
  • Configuration options - Provider-specific config
  • Port interface - TypeScript interface for the port
Available Providers:

Utility APIs

@contract-kit/openapi

  • contractsToOpenAPI() - Generate OpenAPI 3.1 spec
  • Configuration - OpenAPI generation options
  • Customization - Extend generated spec
View OpenAPI Package →

Type Utilities

Contract Kit exports several type utilities for advanced use cases:
import type { InferInput, InferOutput, HttpContractConfig } from "@contract-kit/core";
import type { InferPath, InferQuery, InferBody } from "@contract-kit/server";
import type {
  InferSuccessResponse,
  InferPathParams,
  InferQuery as InferClientQuery,
  InferBody as InferClientBody,
} from "@contract-kit/client";

Next Steps