Overview
tRPC provides end-to-end typesafe APIs for the DeltaHacks Portal. It eliminates the need for API contracts or code generation by leveraging TypeScript’s type inference.Why tRPC?
Benefits:- Full type safety - Types flow from server to client automatically
- No code generation - Uses TypeScript’s type inference
- Autocompletion - Full IDE support for API calls
- Runtime validation - Zod schemas validate inputs
- Small bundle size - No heavy dependencies
- Easy refactoring - Rename procedures safely across codebase
Router Structure
All tRPC routers are located insrc/server/router/.
App Router
The main router combines all sub-routers:Available Routers
application - Hacker Applications
application - Hacker Applications
Handles application submission, status checks, RSVP, and application data retrieval.Key Procedures:
getStatusCount- Get application status statistics (ADMIN/REVIEWER only)status- Get current user’s application statusqr- Get user’s QR codersvp- Submit RSVP and dietary restrictionssubmit- Submit new applicationget- Get current user’s applicationgetAll- Get all applications (ADMIN/REVIEWER only)
reviewer - Application Reviews
reviewer - Application Reviews
Manages application review workflows for reviewers.Key Procedures:
getNext- Get next application to reviewsubmitReview- Submit review score and commentgetReviewStats- Get reviewer statisticsgetAllReviews- Get all reviews for an application
user - User Management
user - User Management
User profile and account operations.Key Procedures:
getProfile- Get current user profileupdateProfile- Update user informationgetRoles- Get user roles
admin - Administration
admin - Administration
Admin-only operations for managing users and applications.Key Procedures:
updateApplicationStatus- Change application statusassignRole- Add/remove user rolesgetUserStats- Get platform statisticsexportApplications- Export applications as CSV
file - File Uploads
file - File Uploads
Resume uploads to Cloudflare R2.Key Procedures:
getUploadUrl- Get presigned upload URLconfirmUpload- Confirm file upload completion
judging - Project Judging
judging - Project Judging
Judging system for hackathon projects.Key Procedures:
submitProject- Submit a projectgetProject- Get project detailssubmitJudgingResult- Submit judging scoresgetRubric- Get rubric questions for a track
table - Judging Tables
table - Judging Tables
Manage physical judging tables.Key Procedures:
create- Create new tablegetAll- List all tablesassign- Assign table to track
track - Project Tracks
track - Project Tracks
Manage project categories/themes.Key Procedures:
create- Create new trackgetAll- List all tracksaddRubricQuestion- Add rubric question to track
project - Project Management
project - Project Management
Manage hackathon project submissions.Key Procedures:
create- Create projectupdate- Update project detailsgetAll- List all projectsassignTrack- Assign project to track
timeSlot - Judging Schedule
timeSlot - Judging Schedule
Schedule projects at tables.Key Procedures:
create- Create time slotgetSchedule- Get full judging schedulegetByTable- Get schedule for specific table
scanner - QR Code Scanner
scanner - QR Code Scanner
Event check-ins and meal tracking.Key Procedures:
checkIn- Check in user to eventserveMeal- Record meal servedgetUserInfo- Get user info from QR code
equipment - Equipment Tracking
equipment - Equipment Tracking
Hardware and sleeping bag checkout.Key Procedures:
checkOut- Check out equipmentreturnEquipment- Return equipmentgetHistory- Get equipment historygetCurrentCheckouts- Get active checkouts
tRPC Configuration
The tRPC instance is configured insrc/server/router/trpc.ts:
- SuperJSON - Serializes Date, Map, Set, undefined, and more
- Context - Includes session, Prisma client, LogSnag, PostHog
- Public Procedure - No authentication required
- Protected Procedure - Requires authenticated session
Context
The tRPC context provides shared resources to all procedures:session- NextAuth session (or null)prisma- Prisma database clientlogsnag- Event logging serviceposthog- Analytics service
Creating Procedures
Public Procedure
No authentication required:Protected Procedure
Requires authenticated user:Role-Based Authorization
Check user roles within procedures:Input Validation with Zod
Define input schemas for type safety and runtime validation:Mutations vs Queries
Query - Read operations, no side effects:Client Usage
Setup
The tRPC client is configured insrc/utils/trpc.ts (or similar):
React Hooks
useQuery - Fetch data:Optimistic Updates
Error Handling
Server-Side Errors
BAD_REQUEST- Invalid inputUNAUTHORIZED- Not authenticatedFORBIDDEN- Authenticated but not authorizedNOT_FOUND- Resource doesn’t existINTERNAL_SERVER_ERROR- Server error
Client-Side Error Handling
Advanced Patterns
Middleware
Create custom middleware for common logic:Batching
tRPC automatically batches requests made in the same render cycle:Server-Side Usage
Call tRPC procedures from server components or API routes:Testing
Unit Testing Procedures
Best Practices
Use Input Validation
Always define Zod schemas for inputs to ensure type safety and runtime validation.
Handle Errors Gracefully
Throw appropriate TRPCError codes and handle them properly on the client.
Leverage Type Safety
Let TypeScript infer types from your schemas - avoid manual type definitions.
Use Queries for Reads
Queries are cached and refetched automatically. Use mutations only for writes.
Implement Role Checks
Always verify user roles for protected operations.
Invalidate Queries
After mutations, invalidate related queries to keep data fresh.
See Also
- Architecture Overview - System architecture
- Database Schema - Prisma models
- Authentication - Auth system
- tRPC Documentation - Official tRPC docs