This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This project uses pnpm 10.9.x as the package manager. The version is enforced via:
packageManagerfield in package.jsonenginesfield requiring^10.9.0.npmrcwithengine-strict=true
- Build:
pnpm build- Builds both CJS and ESM versionspnpm build:cjs- TypeScript compilation for CommonJSpnpm build:esm- TypeScript compilation for ESM with js2mjs conversion
- Watch:
pnpm watch- Runs both CJS and ESM builds in watch mode - Test:
pnpm test- Runs tests with Vitest - Type Check:
pnpm typecheck- TypeScript type checking without emitting - Lint & Format:
pnpm lint:check- Check for linting issues with Biomepnpm lint- Fix linting issues automatically with Biomepnpm format:check- Check formatting with Biomepnpm format- Format code with Biome
- Make Linkable:
pnpm make-lib-linkable- Builds and prepares for local linking
Shared-routes is a TypeScript library that provides type-safe REST API route definitions and client/server utilities. The architecture follows a modular approach with separate integrations for different HTTP clients and server frameworks.
src/defineRoutes.ts: Central route definition system using Zod schemas for validationsrc/configureCreateHttpClient.ts: Base HTTP client configuration and typessrc/pathParameters.ts: URL path parameter handling and type extractionsrc/standardSchemaUtils.ts: Schema validation utilities compatible with StandardSchema
src/axios/: Axios HTTP client integrationsrc/fetch/: Native fetch API integrationsrc/supertest/: Testing utilities with Supertest
src/express/: Express.js router integration with validation middleware
src/openapi/: OpenAPI specification generationsrc/createCustomSharedClient.ts: Generic client creation for custom HTTP implementations
The library uses a declarative approach where routes are defined with:
- HTTP method and URL pattern
- Request/response schemas using StandardSchema (Zod compatible)
- Type-safe path parameters extracted from URL patterns
- Validation middleware for server-side implementations
- Type-safe client generation for frontend consumption
The project uses dual-package exports supporting both CommonJS and ESM:
- Main TypeScript config builds to
dist/(CommonJS) - ESM config (
tsconfig.esm.json) builds todist/esm/with.mjsextensions - Package exports defined in
package.jsonfor proper module resolution
Uses Vitest with test files in test/ directory covering:
- Route definition and validation
- Client implementations (Axios, Fetch)
- Server integration (Express, Supertest)
- OpenAPI generation