| name | orpc |
| description | Type-safe API endpoints with oRPC framework. Use when creating or modifying procedures, middleware composition, validation, and error handling. |
oRPC Procedures
Type-safe API endpoint patterns with oRPC (Object-oriented RPC).
- Use
authProcedure for authenticated endpoints; add middleware for authorization
- Always use
NOT_FOUND (never FORBIDDEN) to prevent resource enumeration
- Set
createdAt/updatedAt on insert; update only updatedAt on update
- Use
.returning() and check for null after insert/update/delete
- Filter queries by tenant even after middleware checks (defense in depth)
- Use consistent ID generation across procedures (UUID, ULID, nanoid)
- Validate tenant context in procedures requiring tenant scope
- Include pagination (limit, offset) on list procedures
- Use Zod for input validation; keep schemas near procedure definitions
- Stack middleware in logical order: auth → authorization → business logic