Clean Code
Apply to every change. Read surrounding code first — match the author's style.
Core Rules
- Minimal scope — only change what the task requires
- No over-engineering — no abstractions for one-time use; three similar lines > premature helper
- Match conventions — naming, imports, error handling, response format, formatting
- Self-explanatory code — comments only for non-obvious business logic
- Meaningful names —
activeCategoriesnotdata;handleDeleteCategorynothandleClick
Backend (NestJS)
- Controllers thin — delegate to service, use response helpers
- Services:
try/catch→handleException; business errors →CustomHttpException - DTOs: global field decorators; barrel
dto/index.ts - Prisma: build
whereincrementally;Promise.allfor count + findMany
Frontend (React / Next.js)
- Server Components for fetch; Client for interactivity only
- Server state → React Query; global client → Zustand; URL →
useSearchParams - API in feature
api/folder; query key factories - Forms: Zod + RHF; files in separate
useState
Error Handling
| Layer | Pattern |
|---|---|
| Backend service | handleException(error, false, {}) |
| Backend business | CustomHttpException(message, status) |
| Frontend API | 401 interceptor; mutation onError → toast |
| Forms | showFormValidationToast |
Never
- Placeholder/lorem data in production code
- Empty
catch {}blocks - Business logic in controllers or JSX
- God files (600-line routers, 500-line services)
- Unrelated file changes
anyunless unavoidable (file fields, JSON settings)
Review Checklist
- Smallest diff that solves the problem
- Matches surrounding patterns
- Error cases handled
- No dead code / unused imports
- Bilingual fields paired (
_en/_ar) if localized entity
Refactor only when asked or required by the task — not proactively.