📔 Developer Guidelines¶
Standard engineering, architecture, and git rules for every repo. Follow them unless a repo's own AGENTS.md adds stricter project-specific rules.
1. Definition of Done¶
A task is Done only when all of these are true:
- Running in production (or built and ready if it's a library/CLI).
- Verified end-to-end on the real deployment or preview — not just
localhost. - All checks pass: formatter, linter, typechecker, build, and automated tests (see testing-guidelines.md).
- Local AI review (when
coderabbitCLI is installed): runcoderabbit review --agent --uncommitted(or--base main) to catch bugs/security/slop before opening a PR. - Peripheral files updated in the same PR: README,
docs/,.env.example, schemas, and tests that belong to the change.
2. Change Categories & Review Discipline¶
| Category | Examples | Minimum Bar |
|---|---|---|
| Core infra / auth / billing / DB | Auth flows, webhooks, migrations, API gateways, shared libs | Strict commit style, unit + integration tests, CodeQL + security checklist review |
| Product features & UI | App Router pages, reusable components, forms, charts | Anti-slop UI check (ui-guidelines.md), 4 UI states, Playwright/a11y check |
| Non-core / one-off scripts | Event microsites, admin utilities, seeders | Clean modular code, no committed secrets, smoke-tested |
- Peripheral Files Rule: Keep docs,
.env.example, and tests in the same PR as the code they describe. Never leave documentation "for later." - API & App Boundaries:
- Prefer dedicated focused services (
api-*) over turning one legacyapimonolith into a kitchen sink. - Next.js: Always use the App Router (
app/). Never add new features topages/— migrate the route toapp/first.
3. Code Style & File Structure¶
- Zero noise: No dead code, commented-out blocks, unused imports, or stray
console.log/printstatements. - File size limit: Keep files focused and under ~300 lines. Split growing files into cohesive modules (
components/,hooks/,lib/,server/). - File naming:
- TypeScript / JavaScript:
kebab-case(user-profile.ts,use-debounce.ts,auth-guard.tsx), unless a framework explicitly requires otherwise (page.tsx,layout.tsx,route.ts). - Python:
snake_casefor files, functions, and variables;PascalCasefor classes. - TypeScript / JavaScript rules:
- Variables and functions in
camelCase; React components and types/interfaces inPascalCase. - Use strict equality (
===/!==), never loose equality (==/!=). - Prefer
async/awaitover raw.then()promise chains or nested callbacks. - Prefer standalone
functiondeclarations with named exports at definition (export async function ...). Only useexport defaultwhere the framework requires it (page.tsx,layout.tsx,next.config.*). - Prefer
if/elseearly returns and object lookup maps over sprawlingswitchblocks or deep nesting. - Use
for...offor async iteration or early exit; avoidArray.prototype.forEach()for async work. - No type-escape hatches: Never use
@ts-ignore,@ts-expect-error, or@ts-nocheck. Avoidany— useunknown+ Zod/type-guard narrowing. - Error handling: Never swallow errors with empty
catch {}blocks. Let pure helpers throw descriptive errors; catch at API/I/O/UI boundaries to map to clean HTTP status codes, logs, and user-safe states. - Comments: Explain why (invariants, edge cases, external constraints), never what. Keep inline comments concise; use docstrings/JSDoc on exported public modules and complex contracts.
4. Reusable Component & Module Architecture¶
Organize code by responsibility so UI, state, and business logic stay decoupled and reusable:
src/
components/
ui/ # Pure, domain-agnostic primitives (Button, Badge, Modal, EmptyState, DataTable)
features/ # Domain components composed from ui/ primitives — no raw fetch() inside JSX
hooks/ # Reusable client hooks (data fetching, form state, media queries)
lib/ # Pure business logic, Zod/Pydantic schemas, formatters, DB/API clients
app/ (or routes) # Thin route handlers & pages: validate input -> call lib/ -> return response
- Rule of Two: If a UI block, badge map, formatter, or fetch wrapper appears in 2+ places, extract it into a shared component or helper.
- Props composition over flag soup: Compose via
children, slots, andvariant/sizemaps (cva/ Tailwind) instead of adding 8 boolean mode flags to one component. - Single source of truth for types: Derive TS types from Zod / Prisma / Drizzle / Pydantic schemas (
z.infer<typeof ...>) rather than duplicating manual interfaces.
5. Standard Health Endpoint & Interactive API Docs¶
Every hosted web app or backend service must expose a machine-readable health route, and every service with API endpoints must expose interactive OpenAPI documentation:
Health Endpoint (GET /api/health or GET /health)¶
- Return HTTP
200when healthy and503when a backing dependency fails, withCache-Control: no-store: - Ping DB/cache dependencies with a strict bounded timeout (
<= 2s). Never leak secrets, connection strings, or stack traces. - Starter template for Next.js App Router:
stack-templates/health-route.ts.
Interactive API Docs (/api-docs or /docs)¶
Expose live OpenAPI documentation + JSON spec whenever the app has backend/API routes (skip empty API docs on pure static client-only apps):
| Stack | Docs URL | Spec URL | Standard Implementation |
|---|---|---|---|
| FastAPI (Python) | /docs (built-in) |
/openapi.json (built-in) |
Configure title, description, contact (https://tanisheesh.in), tags, and typed Pydantic response models |
| Next.js App Router | /api-docs |
/api/openapi.json |
Copy stack-templates/openapi-route.ts + stack-templates/api-docs-route.ts (Scalar viewer, zero extra deps) |
| Express (Node/TS) | /api-docs |
/openapi.json |
@scalar/express-api-reference or swagger-ui-express + swagger-jsdoc |
| Flask (Python) | /api-docs |
/openapi.json |
flasgger / flask-smorest or /openapi.json + standalone Scalar HTML viewer |
Go (net/http / gin) |
/api-docs |
/openapi.json |
Embed openapi.json via //go:embed + Scalar HTML handler (or swaggo) |
- Security: Public on portfolio/demo APIs with
BearerAuth/ApiKeyAuthschemes declared (never pre-fill credentials). Gate behind auth or dev-only onPrivate Product/Client Websiterepos unless public API docs are explicitly required.
6. Commits, Branches & Pull Requests¶
- Atomic commits: Split work into logical, reviewable units following commit-style.md. Avoid giant
"update"commits. - Secrets stay out of Git: Never commit
.env*files. Every new env var goes into.env.examplewith an empty value and source comment. mainis always deployable: Do larger features/refactors onfeat/,fix/,refactor/,docs/,chore/, ortest/branches and merge via PR.- PR hygiene: Use plain-English past-tense PR titles (no emojis/issue hashes in PR titles), check off the PR template, and ensure CI + CodeQL + Dependency Review + tests pass before merging.
7. Git & Production Safety¶
⚠️ No force-push or
git reset --hardonmain. Use feature branches/forks for history rewrites.⚠️ Rollbacks: When rolling back on Vercel, Render, or any host, immediately record the rollback reason and target SHA in a commit or PR so the next push does not silently re-ship the broken build.