This document provides essential guidelines and technical references for AI agents (and human developers) working on the Deep Research repository. Adhere to these patterns to ensure consistency, security, and maintainability.
The project uses pnpm as the primary package manager.
- Install Dependencies:
pnpm install - Development Server:
pnpm dev(Runs athttp://localhost:3000) - Build Project:
pnpm build - Static Export:
pnpm build:export(Generatesout/directory) - Standalone Build:
pnpm build:standalone - Linting:
pnpm lint
- Status: Currently, there are no automated tests in the codebase.
- Guideline: If adding tests, use Vitest or Jest following standard Next.js patterns. Place test files next to the code they test (e.g.,
ComponentName.test.tsx) or in a__tests__directory. - Single Test: To run a single test (if added), use
pnpm vitest run path/to/file.test.ts.
src/app: Next.js App Router (Pages, API routes, Layouts).src/components: UI components.ui/: Shadcn primitives.Internal/: Custom shared components.Research/,Knowledge/, etc.: Feature-specific components.
src/hooks: Custom React hooks for business logic and state interaction.src/libs: External service integrations (e.g., MCP server logic).src/store: Zustand stores for global state and persistence.src/utils: Helper functions and core deep research logic.src/locales: I18n translation files (JSON).
- Strict Mode:
strict: trueis enabled intsconfig.json. Always provide explicit types for function parameters and return values. - Global Types: Core business logic types (e.g.,
SearchTask,Knowledge,Source) are defined insrc/types.d.ts. Check this file before creating new interfaces. - Explicit Any: While
@typescript-eslint/no-explicit-anyis currentlyoff, avoidanyunless absolutely necessary for external library compatibility. Preferunknownor specific interfaces. - Zod: Use Zod for schema validation, especially for AI response parsing and API request bodies. See
src/app/api/mcp/server.tsfor examples.
- App Router: This project uses the Next.js App Router.
- Client Components: Use
"use client";at the top of files that require browser APIs or React hooks (state, effects). - Dynamic Imports: Use Next.js
dynamic()for heavy components or those that rely on browser-only libraries (e.g.,MagicDown,Mermaid). - Hooks: Prefer custom hooks for complex logic (e.g.,
useDeepResearch,useKnowledge).
- Shadcn UI: UI primitives are located in
@/components/ui. Do not modify them directly; extend them or create wrappers insrc/components/Internal. - Styling: Use Tailwind CSS. Follow mobile-first responsive design patterns.
- Icons: Use lucide-react.
- I18n: All UI strings must use
useTranslationfromreact-i18next. Uset("key.path")for all labels.
- Zustand: Used for global state and persistence.
- Persistence: Most stores use the
persistmiddleware (e.g.,useTaskStoreinsrc/store/task.ts) to save research data inlocalStorage. - Radash: Use radash utilities for common operations like
pick,isString,isObject, etc.
- Path Alias: Always use the
@/prefix for absolute imports from thesrcdirectory. - Ordering:
- React/Next.js core
- Third-party libraries
- Components (Internal/UI)
- Hooks & Stores
- Utils & Types
- Use the
parseErrorutility from@/utils/error.tsto standardize error messages. - In async functions, use
try...catch...finallyto manage loading states and error reporting. - Standardized API error format:
{ isError: true, content: [{ type: "text", text: "..." }] }.
- SSE API: Located at
src/app/api/sse. Handles real-time streaming research reports. - MCP Server: Located at
src/app/api/mcp. Implements the Model Context Protocol for tool use by other AI agents. - Proxying: The project proxies various AI and search providers via
next.config.tsrewrites to avoid CORS issues and manage keys.
- Refer to
env.tplfor all available environment variables. - Critical variables include
GOOGLE_GENERATIVE_AI_API_KEY,TAVILY_API_BASE_URL, andACCESS_PASSWORD. - Never commit
.envor.env.localfiles.
- Secrets: Do not hardcode API keys or credentials.
- Sanitization: Use Zod to sanitize and validate all external inputs (web search results, user input).
- Destructive Actions: Avoid
rm -rfor history rewriting in git unless explicitly requested.
- Read First: Always read the relevant file and its neighbors before proposing edits.
- Follow Patterns: If adding a new component, look at
src/components/Research/SearchResult.tsxfor a reference implementation. - Keep it Focused: Make small, cohesive changes. Avoid unrelated refactors.
- Validate: Run
pnpm lintandpnpm buildto ensure your changes don't break the build. - Communication: Summarize what changed, where, and why. Call out tradeoffs, assumptions, and known limitations. If validation could not be run, say so explicitly.
- Clarity: Prefer clarity and simplicity over cleverness. Preserve existing behavior unless the task explicitly requires changes.
- UI Consistency: Ensure all new UI elements support both light and dark modes using Tailwind
dark:classes.