CLAUDE.md@app · diff
git:20260827.5520675 to git:20260901.ecf6536
45 added, 0 removed. Audit A to A.
What this update changes in the checks
No check changed: every fixed check gives the same answer before and after this update.
A tripped check is a label, not a verdict: read the matched text and the lines below. This week's updates that newly trip a check.
# Duct App — Claude Code instructions
Next.js App Router report viewer and agent interface.
## Stack
- **Framework:** Next.js 16 App Router, React 19, TypeScript 6, Node 22 (pinned in `app/.nvmrc` — the OpenNext/wrangler toolchain requires ≥22; dev runs on port 3003)
- **UI:** shadcn/ui + Radix UI primitives, Tailwind CSS 4, lucide-react, next-themes (light/dark)
- **Charts:** Nivo (heatmaps, complex) + Recharts (general) — both intentionally present
- **State:** React Context (`InsightContext.js`) + component-level state only. No Redux/Zustand.
- **HTTP:** Native `fetch` wrapped in `lib/api.js`. No type-safe client or OpenAPI generation.
- **Auth:** Custom API key (`NEXT_PUBLIC_DUCT_API_KEY`) sent to backend + Google Sign-In (`GoogleSignInButton.jsx`). No next-auth/Clerk/Supabase.
- **Observability:** Sentry (`@sentry/nextjs` — server, edge, client), Google Tag Manager (`NEXT_PUBLIC_GTM_ID`), Cloudflare Turnstile bot protection.
## Deployment
- **Host:** Cloudflare Workers via `@opennextjs/cloudflare` adapter + wrangler CLI.
- `npm run deploy:cf` → OpenNext build + `wrangler deploy` (do not run directly — all deploys go through CI/CD on merge to main).
- **CI/CD:** GitHub Actions (`app.yml`) — lint, typecheck, `next build` on every PR; on push to `main` the `deploy` job runs `opennextjs-cloudflare build` + `wrangler deploy`. (Replaced the Cloudflare "Workers Builds" git integration, which failed on its Node 20 builder — wrangler@4.99 needs ≥22.)
## Route structure
Two route groups under `app/`:
- `(auth)/` — login page
- `(app)/` — authenticated app shell:
- `audit/` + `audit/[sessionId]/` — general audit reports
- `audit/seo/` + `audit/seo/[sessionId]/` — SEO audit variant
- `connections/` — connector/integration management
- `generate/` — report generation workflow
- `insights/` + `insights/[slug]/` + `insights/generate/` — insights hub
- `insights/organic-growth/` + `[slug]/` + `generate/` — organic growth insights
- `onboarding/` — new user setup
- `projects/` + `project/[projectId]/` — project management
- `project/[projectId]/members/` — project members + invitations (owner/collaborator)
Plus `invite/[token]/` at the top level (outside every route group): the invitation landing page, which must render for signed-out recipients.
## Key utilities
- `lib/api.js` — fetch wrapper for backend calls
- `lib/membersApi.js` — project members + invitations (server-only; no localStorage mirror, unlike `lib/projects.js`)
- `lib/engines.js` — LLM engine/model selection
- `lib/insightData.js` — insight fetching and management
- `lib/localInsights.js` — client-side insight storage
- `lib/reports.js` — report generation helpers
- `lib/userPreferences.js` — preference persistence
- `lib/analytics-client.js` — analytics event wrapper
- `lib/format.js` — dates, numbers and labels: `relativeTime`, `relativeDays`,
`formatDate`, `formatTime`, `toDate`, `dayKey`, `compactNumber`,
`formatNumber`, `titleCase`, `formatTitle`, `capitalize`, `initials`.
Use these instead of a component-local `fmtDate`/`fmtNum`/`prettify` — the
per-component copies had drifted apart before they were consolidated.
- `lib/sse.js` — `consumeSseStream` / `parseSseDataFrame`, shared by every
streaming endpoint (audit, content, insights)
- `lib/authFetch.js` — the one home for the auth token: `AUTH_TOKEN_KEY`,
`authToken`, `hasAuthToken`, `authedHeaders`, `authedRequest`, plus
`decodeJwtPayload` / `isTokenValid`. Never hardcode `"duct_auth_token"`.
+ ## UI conventions
+
+ Full reasoning in `docs/engineering/desktop-adaptive-ui-review.html` (in `duct`).
+
+ **Sizing: ask the container, not the window.** The viewport is the wrong ruler
+ here — the sidebar takes 16rem out of it, and the agent panes are user-resizable,
+ so `lg:` can be true while the box you are in is 300px. Each layout REGION
+ declares a container (`.app-main`, `.app-main-wide`, the full-bleed wrapper, both
+ `SplitWorkspace` panes), so components use `@`-variants and are correct wherever
+ they are placed.
+
+ - Content: `@container` variants on Tailwind's `@`-scale — `@md` 28rem, `@lg` 32rem,
+ `@xl` 36rem, `@2xl` 42rem, `@4xl` 56rem. Roughly 224px per grid column.
+ - Viewport (`sm:`/`md:`/…) only for genuine device concerns: the sign-in page,
+ the sidebar's mobile sheet, the pane toggle, and `md:text-sm` on chat inputs
+ (which exists to stop iOS zooming a sub-16px field).
+ - No hand-picked pixel breakpoints. There are currently zero; keep it that way.
+ - Before adding `container-type` anywhere new: it implies `contain: layout`, which
+ makes that element the containing block for `position: fixed` descendants.
+ Overlays must be portalled (they are — see below) or they will shrink to it.
+
+ **Units.** Type, spacing and sticky offsets in `rem` so they follow the reader's
+ text size. Device units stay `px`: borders, outlines, shadows, radii, 1px optical
+ nudges. Prose gets `max-width: var(--measure)` (68ch) or the `.measure` utility —
+ never tables, code, or column layouts.
+
+ **CSS lives in `src/app/styles/`.** `globals.css` is a manifest of imports and
+ nothing else; order is load-bearing (see its header). Add a partial for a new
+ concern rather than growing an existing one, and put page-specific styling with
+ the page.
+
+ **Shared UI primitives — use them, don't re-fork.**
+
+ - Overlays: `ui/dialog` (Radix — portal, focus trap, Escape, scroll lock) and
+ `ui/lightbox`. Never hand-roll a `fixed inset-0` backdrop.
+ - Busy state: `ui/spinner`. Colour comes from `currentColor`.
+ - Agent shells: `workspace/SplitWorkspace` (split + responsive), `PipelineProgress`
+ (the working ladder), `workspace/CodeBlock`, `workspace/agentPhase`.
+ - Shortcuts: `lib/shortcuts`' `useShortcut("mod+k", fn)` — platform-neutral, owned
+ by the surface that needs it.
+ - Commands: `useRegisterCommands` from `components/commands/CommandRegistry`. A
+ route contributes its own commands and they withdraw on unmount.
+ - Navigation: `lib/navigation`'s `NAV_SECTIONS` is the single source of truth for
+ the sidebar and the palette.
+
## What's not here
- No dedicated auth library (next-auth, Clerk, Supabase)
- No form library (React Hook Form, Formik)
- No global state library (Redux, Zustand, Jotai)
- No test suite (Jest, Vitest, Playwright) — E2E tests live in `site/`, not `app/`
- No Supabase anywhere in this project
<!-- BEGIN:nextjs-agent-rules -->
# This is NOT the Next.js you know
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.
This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.
<!-- END:nextjs-agent-rules -->