tRPC API
Type-safe RPC for first-party clients.
For internal communication between our Fastify server and our TypeScript clients (apps/web and apps/client), Waylog utilizes tRPC.
Why tRPC?
tRPC provides absolute end-to-end type safety. If the database schema changes, or a server route requires a new parameter, the TypeScript compiler will immediately flag errors in the React frontend during the build process, eliminating an entire class of runtime bugs.
Router Architecture
To prevent circular dependencies, all tRPC routers and type definitions are housed in the shared packages/api workspace package, rather than directly inside the server application.
Core Routers
jobsRouter: Queries for historical job logs, statistical aggregations, and paginated delivery histories.usersRouter: Mutations for updating profile settings, theme preferences, and linking gaming identities.vtcRouter: Comprehensive endpoints for creating VTCs, updating company metadata, and reviewing recruitment applications.permissionsRouter: Specialized procedures that evaluate the 64-bit FGAC bitmasks to render UI elements conditionally based on the user's effective permissions.
Context Injection
Every tRPC request is intercepted by our Fastify adapter to inject context:
export interface Context {
user: {
id: string;
sessionId: string;
} | null;
db: DrizzleDatabase;
}If a procedure requires authentication, it utilizes tRPC middleware to assert that ctx.user is not null, throwing a TRPCError({ code: 'UNAUTHORIZED' }) before the business logic executes.