* docs: add root-level CLAUDE.md to orient the monorepo Adds a thin top-level CLAUDE.md that maps the monorepo and delegates depth to backend/CLAUDE.md and frontend/CLAUDE.md, per issue #3761. Includes the project overview + service topology (Nginx 2026, Gateway 8001, Frontend 3000, optional Provisioner 8002), a top-level repository map, root `make` vs. per-module command sections, "where to go next" links to the module guides and primary root docs, and the repo-wide cross-cutting conventions (documentation-update policy, TDD expectation, format before pushing). No code or behavior changes; root points down, modules own depth. Closes #3761 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * docs: make AGENTS.md the source of truth, CLAUDE.md a thin @AGENTS.md importer Adopt the AGENTS.md convention so the same agent guidance serves Claude Code, Codex, and other tools. At each level (root, backend, frontend) the content lives in AGENTS.md and CLAUDE.md just imports it via `@AGENTS.md`. - root: move the monorepo orientation layer to AGENTS.md; CLAUDE.md -> @AGENTS.md. Fix an incorrect "TUI" reference (not present on main) and repoint the module links to the AGENTS.md files. - backend: move the guide to AGENTS.md (was an AGENTS.md -> @CLAUDE.md pointer; direction is now flipped). Refresh stale content: rebuild the full middleware chain (~26 ordered steps incl. InputSanitization, ToolOutputBudget, DynamicContext, TokenBudget, SafetyFinishReason) from the actual build functions; drop the brittle "11 middleware components" count; expand the community-tools list to the real set. - frontend: merge the practical Next.js guide with the existing AGENTS.md's unique sections (LangGraph diagram, tech-stack versions, interaction ownership, resources) into one AGENTS.md (CLAUDE.md -> @AGENTS.md). Fix the stale src/ layout (remove the no-longer-present server/ better-auth entry; add the now-active auth/agents/blog/... modules and routes) and drop a bogus interaction-ownership bullet referencing files that don't exist. Docs only; no code or behavior changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
6.7 KiB
AGENTS.md
This file provides guidance to AI coding agents (Claude Code, Codex, and others) when working with the DeerFlow frontend. It is the source of truth; the sibling CLAUDE.md imports it via @AGENTS.md.
Project Overview
DeerFlow Frontend is a Next.js 16 web interface for an AI agent system. It communicates with a LangGraph-based backend to provide thread-based AI conversations with streaming responses, artifacts, and a skills/tools system.
Stack: Next.js 16, React 19, TypeScript 5.8, Tailwind CSS 4, pnpm 10.26.2. Requires Node.js 22+ and pnpm 10.26.2+.
Core dependencies
- LangGraph SDK (
@langchain/langgraph-sdk^1.5.3) — Agent orchestration and streaming - LangChain Core (
@langchain/core^1.1.15) — Fundamental AI building blocks - TanStack Query (
@tanstack/react-query^5.90.17) — Server state management - UI: Shadcn UI, MagicUI, React Bits, and Vercel AI SDK elements (generated from registries — see Code Style)
Commands
| Command | Purpose |
|---|---|
pnpm dev |
Dev server with Turbopack (http://localhost:3000) |
pnpm build |
Production build |
pnpm check |
Lint + type check (run before committing) |
pnpm lint |
ESLint only |
pnpm lint:fix |
ESLint with auto-fix |
pnpm format |
Prettier check (pnpm format:write to apply) |
pnpm test |
Run unit tests with Rstest |
pnpm test:e2e |
Run E2E tests with Playwright (Chromium) |
pnpm typecheck |
TypeScript type check (tsc --noEmit) |
pnpm start |
Start production server |
Unit tests live under tests/unit/ and mirror the src/ layout (e.g., tests/unit/core/api/stream-mode.test.ts tests src/core/api/stream-mode.ts). Powered by Rstest; import source modules via the @/ path alias.
E2E tests live under tests/e2e/ and use Playwright with Chromium. They mock all backend APIs via page.route() network interception and test real page interactions (navigation, chat input, streaming responses). Config: playwright.config.ts.
Architecture
Frontend (Next.js) ──▶ LangGraph SDK ──▶ LangGraph Backend (lead_agent)
├── Sub-Agents
└── Tools & Skills
The frontend is a stateful chat application. Users create threads (conversations), send messages, and receive streamed AI responses. The backend orchestrates agents that can produce artifacts (files/code) and todos.
Source Layout (src/)
app/— Next.js App Router. Routes include/(landing),/workspace/chats/[thread_id](chat),/workspace/agents/[agent_name]and/workspace/agents/new(custom agents),/blog/…, the(auth)/{login,setup,auth/callback}flow,/[lang]/docs/…, and/api/…route handlers (e.g./api/memory).components/— React components:ui/— Shadcn UI primitives (auto-generated, ESLint-ignored)ai-elements/— Vercel AI SDK elements (auto-generated, ESLint-ignored)workspace/— Chat page components (messages, artifacts, settings)landing/— Landing page sectionsdocs/— Docs / MDX rendering components
core/— Business logic, the heart of the app. Domains includethreads/(creation, streaming, state),api/(LangGraph client singleton),agents/(custom agents),auth/(authentication),artifacts/,channels/(IM connections),i18n/(en-US, zh-CN),settings/,memory/,skills/,messages/,mcp/,models/,suggestions/,tasks/,todos/,tools/,config/,notification/,blog/, plus rendering helpers (rehype/,streamdown/) andutils/.hooks/— Shared React hookslib/— Utilities (cn()from clsx + tailwind-merge)content/— MDX content (blog posts, docs) rendered by the appstyles/— Global CSS with Tailwind v4@importsyntax and CSS variables for themingtypings/— Ambient TypeScript declarations- Root files:
env.js(env validation),mdx-components.ts(MDX component map)
Data Flow
- User input → thread hooks (
core/threads/hooks.ts) → LangGraph SDK streaming - Stream events update thread state (messages, artifacts, todos)
- TanStack Query manages server state; localStorage stores user settings
- Components subscribe to thread state and render updates
Key Patterns
- Server Components by default,
"use client"only for interactive components - Thread hooks (
useThreadStream,useSubmitThread,useThreads) are the primary API interface - LangGraph client is a singleton obtained via
getAPIClient()incore/api/ - Environment validation uses
@t3-oss/env-nextjswith Zod schemas (src/env.js). Skip withSKIP_ENV_VALIDATION=1
Interaction Ownership
src/app/workspace/chats/[thread_id]/page.tsxowns composer busy-state wiring.src/core/threads/hooks.tsowns pre-submit upload state and thread submission.
Code Style
- Imports: Enforced ordering (builtin → external → internal → parent → sibling), alphabetized, newlines between groups. Use inline type imports:
import { type Foo }. - Unused variables: Prefix with
_. - Class names: Use
cn()from@/lib/utilsfor conditional Tailwind classes. - Path alias:
@/*maps tosrc/*. - Components:
ui/andai-elements/are generated from registries (Shadcn, MagicUI, React Bits, Vercel AI SDK) — don't manually edit these.
Environment
Backend API URLs are optional; an nginx proxy is used by default:
NEXT_PUBLIC_BACKEND_BASE_URL=http://localhost:8001
NEXT_PUBLIC_LANGGRAPH_BASE_URL=http://localhost:8001/api
Leave these unset for the standard make dev / Docker flow, where nginx serves the public /api/langgraph/* prefix and rewrites it to Gateway's native /api/* routes.
Resources
Contributing
When adding features:
- Follow the established
src/structure - Add TypeScript types and proper error handling
- Write unit tests under
tests/unit/(pnpm test) and E2E tests undertests/e2e/(pnpm test:e2e) - Run
pnpm checkbefore committing - Update this
AGENTS.mdwhen architecture, commands, or conventions change