trpc-scaffolder
Scaffolds tRPC routers, procedures, and Zod schemas with full type safety following DevPrep AI patterns
What this skill does
# tRPC Scaffolder
Automate creation of type-safe tRPC endpoints with Zod validation.
**TL;DR**: Run scripts to create routers/schemas, register in `_app.ts`, validate with scripts.
---
## Auto-Triggers
Auto-triggered by keywords:
- "new endpoint", "create endpoint", "tRPC procedure"
- "new router", "API", "Zod schema"
---
## Quick Standards
### File Locations
```
lib/trpc/routers/
_app.ts # Register all routers here ⚠️
{name}.ts # Router files
lib/trpc/schemas/
{entity}.schema.ts # Zod schemas
```
### Router Pattern
```typescript
export const nameRouter = router({
doThing: publicProcedure
.input(inputSchema)
.output(outputSchema)
.mutation(async ({ input }) => { /* logic */ }),
});
```
### Schema Pattern
```typescript
export const inputSchema = z.object({
field: z.string().min(1),
});
export type Input = z.infer<typeof inputSchema>; // ⚠️ Required!
```
### Registration (Required!)
```typescript
// In _app.ts
export const appRouter = router({
ai: aiRouter,
name: nameRouter, // ⬅️ Add new routers here
});
```
---
## Run Scripts
### Create Router
```bash
./.claude/skills/trpc-scaffolder/scripts/create-router.sh user
# Creates: lib/trpc/routers/user.ts
# ⚠️ Remember to register in _app.ts!
```
### Add Procedure
```bash
./.claude/skills/trpc-scaffolder/scripts/add-procedure.sh ai getHints query
# Outputs code snippet to add to router
```
### Create Schema
```bash
./.claude/skills/trpc-scaffolder/scripts/create-schema.sh hint
# Creates: lib/trpc/schemas/hint.schema.ts
```
### Validate Setup
```bash
./.claude/skills/trpc-scaffolder/scripts/validate-trpc.sh
# Checks: router registration, type exports
```
---
## Quick Reference
### Query vs Mutation
| Type | Use For | Method |
|------|---------|--------|
| Query | Fetch data (GET) | `.query(async ({ input }) => ...)` |
| Mutation | Modify data (POST/PUT/DELETE) | `.mutation(async ({ input }) => ...)` |
### Common Zod Patterns
| Type | Pattern | Example |
|------|---------|---------|
| String | `z.string().min(1).max(100)` | Name validation |
| Number | `z.number().int().min(0).max(10)` | Difficulty 0-10 |
| Email | `z.string().email()` | Email validation |
| Optional | `z.string().optional()` | Optional field |
| Array | `z.array(z.string()).min(1)` | At least 1 item |
| Enum | `z.enum(["a", "b", "c"])` | Fixed choices |
| Object | `z.object({ field: z.string() })` | Nested object |
### Naming Conventions
- **Routers**: `{domain}Router` (e.g., `aiRouter`, `userRouter`)
- **Procedures**: `camelCase` (e.g., `generateQuestions`, `getHints`)
- **Schemas**: `{action}{Entity}{Input\|Output}Schema`
- **Files**: `{entity}.schema.ts`, `{domain}.ts`
### Error Codes
| Code | When | Example |
|------|------|---------|
| `NOT_FOUND` | Resource doesn't exist | User not found |
| `BAD_REQUEST` | Invalid input | Validation failed |
| `UNAUTHORIZED` | Not authenticated | Login required |
| `FORBIDDEN` | Not authorized | Access denied |
| `INTERNAL_SERVER_ERROR` | Server error | API failure |
---
## Common Fixes
### Router Not Registered
```typescript
// ❌ Forgot this step
// ✅ Add to _app.ts:
import { userRouter } from "./user";
export const appRouter = router({ ai: aiRouter, user: userRouter });
```
### Missing Type Exports
```typescript
// ❌ Schema without types
export const userSchema = z.object({ name: z.string() });
// ✅ Always export inferred types
export type User = z.infer<typeof userSchema>;
```
### Wrong Procedure Type
```typescript
// ❌ Using mutation for fetching data
getData: publicProcedure.mutation(...)
// ✅ Use query for GET operations
getData: publicProcedure.query(...)
```
### Schema Validation Error
```typescript
// ❌ No validation
field: z.string()
// ✅ Add constraints
field: z.string().min(1, "Field is required")
```
---
## When to Load Additional Docs
**SKILL.md is self-sufficient for:**
- Creating routers and schemas
- Running scripts
- Fixing common errors
**Load additional docs when needed:**
| Need | Load |
|------|------|
| Step-by-step tutorial | `docs/quick-start-guide.md` |
| Advanced Zod patterns | `docs/trpc-patterns.md` (lines 1-80) |
| Error handling strategies | `docs/trpc-patterns.md` (lines 150-220) |
| Testing procedures | `docs/trpc-patterns.md` (lines 220-270) |
| Context & middleware | `docs/trpc-patterns.md` (lines 80-150) |
**Code examples:**
- ✅ Perfect: `examples/good-router.ts`, `examples/good-schema.ts`
**Full project docs:** `Docs/api-design.md`, `Docs/api-transition/trpc-migration.md`
---
**Version:** 1.0.0 | **Updated:** October 2025
**Pattern**: Follows quality-reviewer structure (optimized)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.