ToolScout
Templates
Home/API Layer/tRPC
API Layer
trpc

tRPC

TypeScriptOpen SourceFree tier

End-to-end typesafe APIs for TypeScript monorepos. Eliminates the need for code generation or a schema — your TypeScript types ARE your API contract. Pairs perfectly with Next.js.

License

MIT

Language

TypeScript

Used for

API Layer
87
Trust
Strong

Why tRPC?

Full-stack TypeScript monorepo (Next.js, SvelteKit)

You want autocomplete on API calls without a separate schema step

Small-to-medium team that wants to move fast without REST boilerplate

Signal Breakdown

What drives the Trust Score

Weekly npm downloads
3.2M/wk
GitHub commits (90d)
120
GitHub stars
35k
Stack Overflow questions
8k
Community health
Very Active
Weighted Trust Score87 / 100

Download Trend

Last 12 months

Tradeoffs & Caveats

Know before you commit

Public API consumed by non-TypeScript clients

Large polyglot team — REST/GraphQL are language-agnostic

Microservices that communicate across repos

Pricing

Free tier & paid plans

Free tier

Open source, free forever

Paid

N/A

MIT license

Alternative Tools

Other options worth considering

apollo-graphql
Apollo GraphQL45Limited

The industry-standard GraphQL server (Apollo Server) and client (Apollo Client). Provides a complete solution for building and consuming GraphQL APIs, with caching, subscriptions, and Apollo Studio for monitoring.

View Compare
See all alternatives to tRPC

Often Used Together

Complementary tools that pair well with tRPC

nextjs

Next.js

Frontend & UI

98Excellent
View
zod

Zod

API Layer

93Excellent
View
prisma

Prisma

Database & Cache

88Strong
View
supabase

Supabase

Database & Cache

95Excellent
View
drizzle

Drizzle ORM

Database & Cache

37Limited
View

Learning Resources

Docs, videos, tutorials, and courses

tRPC Docs

docs

GitHub repo

github

tRPC quickstart

tutorial

Get Started

Repository and installation options

View on GitHub

github.com/trpc/trpc

npmnpm install @trpc/server @trpc/client @trpc/react-query

Quick Start

Copy and adapt to get going fast

import { initTRPC } from '@trpc/server';
import { z } from 'zod';

const t = initTRPC.create();

export const appRouter = t.router({
  getUser: t.procedure
    .input(z.object({ id: z.string() }))
    .query(async ({ input }) => {
      return db.users.findUnique({ where: { id: input.id } });
    }),
  createPost: t.procedure
    .input(z.object({ title: z.string(), body: z.string() }))
    .mutation(async ({ input }) => {
      return db.posts.create({ data: input });
    }),
});

export type AppRouter = typeof appRouter;

Code Examples

Common usage patterns

Protected procedure

Add authentication middleware to a tRPC procedure

// server/trpc.ts
import { initTRPC, TRPCError } from '@trpc/server';
import { getServerSession } from 'next-auth';

const t = initTRPC.context<{ session: Session | null }>().create();

const isAuthed = t.middleware(({ ctx, next }) => {
  if (!ctx.session?.user) throw new TRPCError({ code: 'UNAUTHORIZED' });
  return next({ ctx: { session: ctx.session } });
});

export const protectedProcedure = t.procedure.use(isAuthed);

Infinite scroll with tRPC

Paginated query with cursor-based pagination

// server/router.ts
import { z } from 'zod';

export const postRouter = router({
  list: publicProcedure
    .input(z.object({ cursor: z.string().optional(), limit: z.number().default(10) }))
    .query(async ({ input }) => {
      const posts = await db.posts.findMany({
        take: input.limit + 1,
        cursor: input.cursor ? { id: input.cursor } : undefined,
        orderBy: { createdAt: 'desc' },
      });
      const nextCursor = posts.length > input.limit ? posts.pop()!.id : undefined;
      return { posts, nextCursor };
    }),
});

Community Notes

Real experiences from developers who've used this tool