tRPC -- Skill Router
Decision Tree
What are you trying to do?
Define a tRPC backend (server)
Initialize tRPC, define routers, procedures, context, export AppRouter
-> Load skill: server-setup
Add middleware (.use), auth guards, logging, base procedures
-> Load skill: middlewares
Add input/output validation with Zod or other libraries
-> Load skill: validators
Throw typed errors, format errors for clients, global error handling
-> Load skill: error-handling
Call procedures from server code, write integration tests
-> Load skill: server-side-calls
Set Cache-Control headers on query responses (CDN, browser caching)
-> Load skill: caching
Accept FormData, File, Blob, or binary uploads in mutations
-> Load skill: non-json-content-types
Set up real-time subscriptions (SSE or WebSocket)
-> Load skill: subscriptions
Host the tRPC API (adapters)
Node.js built-in HTTP server (simplest, local dev)
-> Load skill: adapter-standalone
Express middleware
-> Load skill: adapter-express
Fastify plugin
-> Load skill: adapter-fastify
AWS Lambda (API Gateway v1/v2, Function URLs)
-> Load skill: adapter-aws-lambda
Fetch API / Edge (Cloudflare Workers, Deno, Vercel Edge, Astro, Remix)
-> Load skill: adapter-fetch
Consume the tRPC API (client)
Create a vanilla TypeScript client, configure links, headers, types
-> Load skill: client-setup
Configure link chain (batching, streaming, splitting, WebSocket, SSE)
-> Load skill: links
Use SuperJSON transformer for Date, Map, Set, BigInt
-> Load skill: superjson
Use tRPC with a framework
React with TanStack Query (useQuery, useMutation, queryOptions)
-> Load skill: react-query-setup
Next.js App Router (RSC, server components, HydrateClient)
-> Load skill: nextjs-app-router
Next.js Pages Router (withTRPC, SSR, SSG helpers)
-> Load skill: nextjs-pages-router
Advanced patterns
Generate OpenAPI spec, REST client from tRPC router
-> Load skill: openapi
Multi-service gateway, custom routing links, SOA
-> Load skill: service-oriented-architecture
Auth middleware + client headers + subscription auth
-> Load skill: auth
Quick Reference: Minimal Working App
// server/trpc.ts
import { initTRPC } from '@trpc/server';
const t = initTRPC.create();
export const router = t.router;
export const publicProcedure = t.procedure;
// server/appRouter.ts
import { z } from 'zod';
import { publicProcedure, router } from './trpc';
export const appRouter = router({
hello: publicProcedure
.input(z.object({ name: z.string() }))
.query(({ input }) => ({ greeting: `Hello ${input.name}` })),
});
export type AppRouter = typeof appRouter;
// server/index.ts
import { createHTTPServer } from '@trpc/server/adapters/standalone';
import { appRouter } from './appRouter';
const server = createHTTPServer({ router: appRouter });
server.listen(3000);
// client/index.ts
import { createTRPCClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../server/appRouter';
const trpc = createTRPCClient<AppRouter>({
links: [httpBatchLink({ url: 'http://localhost:3000' })],
});
const result = await trpc.hello.query({ name: 'World' });
See Also
server-setup -- full server initialization details
client-setup -- full client configuration
adapter-standalone -- simplest adapter for getting started
react-query-setup -- React integration
nextjs-app-router -- Next.js App Router integration
1---2name: trpc-router3description: Entry point for all tRPC skills. Decision tree routing by task: initTRPC.create(), t.router(), t.procedure, createTRPCClient, adapters, subscriptions, React Query, Next.js, links, middleware, validators, error handling, caching, FormData.4---56# tRPC -- Skill Router78## Decision Tree910### What are you trying to do?1112#### Define a tRPC backend (server)1314- **Initialize tRPC, define routers, procedures, context, export AppRouter**15 -> Load skill: `server-setup`1617- **Add middleware (.use), auth guards, logging, base procedures**18 -> Load skill: `middlewares`1920- **Add input/output validation with Zod or other libraries**21 -> Load skill: `validators`2223- **Throw typed errors, format errors for clients, global error handling**24 -> Load skill: `error-handling`2526- **Call procedures from server code, write integration tests**27 -> Load skill: `server-side-calls`2829- **Set Cache-Control headers on query responses (CDN, browser caching)**30 -> Load skill: `caching`3132- **Accept FormData, File, Blob, or binary uploads in mutations**33 -> Load skill: `non-json-content-types`3435- **Set up real-time subscriptions (SSE or WebSocket)**36 -> Load skill: `subscriptions`3738#### Host the tRPC API (adapters)3940- **Node.js built-in HTTP server (simplest, local dev)**41 -> Load skill: `adapter-standalone`4243- **Express middleware**44 -> Load skill: `adapter-express`4546- **Fastify plugin**47 -> Load skill: `adapter-fastify`4849- **AWS Lambda (API Gateway v1/v2, Function URLs)**50 -> Load skill: `adapter-aws-lambda`5152- **Fetch API / Edge (Cloudflare Workers, Deno, Vercel Edge, Astro, Remix)**53 -> Load skill: `adapter-fetch`5455#### Consume the tRPC API (client)5657- **Create a vanilla TypeScript client, configure links, headers, types**58 -> Load skill: `client-setup`5960- **Configure link chain (batching, streaming, splitting, WebSocket, SSE)**61 -> Load skill: `links`6263- **Use SuperJSON transformer for Date, Map, Set, BigInt**64 -> Load skill: `superjson`6566#### Use tRPC with a framework6768- **React with TanStack Query (useQuery, useMutation, queryOptions)**69 -> Load skill: `react-query-setup`7071- **Next.js App Router (RSC, server components, HydrateClient)**72 -> Load skill: `nextjs-app-router`7374- **Next.js Pages Router (withTRPC, SSR, SSG helpers)**75 -> Load skill: `nextjs-pages-router`7677#### Advanced patterns7879- **Generate OpenAPI spec, REST client from tRPC router**80 -> Load skill: `openapi`8182- **Multi-service gateway, custom routing links, SOA**83 -> Load skill: `service-oriented-architecture`8485- **Auth middleware + client headers + subscription auth**86 -> Load skill: `auth`8788## Quick Reference: Minimal Working App8990```ts91// server/trpc.ts92import { initTRPC } from '@trpc/server';9394const t = initTRPC.create();9596export const router = t.router;97export const publicProcedure = t.procedure;98```99100```ts101// server/appRouter.ts102import { z } from 'zod';103import { publicProcedure, router } from './trpc';104105export const appRouter = router({106 hello: publicProcedure107 .input(z.object({ name: z.string() }))108 .query(({ input }) => ({ greeting: `Hello ${input.name}` })),109});110111export type AppRouter = typeof appRouter;112```113114```ts115// server/index.ts116import { createHTTPServer } from '@trpc/server/adapters/standalone';117import { appRouter } from './appRouter';118119const server = createHTTPServer({ router: appRouter });120server.listen(3000);121```122123```ts124// client/index.ts125import { createTRPCClient, httpBatchLink } from '@trpc/client';126import type { AppRouter } from '../server/appRouter';127128const trpc = createTRPCClient<AppRouter>({129 links: [httpBatchLink({ url: 'http://localhost:3000' })],130});131132const result = await trpc.hello.query({ name: 'World' });133```134135## See Also136137- `server-setup` -- full server initialization details138- `client-setup` -- full client configuration139- `adapter-standalone` -- simplest adapter for getting started140- `react-query-setup` -- React integration141- `nextjs-app-router` -- Next.js App Router integration