Agent skill
new-router
Scaffold a new tRPC router with repository, interface, tests, and barrel exports following project conventions
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/new-router
SKILL.md
New Router Runbook
Files to Create
Given a domain name <domain> (e.g., "invoice"):
- Repository interface:
src/server/repositories/<domain>-repository.ts - Repository implementation: (in same file or separate)
- Router:
src/server/routers/<domain>.ts - Unit tests:
src/server/routers/__tests__/<domain>.test.ts - Register in app router:
src/server/routers/_app.ts
Repository Template
See src/server/CLAUDE.md for the full repository pattern. Key points:
- Implement an interface with typed methods
- Use
Partial<SchemaType>for update data (neverRecord<string, unknown>) - Always scope queries by
userId/ownerId - Return typed values (never
Promise<unknown>)
Router Template
See src/server/CLAUDE.md for the router template. Key points:
- Routers are thin controllers — data access through
ctx.uow - Use
protectedProcedurefor reads,writeProcedurefor mutations - Use
proProcedure/teamProcedurefor gated features - Always validate input with Zod schemas
- Use
.returning()on insert/update
Test Template
import { describe, it, expect, vi, beforeEach } from "vitest";
import { createMockUow } from "@/server/test-utils";
describe("<domain> router", () => {
const mockUow = createMockUow();
beforeEach(() => {
vi.clearAllMocks();
});
it("lists items for the owner", async () => {
// Arrange
mockUow.<domain>.findByOwner.mockResolvedValue([]);
// Act
const result = await caller.list();
// Assert
expect(result).toEqual([]);
});
});
Registration
Add to src/server/routers/_app.ts:
import { <domain>Router } from "./<domain>";
// In the router() call:
<domain>: <domain>Router,
Checklist
- Repository interface with typed methods
- Router with appropriate procedure types
- Unit tests covering list, get, create, update, delete
- Registered in
_app.ts - Input validation with Zod
- User scoping on all queries (
ctx.portfolio.ownerId)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?