tRPC Core Concepts Overview
Get a high-level overview of tRPC's architecture, including routers, procedures, and context.
tRPC Core Concepts Overview is a free tRPC End-to-End Type Safe APIs lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the tRPC End-to-End Type Safe APIs learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
tRPC Core Concepts Intro
Time for tRPC's building blocks. We'll cover routers (how the API is organized), procedures (the functions clients call), and context (per-request data).
tRPC Flow: Client to Server
The tRPC flow: the client calls a procedure, the router routes it, the procedure runs (often using context), and a typesafe response goes back to the client.
Meet tRPC Routers
Routers are the backbone of a tRPC API. They group related procedures into modules, define your API structure, and can be merged into one full API.
Simple Router Structure
A router is just an object holding your callable functions. Here's a conceptual sketch of a minimal user router you'll fill with procedures.
import { router, publicProcedure } from '../trpc';
// This is a conceptual router definition.
// 'router' and 'publicProcedure' would be defined in your tRPC setup file.
export const userRouter = router({
// All user-related procedures will be defined here
// e.g., 'getUser', 'createUser', 'updateUser'
});Understanding Procedures
Procedures are the actual functions your client calls — your API endpoints. Each defines its input, its output, and the server-side business logic.
Queries for Data Fetching
A query procedure fetches data. It should be read-only and idempotent — same input, same result — making it ideal for client-side caching. Like an HTTP GET.
Basic Query Procedure
Here's a conceptual query that fetches a user by ID: it declares an input and returns a user object.
// Inside your userRouter (from previous scene)
// This procedure gets a user by ID.
getUserById: publicProcedure
.input(z.string()) // Expects a string (the user ID)
.query(({ input }) => {
// In a real app, you'd fetch from a database here.
// For now, imagine we're returning a simple object.
return { id: input, name: "Jane Doe", email: "jane@example.com" };
}),Mutations for Data Changes
A mutation changes data — create, update, delete. It has side effects and isn't idempotent, so repeated calls can differ. Like an HTTP POST, PUT, or DELETE.
tRPC Context Explained
Context is built once per request and passed to every procedure in it. It's where you stash request-scoped data like the auth user or a DB connection.
Core Concepts Check
Let's quickly check your understanding of tRPC's core building blocks.
Core Concepts Recap
Recap: routers organize the API, procedures (queries for reads, mutations for writes) do the work, and context shares per-request data. Next: your first project.
Frequently asked questions
Is the “tRPC Core Concepts Overview” lesson free?
Yes — the full text of “tRPC Core Concepts Overview” is free to read here on the web, and the tRPC End-to-End Type Safe APIs course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the tRPC End-to-End Type Safe APIs course, upgrade to CoddyKit PRO.
What will I learn in “tRPC Core Concepts Overview”?
Get a high-level overview of tRPC's architecture, including routers, procedures, and context. You practise tRPC End-to-End Type Safe APIs with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start tRPC End-to-End Type Safe APIs?
No prior experience is required. tRPC End-to-End Type Safe APIs on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “tRPC Core Concepts Overview” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this tRPC End-to-End Type Safe APIs lesson?
Yes. Every tRPC End-to-End Type Safe APIs lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What is tRPC?
- The Power of Type Safety
- tRPC Core Concepts Overview
- Setting Up Your First tRPC Project