How shilin66/fastgpt works
Project Type & Purpose
• Full-stack AI-Agent Orchestration Platform
• Frontend: Next.js + React + ChakraUI
• Backend: Node.js + TypeScript serverless APIs (Next.js pages/api) plus separate microservices
• Data stores: MongoDB for metadata, Redis for cache/queues, Vector DB via PostgreSQL+pgvector or Milvus/OceanBase
• Worker layer for heavy tasks (embedding, file parsing)
• Plugin & template subsystems for extensibility
• Additional microservices: mcp_server (multi-channel push), sandbox (code execution sandbox), webcrawler
High-Level Component Breakdown
A. Frontend (Projects/app)
• React UI, SSR/CSR via Next.js
• /pages/api routes call server-side logic
• Static assets, public Chrome extension, OpenAPI doc page
• Local “web” library (packages/web) shared UI components
B. Backend API (Next.js pages/api)
• Entry point for UI and external clients (Flow editor, share iframe, OpenAPI endpoints)
• Delegates to service modules (packages/service) for business logic
C. Service Layer (packages/service)
• Core domain logic for AI, chat, workflow, dataset, support, permission, wallet
• Exposes utility controllers, schema definitions
• Interfaces with databases, message queues, external providers
D. Domain / Shared Logic (packages/global)
• Error codes, common utils, types, AI-provider abstraction, workflow templates
• Imported by both service and web packages
E. Worker Processes (packages/service/worker & packages/plugins/runtime)
• Consume BullMQ queues in Redis
• Count tokens, parse files (pdf, docx, html), generate embeddings, transcribe audio
• Plugin runtime workers (e.g., DingTalk, Doc2X) to isolate plugin execution
F. Plugin Subsystem (packages/plugins)
• Registry and runtime for system/community plugins
• Template definitions and worker code
• Loaded and invoked by service layer during workflow execution
G. Templates Library (packages/templates)
• Predefined prompt/workflow templates
• Imported by service or UI for prompt marketplaces
H. Microservices
1. mcp_server (projects/mcp_server) – external tool invocation API
2. sandbox (projects/sandbox) – secure JS function execution (code sandbox)
3. webcrawler (plugins/webcrawler/SPIDER) – scraping engine for document ingestion
Data Stores & Infrastructure
• MongoDB cluster (for user, app, chat, dataset metadata)
• Redis (cache, job queue via BullMQ, session locks)
• Vector database options:
• PostgreSQL + PGVector plugin
• Milvus / Zilliz / OceanBase via Docker Compose or Helm
• File storage: GridFS in Mongo or local FS for uploads
• Cron scheduler for periodic tasks (packages/service/common/system/cron)
• Kubernetes / Helm / Docker Compose for deployment
Relationships & Data Flow
• UI → Backend API (HTTP/HTTPS)
• Backend API → Service Layer (in-process imports)
• Service Layer → Databases (MongoDB, Redis, Vector DB)
• Service Layer → Message Queue (enqueue tasks)
• Worker → Redis → Databases / External AI Providers
• Service Layer ↔ Plugin Runtime (local worker or HTTP/gRPC calls)
• API Clients (OpenAPI, Iframe embed, share links) → Next.js API
Architectural Patterns & Principles
• Layered architecture: Presentation → Application → Domain → Infrastructure
• Monorepo with well-defined package boundaries (global, service, plugins, web, templates)
• Event-driven / asynchronous processing via BullMQ in Redis
• Microservices for specialized workloads (sandboxing, multi-channel push, crawling)
• Plugin architecture enabling hot-pluggable components
• Domain-driven design with shared types and APIs
Elements
• Component Names (Next.js UI, API Routes, Service Layer, Worker Pool, Redis, MongoDB, VectorDB, Plugins, Microservices)
• Deployment Units (Docker containers, Kubernetes pods, Helm charts)