Buildml’s entire API layer is built on tRPC v11 — there are no traditional REST endpoints (except for the QStash webhook). Every procedure is fully type-safe end-to-end: your editor knows the exact input and output shape of every call before you ship a single line to production.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Praashh/buildml/llms.txt
Use this file to discover all available pages before exploring further.
Root Router
The root router is assembled insrc/server/api/root.ts and combines five sub-routers into a single appRouter export. The exported AppRouter type is the source of truth for all client-side type inference.
The
AppRouter type is exported and used by both ~/trpc/react and
~/trpc/server to infer inputs, outputs, and error shapes automatically. You
never need to write manual type definitions for API responses — TypeScript
propagates them from the router definitions.Available Routers
problem
Fetch individual problems and their metadata. Used to populate the challenge
editor view.
problemSet
Fetch collections of problems grouped into a problem set. Powers the
challenge browser and leaderboard pages.
submission
Run code against tests synchronously, or submit for permanent grading via
QStash. Includes a
getStatus query for polling results.user
Retrieve leaderboard rankings and individual user profiles. Useful for
building progress dashboards.
feedback
Submit user feedback on problems or the platform. No authentication required.
Procedure Types
Buildml defines two procedure types insrc/server/api/trpc.ts. Both include a timing middleware that logs execution duration and adds an artificial delay in development to surface loading states.
publicProcedure
No authentication required. Any visitor can invoke a public procedure.
protectedProcedure
Requires an active NextAuth session. If the caller is not signed in, tRPC throws a UNAUTHORIZED error before the resolver runs.
HTTP Transport
The tRPC handler is mounted at:httpBatchStreamLink with SuperJSON as the transformer, so complex types like Date, Map, and Set round-trip correctly between server and client. Requests from React Client Components carry the header x-trpc-source: nextjs-react; requests from React Server Components carry x-trpc-source: rsc.
Calling from the Server
In React Server Components, importapi from ~/trpc/server. This uses a direct server-side caller — no HTTP round-trip occurs.
HydrateClient helper exported from the same module lets you prefetch queries and dehydrate them into the React tree for client-side cache hydration.
Calling from the Client
In React Client Components, importapi from ~/trpc/react. This exposes the full @tanstack/react-query-backed hook API.
Input Validation
Every procedure input is validated with a Zod schema defined inline in the router. When validation fails, tRPC returns a structured error that includes the fullZodError flatten:
Error Codes
| Code | Meaning |
|---|---|
BAD_REQUEST | Input failed Zod validation or a required argument is missing |
UNAUTHORIZED | Caller is not signed in and the procedure is protected |
TOO_MANY_REQUESTS | Per-user rate limit exceeded (applies to run and submit) |
INTERNAL_SERVER_ERROR | Unexpected server-side failure |
Context
The tRPC context is created increateTRPCContext and is available to every resolver as ctx:
| Field | Type | Description |
|---|---|---|
ctx.prisma | PrismaClient | Database client |
ctx.session | Session | null | NextAuth session; guaranteed non-null in protectedProcedure |
ctx.headers | Headers | Incoming request headers |