4.8 KiB
4.8 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
FastGPT is an AI Agent construction platform providing out-of-the-box data processing, model invocation capabilities, and visual workflow orchestration through Flow. This is a full-stack TypeScript application built on NextJS with MongoDB/PostgreSQL backends.
Tech Stack: NextJS + TypeScript + ChakraUI + MongoDB + PostgreSQL (PG Vector)/Milvus
Architecture
This is a monorepo using pnpm workspaces with the following key structure:
Packages (Library Code)
packages/global/- Shared types, constants, utilities used across all projectspackages/service/- Backend services, database schemas, API controllers, workflow enginepackages/web/- Shared frontend components, hooks, styles, i18npackages/templates/- Application templates for the template market
Projects (Applications)
projects/app/- Main NextJS web application (frontend + API routes)projects/sandbox/- NestJS code execution sandbox serviceprojects/mcp_server/- Model Context Protocol server implementation
Key Directories
document/- Documentation site (NextJS app with content)plugins/- External plugins (models, crawlers, etc.)deploy/- Docker and Helm deployment configurationstest/- Centralized test files and utilities
Development Commands
Main Commands (run from project root)
pnpm dev- Start development for all projects (uses package.json workspace scripts)pnpm build- Build all projectspnpm test- Run tests using Vitestpnpm test:workflow- Run workflow-specific testspnpm lint- Run ESLint across all TypeScript files with auto-fixpnpm format-code- Format code using Prettier
Project-Specific Commands
Main App (projects/app/):
cd projects/app && pnpm dev- Start NextJS dev servercd projects/app && pnpm build- Build NextJS appcd projects/app && pnpm start- Start production server
Sandbox (projects/sandbox/):
cd projects/sandbox && pnpm dev- Start NestJS dev server with watch modecd projects/sandbox && pnpm build- Build NestJS appcd projects/sandbox && pnpm test- Run Jest tests
MCP Server (projects/mcp_server/):
cd projects/mcp_server && bun dev- Start with Bun in watch modecd projects/mcp_server && bun build- Build MCP servercd projects/mcp_server && bun start- Start MCP server
Utility Commands
pnpm create:i18n- Generate i18n translation filespnpm api:gen- Generate OpenAPI documentationpnpm initIcon- Initialize icon assetspnpm gen:theme-typings- Generate Chakra UI theme typings
Testing
The project uses Vitest for testing with coverage reporting. Key test commands:
pnpm test- Run all testspnpm test:workflow- Run workflow tests specifically- Test files are located in
test/directory andprojects/app/test/ - Coverage reports are generated in
coverage/directory
Code Organization Patterns
Monorepo Structure
- Shared code lives in
packages/and is imported using workspace references - Each project in
projects/is a standalone application - Use
@fastgpt/global,@fastgpt/service,@fastgpt/webimports for shared packages
API Structure
- NextJS API routes in
projects/app/src/pages/api/ - Core business logic in
packages/service/core/ - Database schemas in
packages/service/with MongoDB/Mongoose
Frontend Architecture
- React components in
projects/app/src/components/andpackages/web/components/ - Chakra UI for styling with custom theme in
packages/web/styles/theme.ts - i18n support with files in
packages/web/i18n/ - State management using React Context and Zustand
Workflow System
- Visual workflow editor using ReactFlow
- Workflow engine in
packages/service/core/workflow/ - Node definitions in
packages/global/core/workflow/template/ - Dispatch system for executing workflow nodes
Development Notes
- Package Manager: Uses pnpm with workspace configuration
- Node Version: Requires Node.js >=18.16.0, pnpm >=9.0.0
- Database: Supports MongoDB, PostgreSQL with pgvector, or Milvus for vector storage
- AI Integration: Supports multiple AI providers through unified interface
- Internationalization: Full i18n support for Chinese, English, and Japanese
Key File Patterns
.tsand.tsxfiles use TypeScript throughout- Database schemas use Mongoose with TypeScript
- API routes follow NextJS conventions
- Component files use React functional components with hooks
- Shared types defined in
packages/global/with.d.tsfiles
Environment Configuration
- Configuration files in
projects/app/data/config.json - Environment-specific configs supported
- Model configurations in
packages/service/core/ai/config/