A minimalist, RPC framework for TypeScript. Enables zero-overhead, end-to-end type safety between server and client by leveraging recursive type inference. This repository contains the complete framework source, multiple deployment adapters, and a comprehensive test suite.
- @tinyrpc/server: Core orchestration, procedure building, and runtime dispatch.
- @tinyrpc/client: Proxy-based client with functional link-chain architecture.
- @tinyrpc/react: Ergonomic React hooks built on TanStack Query.
initTRPC.create<TConfig>(): Initializes the framework. Accepts configuration forctx,meta, andtransformer.
.input(schema): Attaches a Zod or custom parser for incoming data..output(schema): Validates outgoing data before sending to the client..use(middleware): Chains recursive logic before the resolver..query(resolver): Definition for idempotent data fetching..mutation(resolver): Definition for state-changing operations..subscription(resolver): Definition for event-based streaming.
t.router({ ... }): Groups procedures into a logical tree.t.mergeRouters(r1, r2): Merges nested router definitions.t.middleware(fn): Defines reusable context/logic wrappers.
createTRPCProxyClient<Router>(opts): Creates the typed proxy.opts.links: An array of functional middleware (links).opts.transformer: Optional data serializer (e.g., handles Dates, BigInts).
httpLink: Unbatched Fetch-based transport.httpBatchLink: Merges concurrent requests to minimize network roundtrips.wsLink: Stateful WebSocket transport for real-timesubscriptionoperations.splitLink: Conditional routing based on operation type or path.retryLink: Resilient execution with jittered exponential backoff.cacheLink: Client-side caching with Stale-While-Revalidate (SWR).dedupeLink: Logic to prevent redundant inflight requests.loggerLink: Integrated observability for requests and responses.
trpc.useQuery([input], [opts]): Standard data fetching hook.trpc.useMutation([opts]): State mutation hook.trpc.useSubscription(onData, [opts]): Real-time streaming hook.trpc.useUtils(): Context utility for cache invalidation and manual state updates.
- Node.js:
createHTTPHandler(compatible withhttpandExpress). - Web/Edge:
fetchRequestHandler(compatible with Cloudflare Workers and Vercel Edge). - WebSockets:
applyWSHandler(Node.jswsintegration).
- basic-http (
examples/basic-http): Simple Node.js server using Fetch. - full-stack-ws (
examples/full-stack-ws): Bidirectional real-time communication. - analytics-dashboard (
examples/analytics-dashboard): High-load dashboard using Batching and SWR caching. - nextjs-app (
examples/nextjs-app): Integration with App Router and Turbopack. - edge-runtime (
examples/edge-runtime): Minimalist Cloudflare Worker deployment. - validation-test (
example/src/validation-test.ts): Technical demo of deep schema enforcement.
packages/server/src: Dispatcher, Router, Middleware, and Adapters.packages/client/src: Proxy, Links, Observables, and Error handling.packages/react/src: Query wrapper, context hooks.
README.md: Technical specification and API overview.TEST_REPORT.md: Consolidated test metrics.tsconfig.json: Monorepo-wide TypeScript configuration.package.json: Dependency management and scripts.
tests/run-all-tests.ts: Central test orchestrator.tests/core-functionality.ts: Foundation tests.tests/links-tests.ts: Link-chain logic verification.tests/react-hooks.ts: Frontend hook integrity checks.tests/comprehensive-benchmark.ts: Throughput and overhead measurements.
npm run test:allnpm run test:benchmark