Agent Skills: ChatJS tRPC patterns

Skill: trpc-patterns

UncategorizedID: FranciscoMoretti/sparka/trpc-patterns

Repository

FranciscoMorettiLicense: NOASSERTION
1,180111

Install this agent skill to your local

pnpm dlx add-skill https://github.com/FranciscoMoretti/chat-js/tree/HEAD/.agents/skills/trpc-patterns

Skill Files

Browse the full folder contents for trpc-patterns.

Download Skill

Loading file tree…

.agents/skills/trpc-patterns/SKILL.md

Skill Metadata

Name
trpc-patterns
Description
Implement ChatJS tRPC routers, TanStack Query hooks, mutations, and cache invalidation. Use when adding or changing tRPC procedures or their React consumers in apps/chat.

ChatJS tRPC patterns

Backend

  • Add feature routers under apps/chat/trpc/routers/*.router.ts and register them in apps/chat/trpc/routers/_app.ts.
  • Use protectedProcedure for authenticated operations.
  • Validate inputs with Zod and verify ownership before mutations.
  • Keep database access in apps/chat/lib/db/queries.ts.

React queries

Use useTRPC() with TanStack Query:

const trpc = useTRPC();
const query = useQuery({
  ...trpc.feature.list.queryOptions(),
  enabled: Boolean(condition),
});

For mutations, use generated mutation options and invalidate related keys after success:

const trpc = useTRPC();
const queryClient = useQueryClient();

const mutation = useMutation(
  trpc.feature.update.mutationOptions({
    onSuccess: () =>
      queryClient.invalidateQueries({
        queryKey: trpc.feature.list.queryKey(),
      }),
  })
);

Handle loading and error states in the consumer.