trpc-fullstack

Build end-to-end type-safe APIs with tRPC routers, procedures, and Next.js integration.

1|Updated Aug 17, 2025
One-click install
npx skills add https://github.com/ratnesh-maurya/mdconverter --skill trpc-fullstack-ratnesh-maurya
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: trpc-fullstack
Source: https://github.com/ratnesh-maurya/mdconverter/tree/main/.claude/skills/trpc-fullstack
Command: npx skills add https://github.com/ratnesh-maurya/mdconverter --skill trpc-fullstack-ratnesh-maurya

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @trpc/server, @trpc/client, @trpc/react-query, @tanstack/react-query, zod.

What problem does it solve? Building APIs in TypeScript full-stack apps often means duplicating type definitions between server and client, writing REST boilerplate, or maintaining GraphQL schemas. This Skill guides you through creating tRPC APIs where TypeScript types flow automatically from server router to client, giving you autocomplete, compile-time validation, and refactoring safety without code generation. ## Core Features & Use Cases - Router and Procedure Design: Create queries, mutations, and subscriptions with Zod-validated inputs, organized into domain routers merged into a root AppRouter. - Auth Middleware and Context: Build protected procedures with middleware that enforces authentication and narrows session types, using separate context factories for App Router handlers and Server Components. - React Query Client Integration: Set up the tRPC React client with httpBatchLink, cache invalidation after mutations, and WebSocket subscriptions for real-time features. - Use Case: You are building a Next.js app and need a posts API. Use this Skill to scaffold the server router with cursor pagination, protect mutations behind auth middleware, and consume everything from React components with fully typed useQuery and useMutation hooks. ## Quick Start Set up a tRPC API in my Next.js app with a protected posts router, Zod input validation, and a React Query client provider.

Frequently Asked Questions about trpc-fullstack

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up tRPC with Next.js App Router?

Use fetchRequestHandler from @trpc/server/adapters/fetch in a route handler at app/api/trpc/[trpc]/route.ts, passing your appRouter and a fetch-based context factory. Export the handler as both GET and POST, then create a React client with createTRPCReact typed by your AppRouter.

How do I add authentication to tRPC procedures?

Create a middleware that checks ctx.session and throws TRPCError with code UNAUTHORIZED when no user exists, then build a protectedProcedure with t.procedure.use(enforceAuth). The middleware can extend the context so downstream procedures receive a non-null typed session.

tRPC vs GraphQL for a TypeScript full-stack app?

tRPC shares TypeScript types directly between server and client with no schema or code generation, making it ideal for monorepos where both sides share a codebase. GraphQL suits public APIs or cross-language clients where a schema contract is required.

Why is my tRPC session null in protected procedures?

The context factory is likely receiving the wrong request shape, such as a Pages Router req/res cast in an App Router handler. Ensure createTRPCContext uses FetchCreateContextFnOptions and calls your server-side auth helper like Next-Auth v5 auth() directly.

Does tRPC support real-time subscriptions?

Yes, tRPC supports subscriptions using observables over WebSockets. Configure the client with splitLink so subscriptions route to wsLink while queries and mutations use httpBatchLink, and define subscription procedures returning an observable.

Why are mutations not updating the UI in tRPC?

React Query caches query results, so the UI stays stale after a mutation succeeds. Call utils.<router>.<procedure>.invalidate() inside the mutation's onSuccess callback to trigger a refetch of the affected queries.