CLAUDE.md@app · git:20260901.56d04f9 · 2026-09-01 · sha256 75c416d854903ada
CLAUDE.md@app git:20260901.56d04f9A
Immutable. This exact content never changes and is served at /api/v1/blob/75c416d854903ada.
# 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.
**Accessibility.** Desktop keyboard and screen-reader basics, not a full audit.
- Every form control needs an accessible name. A `placeholder` is not one — it
disappears on focus and is skipped by some readers. Use a visible `<label>`,
or `aria-label` where the design has no room for one.
- Anything clickable is a `<button>`. A `<div onClick>` cannot be tabbed to or
triggered with Enter/Space, and the focus ring comes free with the element.
For a whole card, put the button on the title and stretch it with an
`after:absolute after:inset-0` pseudo-element — one tab stop, one readable
name, and the card stays a container.
- Live regions are rationed. The agent's phase label (`role="status"`) is the
one in each chat shell; streaming tokens and the rotating `PipelineProgress`
subtitle are deliberately silent, because announcing them talks over the user.
- `html { scroll-padding-top: 4rem }` in `styles/base.css` keeps a focused
element out from under the sticky header (WCAG 2.2 AA 2.4.11).
- Decorative icons take `aria-hidden`; an icon-only button takes an `aria-label`.
## 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 -->