Cursor Rule: Back End
optics/cursor-rule-back-endFreeUtility
Cursor rule file for back-end development guidelines.
See it running
Open the demo on optics
optics.agusmayol.com.ar/components/cursor-rule-back-endInstall it
npx shadcn@latest add https://optics.agusmayol.com.ar/r/cursor-rule-back-end.jsonSource
1---2description: Rules for back-end development3globs: *.js, *.jsx, *.ts, *.tsx4alwaysApply: false5---6# Backend Development Rules78## Languages and Frameworks910Expert in Node.js, Express, Next.js API Routes, Server Actions, Route Handlers, Fastify, Prisma, Drizzle.1112Use JavaScript by default. Use TypeScript when explicitly requested or when project requires it.1314For monolithic Next.js apps, prefer Server Actions over API Routes when possible for better type safety and reduced boilerplate.1516## Next.js Backend Patterns1718Server Actions are the preferred way to handle mutations in Next.js 16:19```javascript20'use server'21export async function createUser(formData) {22 // Validate, process, return result23}24```2526Use Route Handlers (app/api) for:27- External API consumption28- Webhooks29- Non-form mutations30- Integrations with third-party services3132Server Actions provide automatic serialization, type safety, and progressive enhancement.3334Use "use cache" directive for caching expensive computations or data fetching.3536Always revalidate or update cache after mutations using updateTag() or revalidateTag().3738## Error Handling3940Wrap all async operations in try-catch blocks. Never let errors crash the server.4142Return structured error responses with appropriate HTTP status codes and messages.4344Create custom error classes for different error types (ValidationError, AuthError, NotFoundError).4546Good:47```javascript48try {49 const user = await db.user.findUnique({ where: { id } })50 if (!user) throw new NotFoundError('User not found')51 return user52} catch (error) {53 if (error instanceof NotFoundError) {54 return { error: error.message, status: 404 }55 }56 return { error: 'Internal server error', status: 500 }57}58```5960Log errors properly with context (user ID, request ID, timestamp) but never expose stack traces to clients.6162## Input Validation6364Validate all incoming data at the entry point. Never trust client input.6566Use validation libraries like Zod or Yup for schema validation:67```javascript68const userSchema = z.object({69 email: z.string().email(),70 age: z.number().min(18)71})7273const result = userSchema.safeParse(data)74if (!result.success) {75 return { error: result.error.flatten(), status: 400 }76}77```7879Validate types, formats, lengths, and business rules before processing.8081Sanitize HTML and SQL inputs to prevent injection attacks.8283Return clear validation errors that help clients fix issues without exposing system internals.8485## Authentication and Authorization8687// … truncated
Files it writes
More from optics
All 79 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Cursor Rule: Bulk Processingcursor-rule-bulk-processing | optics | Utilities | Free | no deps | |
| Cursor Rule: Commits Conventioncursor-rule-commits-convention | optics | Utilities | Free | no deps | |
| Cursor Rule: Front Endcursor-rule-front-end | optics | Utilities | Free | no deps | |
| Cursor Rule: Generalcursor-rule-general | optics | Utilities | Free | no deps | |
| Cursor Rule: React Optimizationcursor-rule-react-optimization | optics | Utilities | Free | no deps | |
| Cursor Rule: Web Interface Guidelinescursor-rule-web-interface-guidelines | optics | Utilities | Free | no deps | |
| Get strict contextget-strict-context | optics | Utilities | Free | no deps | |
| Use auto heightuse-auto-height | optics | Utilities | Free | no deps |
