|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +Conventions and guidance for working in this repo. Keep this file short — it loads into every Claude session. |
| 4 | + |
| 5 | +## Stack |
| 6 | + |
| 7 | +- Next.js 16 (App Router), React 19, TypeScript 5.8 |
| 8 | +- PostgreSQL via raw `pg` (no ORM). Migrations are hand-written SQL in `/migrations/`. |
| 9 | +- Playwright for e2e tests; ESLint 9 for linting; no Prettier. |
| 10 | + |
| 11 | +## Naming convention: `snake_case` end-to-end |
| 12 | + |
| 13 | +The database is `snake_case`. To eliminate boundary-translation bugs (the kind where a column rename silently breaks a route), we mirror that everywhere data crosses a wire: |
| 14 | + |
| 15 | +- **DB columns**: `snake_case` (Postgres native) |
| 16 | +- **TS model interfaces** (e.g. `ContactData`, `User`): properties match column names — `grid_locator`, not `gridLocator` |
| 17 | +- **API JSON response fields**: `snake_case` — `{ grid_locator: ... }` |
| 18 | +- **API request bodies**: `snake_case` keys |
| 19 | + |
| 20 | +**Exempt from this rule:** |
| 21 | + |
| 22 | +- React component-local form state (`formData.gridLocator`) — purely internal, never crosses the wire. The translation happens at the `fetch()` call site. |
| 23 | +- Internal helper function parameters (e.g. `buildLoTWDownloadUrl({ dateFrom, dateTo })`) — not API surface, just JS function args. |
| 24 | + |
| 25 | +**Known still-drifting surfaces** (cleanup candidates, not blockers): |
| 26 | + |
| 27 | +- `GET /api/contacts/search` query params (`gridLocator`, `startDate`, `endDate`, `qslStatus`) still use camelCase. Defer to a follow-up sweep. |
| 28 | + |
| 29 | +## Error response shape |
| 30 | + |
| 31 | +API routes return: |
| 32 | + |
| 33 | +```ts |
| 34 | +{ error: string } |
| 35 | +``` |
| 36 | + |
| 37 | +with an appropriate HTTP status (400 client error, 401 unauthorized, 403 forbidden, 404 not found, 500 server error). Some routes return richer shapes (`{ success: boolean, error?: string, ... }`) — that's fine where it's already established, but new routes should default to the simple shape. |
| 38 | + |
| 39 | +## Logging |
| 40 | + |
| 41 | +- `console.log` in `src/` is being phased out — don't add new ones. (Lint rule coming in a follow-up PR.) |
| 42 | +- `console.error` is acceptable in genuine error paths until a real logger is introduced. |
| 43 | + |
| 44 | +## Type discipline |
| 45 | + |
| 46 | +- **No `any`**. The codebase is currently clean of explicit `: any` — keep it that way. If you genuinely don't know a type, use `unknown` and narrow at the use site. |
| 47 | +- Run `npm run typecheck` (alias for `tsc --noEmit`) before committing. It must pass. |
| 48 | + |
| 49 | +## Code layout |
| 50 | + |
| 51 | +- `src/app/` — Next.js App Router. Pages live here; API routes under `src/app/api/<route>/route.ts`. |
| 52 | +- `src/models/` — DB access. API routes should call models, not `query()` directly, when a model method exists. |
| 53 | +- `src/lib/` — utilities, integrations (QRZ, LoTW), auth, db pool, crypto. |
| 54 | +- `src/components/` — React components. Radix-based UI primitives in `src/components/ui/`. |
| 55 | +- `src/contexts/` — React Context (UserContext, ThemeContext). |
| 56 | +- `src/types/` — shared TS types not tied to a single model. |
| 57 | +- `/migrations/` — hand-written SQL migrations. Root-level `*.sql` files are install/seed schema. |
| 58 | +- `/tests/` — Playwright specs. |
| 59 | + |
| 60 | +## Scripts (run from repo root) |
| 61 | + |
| 62 | +- `npm run dev` — Next dev server (Turbopack) |
| 63 | +- `npm run build` — production build |
| 64 | +- `npm run lint` — ESLint |
| 65 | +- `npm run typecheck` — `tsc --noEmit` |
| 66 | +- `npm test` — Playwright e2e |
| 67 | + |
| 68 | +## Pre-commit checklist |
| 69 | + |
| 70 | +1. `npm run lint` clean (warnings allowed for now, errors no) |
| 71 | +2. `npm run typecheck` clean |
| 72 | +3. `npm run build` succeeds |
| 73 | +4. If you touched API request/response shapes, update both ends in the same PR. |
0 commit comments