tRPC Conventions
Settled — do not re-propose
- A rule for the procedure builder — which of the three a route takes is a policy question about the route's data; the decidable rules are the
trpc-procedureplugin's (scripts/src/oxlint/trpcProcedure.ts). - Following tRPC's own skills (
pnpm-@trpc+*) where they differ from this one — they cover every adapter and client setup in general; this repo's server and client wiring is thetrpc-nuxt-modulepackage's, and where the two disagree this skill wins. - A rule that the client path mirrors the file path — needs both trees, so it would be a test walking them rather than a lint rule.
Deep dives
references/router-tests.md— when writing or reviewing a test that drives a tRPC caller.references/subscriptions.md— when a change must reach another client, or deciding whether the caller of a mutation also updates its own store.references/read-endpoints.md— when writing aread*procedure, its pagination input schema, or theuseRead*composable that calls it.references/blob-mutations.md— when a mutation deletes or replaces a blob, or saves a blob a client read.references/procedure-arity.md— when a procedure acts on an entity, or a surface starts acting on a set of them.references/file-placement.md— when adding an input schema, a server helper, a shared service or a live event.references/client-calls.md— when client code calls a procedure.references/router-structure.md— when adding a router, a sub-router or a key, or mapping routers and stores to tables.references/procedure-naming.md— when naming a procedure, a result type, a socket event or a DB result variable.references/room-procedures.md— when writing a room-scoped procedure or choosing its builder.references/ownership-guards.md— when a mutation must touch only the caller's or the room's row, or a router file is about to hold a helper.
Procedures
- Return type generic on the method, not as a callback return annotation —
readFoos: standardAuthedProcedure.query<Foo[]>(async ({ ctx }) => { ... }). Same for.mutation<T>(...). - A procedure that returns nothing still writes
<void>. The generic pins a public API surface, so a handler that later grows areturnis a compile error rather than a silently widened response every client can now read.typescript/no-invalid-void-typeis off for exactly this: a generic type argument is a position upstream allows by default, oxlint does not implement that option, and the config yields rather than the correct call sites. - One entity until a caller acts on a set, then a batch that replaces it. Never a single and a batch procedure for the same operation: promotion deletes the single one, and its one-item callers send one id (
references/procedure-arity.md). - A body that can outgrow
MAX_REQUEST_SIZEis committed by reference, never carried under a raised limit — uploaded to an R2 bucket through a presigned PUT and named to a small mutation that reads and verifies it, as a staged content save is (openspec/specs/architecture/file-uploads/design.md). - Omit
asyncwhen there is noawait— e.g. a body that onlyreturns a Drizzle query chain.
Where the Pieces Live
One input schema file per procedure under shared/models/db/<feature>/, even for identical shapes; helpers one per file under server/services/<feature>/, a store-shared one under shared/services/, a Functions-shared query under packages/db, and a live event's union under packages/db-schema/src/models/realtime/ (references/file-placement.md).
Client-Side Calling Conventions
Every user-facing read and write goes through useQuery/useMutation; never a bare {} input (trpc-procedure/no-empty-input); an empty optional id is omitted and an empty required one returns early; a reader-sized list in a query's input is read in chunks, since it rides the URL (references/client-calls.md).
Live updates are not tRPC subscriptions. The rule, and how a client takes a frame, is references/subscriptions.md.
Router Structure
The client path mirrors the file path; sub-routers compose in the feature's index.ts through a base*Router; no Function.prototype name is a key (trpc-procedure/no-prototype-key) (references/router-structure.md).
Procedure & Result Naming
Every query names its verb — read*, search*, generate* (trpc-procedure/require-query-verb), a count is read*Count, a result type ends in Result, upsert* for an upsert, and a socket event's type is named for the write that sends it (references/procedure-naming.md).
Procedure Helpers (Room RBAC)
getMemberProcedure or getPermissionsProcedure from server/trpc/procedure/room/, and a read takes the builder its data deserves, never the one its caller's UI implies (references/room-procedures.md).
Ownership Guards in Mutations
ownedBy(table, id, userId) and inRoom(table, id, roomId), never a hand-written and(eq…); a router file holds its router({ ... }) and nothing else (references/ownership-guards.md).
Router and Store Structure
One router and one Pinia store per table, named after the table (references/router-structure.md).
Error Handling
BAD_REQUESTalways carries a message, and the router never assembles it —throw getInvalidOperationError(Operation.X, EntityType, context)fromserver/trpc/guards/, picking theOperationmatching the procedure (Operation.Readfor a query;Create/Update/Deletefor mutations), the entity type, and acontextidentifying the invalid value (JSON.stringify(input), the relevant ID). A missing entity isgetNotFoundError; the constructors and the one bare code are owned by.agents/skills/error-handling/references/server-guards.md.- The
if/else ifchain rule in.agents/skills/typescript/references/control-flow.mdapplies inside procedure bodies: an early-exitifthat throws is followed byelse if, even when the conditions are logically independent.