trpc

Implements end-to-end type-safe tRPC APIs with React Query and Next.js integration.

Updated Aug 15, 2025
One-click install
npx skills add https://github.com/yehezkieldio/topaz --skill trpc-yehezkieldio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: trpc
Source: https://github.com/yehezkieldio/topaz/tree/main/.agents/skills/trpc
Command: npx skills add https://github.com/yehezkieldio/topaz --skill trpc-yehezkieldio

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 full-stack TypeScript projects often requires duplicating type definitions, writing validation logic twice, and manually keeping client and server contracts in sync. This Skill provides comprehensive guidance for building tRPC APIs where types flow automatically from server to client without code generation. ## Core Features & Use Cases - Router and Procedure Patterns: Define queries, mutations, nested routers, and middleware with Zod input validation and context management. - React Query Integration: Use typed hooks for queries, mutations, optimistic updates, infinite scrolling, and real-time WebSocket subscriptions. - Next.js App Router Support: Covers server components, server actions, API route handlers, and client provider setup. - Use Case: When building a Next.js dashboard that needs authenticated CRUD endpoints, use this Skill to scaffold a protected tRPC router with Zod validation, auth middleware, and fully typed React Query hooks. ## Quick Start Ask the AI to create a tRPC router with a protected procedure, Zod input validation, and a React Query mutation hook for your Next.js app.

Frequently Asked Questions about trpc

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?

Create a fetchRequestHandler in app/api/trpc/[trpc]/route.ts exporting GET and POST handlers, then wrap your root layout with a client provider containing trpc.Provider and QueryClientProvider. Server components can call procedures directly via createCaller with a context object.

What is the difference between tRPC queries and mutations?

Queries are read operations sent via GET, cached by React Query, and idempotent. Mutations are write operations sent via POST, not cached, and used for database writes or side effects like sending emails.

tRPC vs REST vs GraphQL: which should I choose?

Choose tRPC for full-stack TypeScript monorepos where you control both client and server. Use REST for public language-agnostic APIs, and GraphQL for complex data graphs with multiple client types. tRPC is not suitable for non-TypeScript consumers.

How do I add authentication to tRPC procedures?

Create an isAuthed middleware that checks ctx.session and throws a TRPCError with UNAUTHORIZED code when missing. Build a protectedProcedure with t.procedure.use(isAuthed) so ctx.user is guaranteed and type-narrowed in all protected routes.

Does tRPC support real-time subscriptions?

Yes, tRPC supports subscriptions over WebSockets using wsLink on the client and applyWSSHandler on the server. Procedures return observables that emit events, consumed in React via the useSubscription hook.

When should I not use tRPC?

Avoid tRPC for public APIs consumed by non-TypeScript clients, polyglot microservices, or mobile apps in Swift/Kotlin. It also lacks OpenAPI documentation generation, making REST or GraphQL better for external developer platforms.