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.

25 stars

Best use case

tRPC — End-to-End Type-Safe APIs is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

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.

Teams using tRPC — End-to-End Type-Safe APIs should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/trpc/SKILL.md --create-dirs "https://raw.githubusercontent.com/ComeOnOliver/skillshub/main/skills/TerminalSkills/skills/trpc/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/trpc/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How tRPC — End-to-End Type-Safe APIs Compares

Feature / AgenttRPC — End-to-End Type-Safe APIsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

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.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 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

```typescript
// 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

```tsx
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

```bash
npm install @trpc/server @trpc/client @trpc/react-query @tanstack/react-query zod
```

## Best Practices

1. **Zero code generation** — Types flow from server to client via TypeScript inference; no build step needed
2. **Zod validation** — Use `.input(z.object(...))` for runtime validation; type-safe at compile AND runtime
3. **React Query under the hood** — `useQuery`, `useMutation`, `useInfiniteQuery` all work; full caching
4. **Procedure types** — `query` for reads, `mutation` for writes, `subscription` for WebSocket streams
5. **Middleware** — Chain middleware for auth, logging, rate limiting; `protectedProcedure` pattern
6. **Error handling** — Use `TRPCError` with standard codes; client receives typed error responses
7. **Batching** — tRPC batches multiple queries into one HTTP request by default; reduces roundtrips
8. **Next.js integration** — Use `@trpc/next` for seamless App Router / Pages Router integration

Related Skills

versioning-apis

25
from ComeOnOliver/skillshub

Implement API versioning with backward compatibility, deprecation notices, and migration paths. Use when managing API versions and backward compatibility. Trigger with phrases like "version the API", "manage API versions", or "handle API versioning".

typeorm-entity-generator

25
from ComeOnOliver/skillshub

Typeorm Entity Generator - Auto-activating skill for Backend Development. Triggers on: typeorm entity generator, typeorm entity generator Part of the Backend Development skill category.

throttling-apis

25
from ComeOnOliver/skillshub

Implement API throttling policies to protect backend services from overload. Use when controlling API request rates. Trigger with phrases like "throttle API", "control request rate", or "add throttling".

rate-limiting-apis

25
from ComeOnOliver/skillshub

Implement sophisticated rate limiting with sliding windows, token buckets, and quotas. Use when protecting APIs from excessive requests. Trigger with phrases like "add rate limiting", "limit API requests", or "implement rate limits".

monitoring-apis

25
from ComeOnOliver/skillshub

Build real-time API monitoring dashboards with metrics, alerts, and health checks. Use when tracking API health and performance metrics. Trigger with phrases like "monitor the API", "add API metrics", or "setup API monitoring".

mocking-apis

25
from ComeOnOliver/skillshub

Generate mock API servers for testing and development with realistic response data. Use when creating mock APIs for development and testing. Trigger with phrases like "create mock API", "generate API mock", or "setup mock server".

migrating-apis

25
from ComeOnOliver/skillshub

Implement API migrations between versions, platforms, or frameworks with minimal downtime. Use when upgrading APIs between versions. Trigger with phrases like "migrate the API", "upgrade API version", or "migrate to new API".

load-testing-apis

25
from ComeOnOliver/skillshub

Execute comprehensive load and stress testing to validate API performance and scalability. Use when validating API performance under load. Trigger with phrases like "load test the API", "stress test API", or "benchmark API performance".

generating-rest-apis

25
from ComeOnOliver/skillshub

Generate complete REST API implementations from OpenAPI specifications or database schemas. Use when generating RESTful API implementations. Trigger with phrases like "generate REST API", "create RESTful API", or "build REST endpoints".

chart-type-recommender

25
from ComeOnOliver/skillshub

Chart Type Recommender - Auto-activating skill for Data Analytics. Triggers on: chart type recommender, chart type recommender Part of the Data Analytics skill category.

fuzzing-apis

25
from ComeOnOliver/skillshub

This skill enables Claude to perform automated fuzz testing on APIs to discover vulnerabilities, crashes, and unexpected behavior. It leverages malformed inputs, boundary values, and random payloads to generate comprehensive fuzz test suites. Use this skill when you need to identify potential SQL injection, XSS, command injection vulnerabilities, input validation failures, and edge cases in APIs. Trigger this skill by requesting fuzz testing, vulnerability scanning, or security analysis of an API. The skill is invoked using the `/fuzz-api` command.

microsoft-typescript

25
from ComeOnOliver/skillshub

ALWAYS use when editing or working with *.ts, *.tsx, *.mts, *.cts files or code importing "typescript". Consult for debugging, best practices, or modifying typescript, TypeScript.