Skip to main content

Build

Trpc Router

tRPCOfficialCertified

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.

  • New
  • v1.0.0
  • Reviewed Jul 21
  • No reviews yet

Getting started

Full instructions

Install the skill, then ask your AI tool for the task in plain words. The full SKILL.md below shows what it covers.

Instructions: SKILL.mdv1.0.0

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

ts
// server/trpc.ts
import { initTRPC } from '@trpc/server';

const t = initTRPC.create();

export const router = t.router;
export const publicProcedure = t.procedure;
ts
// 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;
ts
// server/index.ts
import { createHTTPServer } from '@trpc/server/adapters/standalone';
import { appRouter } from './appRouter';

const server = createHTTPServer({ router: appRouter });
server.listen(3000);
ts
// 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

Explore more skills

Browse all
This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

More from tRPC

View source →
non-json-content-typesHandle FormData, file uploads, Blob, Uint8Array, and ReadableStream inputs in tRPC mutations. Use octetInputParser from @trpc/server/http for binary data. Route non-JSON requests with splitLink and isNonJsonSerializable() from…2 installsvalidatorsConfigure input and output validation with .input() and .output() using Zod, Yup, Superstruct, ArkType, Valibot, Effect, or custom validator functions. Chain multiple .input() calls to merge object schemas. Standard Schema protocol…1 installsprinciple-encode-lessons-in-structureApply when you catch yourself writing the same instruction a second time, or notice a recurring correction. Encode the rule as a lint, metadata flag, runtime check, or script instead of more text.0 installstrpc-conventionstRPC's test setup and TypeScript conventions, which win where the generic pstack tdd, typescript-best-practices and principle-type-system-discipline skills disagree. Use when fixing a bug, writing or changing tests, or writing or reviewing…0 installsmiddlewaresCreate and compose tRPC middleware with t.procedure.use(), extend context via opts.next({ ctx }), build reusable middleware with .concat() and .unstable_pipe(), define base procedures like publicProcedure and authedProcedure. Access raw…0 installserror-handlingThrow typed errors with TRPCError and error codes (NOT_FOUND, UNAUTHORIZED, BAD_REQUEST, INTERNAL_SERVER_ERROR), configure errorFormatter for client-side Zod error display, handle errors globally with onError callback, map tRPC errors to…0 installs

Frequently asked questions about trpc-router

What does the trpc-router skill do?

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. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.

How do I install the trpc-router skill?

Run `npx @skills-hub-ai/cli install trpc-router` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/trpc-router/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.

Which AI tools does trpc-router work with?

trpc-router runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.

Is the trpc-router skill free?

Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.

How do I use trpc-router after installing it?

In Claude Code, type `/trpc-router` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.

Can I share the trpc-router skill with my team?

Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.

Badge for your README

Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.

Install on Skills Hub badge preview
Markdown
[![Install on Skills Hub](https://skills-hub.ai/api/badges/skill/trpc-router)](https://skills-hub.ai/skills/trpc-router)
HTML
<a href="https://skills-hub.ai/skills/trpc-router"><img src="https://skills-hub.ai/api/badges/skill/trpc-router" alt="Install on Skills Hub"></a>

More options in the badge docs.