> trpc
You are an expert in tRPC, the framework for building type-safe APIs without schemas or code generation. You help developers create full-stack TypeScript applications where the server defines procedures and the client calls them with full type inference — no REST routes, no GraphQL schemas, no OpenAPI specs, just TypeScript functions that are type-safe from database to UI.
curl "https://skillshub.wtf/TerminalSkills/skills/trpc?format=md"tRPC — End-to-End Type-Safe APIs
You are an expert in tRPC, the framework for building type-safe APIs without schemas or code generation. You help developers create full-stack TypeScript applications where the server defines procedures and the client calls them with full type inference — no REST routes, no GraphQL schemas, no OpenAPI specs, just TypeScript functions that are type-safe from database to UI.
Core Capabilities
Server
// server/trpc.ts — tRPC setup
import { initTRPC, TRPCError } from "@trpc/server";
import { z } from "zod";
const t = initTRPC.context<Context>().create();
export const router = t.router;
export const publicProcedure = t.procedure;
export const protectedProcedure = t.procedure.use(async ({ ctx, next }) => {
if (!ctx.session?.user) throw new TRPCError({ code: "UNAUTHORIZED" });
return next({ ctx: { user: ctx.session.user } });
});
// server/routers/users.ts
export const usersRouter = router({
getById: publicProcedure
.input(z.object({ id: z.string() }))
.query(async ({ input, ctx }) => {
const user = await ctx.db.users.findUnique({ where: { id: input.id } });
if (!user) throw new TRPCError({ code: "NOT_FOUND", message: "User not found" });
return user;
}),
list: publicProcedure
.input(z.object({
cursor: z.string().optional(),
limit: z.number().min(1).max(100).default(20),
}))
.query(async ({ input, ctx }) => {
const items = await ctx.db.users.findMany({
take: input.limit + 1,
cursor: input.cursor ? { id: input.cursor } : undefined,
orderBy: { createdAt: "desc" },
});
const hasMore = items.length > input.limit;
return { items: items.slice(0, input.limit), nextCursor: hasMore ? items[input.limit].id : undefined };
}),
update: protectedProcedure
.input(z.object({ name: z.string().min(1), bio: z.string().max(500).optional() }))
.mutation(async ({ input, ctx }) => {
return ctx.db.users.update({ where: { id: ctx.user.id }, data: input });
}),
});
// server/routers/_app.ts
export const appRouter = router({
users: usersRouter,
posts: postsRouter,
});
export type AppRouter = typeof appRouter;
React Client
import { trpc } from "@/utils/trpc";
function UserProfile({ userId }: { userId: string }) {
// Full type inference — hover shows return type from server
const { data: user, isLoading } = trpc.users.getById.useQuery({ id: userId });
const updateUser = trpc.users.update.useMutation({
onSuccess: () => utils.users.getById.invalidate({ id: userId }),
});
const utils = trpc.useUtils();
if (isLoading) return <Spinner />;
return (
<div>
<h1>{user?.name}</h1> {/* user is typed as User | undefined */}
<button onClick={() => updateUser.mutate({ name: "New Name" })}>
{updateUser.isPending ? "Saving..." : "Update"}
</button>
</div>
);
}
// Infinite scroll
function UserList() {
const { data, fetchNextPage, hasNextPage } = trpc.users.list.useInfiniteQuery(
{ limit: 20 },
{ getNextPageParam: (lastPage) => lastPage.nextCursor },
);
return (
<>
{data?.pages.flatMap(p => p.items).map(user => <UserCard key={user.id} user={user} />)}
{hasNextPage && <button onClick={() => fetchNextPage()}>Load More</button>}
</>
);
}
Installation
npm install @trpc/server @trpc/client @trpc/react-query @tanstack/react-query zod
Best Practices
- Zero code generation — Types flow from server to client via TypeScript inference; no build step needed
- Zod validation — Use
.input(z.object(...))for runtime validation; type-safe at compile AND runtime - React Query under the hood —
useQuery,useMutation,useInfiniteQueryall work; full caching - Procedure types —
queryfor reads,mutationfor writes,subscriptionfor WebSocket streams - Middleware — Chain middleware for auth, logging, rate limiting;
protectedProcedurepattern - Error handling — Use
TRPCErrorwith standard codes; client receives typed error responses - Batching — tRPC batches multiple queries into one HTTP request by default; reduces roundtrips
- Next.js integration — Use
@trpc/nextfor seamless App Router / Pages Router integration
> related_skills --same-repo
> zustand
You are an expert in Zustand, the small, fast, and scalable state management library for React. You help developers manage global state without boilerplate using Zustand's hook-based stores, selectors for performance, middleware (persist, devtools, immer), computed values, and async actions — replacing Redux complexity with a simple, un-opinionated API in under 1KB.
> zoho
Integrate and automate Zoho products. Use when a user asks to work with Zoho CRM, Zoho Books, Zoho Desk, Zoho Projects, Zoho Mail, or Zoho Creator, build custom integrations via Zoho APIs, automate workflows with Deluge scripting, sync data between Zoho apps and external systems, manage leads and deals, automate invoicing, build custom Zoho Creator apps, set up webhooks, or manage Zoho organization settings. Covers Zoho CRM, Books, Desk, Projects, Creator, and cross-product integrations.
> zod
You are an expert in Zod, the TypeScript-first schema declaration and validation library. You help developers define schemas that validate data at runtime AND infer TypeScript types at compile time — eliminating the need to write types and validators separately. Used for API input validation, form validation, environment variables, config files, and any data boundary.
> zipkin
Deploy and configure Zipkin for distributed tracing and request flow visualization. Use when a user needs to set up trace collection, instrument Java/Spring or other services with Zipkin, analyze service dependencies, or configure storage backends for trace data.