# weirenjie3/fastgpt architecture

> Architecture diagram of the GitHub repository weirenjie3/fastgpt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/weirenjie3/fastgpt
- Repository: https://github.com/weirenjie3/fastgpt

## Overview

##### Project Type & Purpose
- FastGPT is a full-stack, monorepo web application for knowledge-base Q&A and visual workflow orchestration built on large language models (LLMs).
- It provides:
- A Next.js/React frontend (ChakraUI)
- A Node/TypeScript backend API (monolithic service layer + NestJS sandbox service)
- Data storage in MongoDB (metadata, sessions, permissions) and PostgreSQL with vector extensions (pgvector or Milvus) for embeddings
- Auxiliary Python microservices (file→text conversion, rerankers, fetch APIs)
- Deployment via Docker, Helm charts, Kubernetes

##### File Structure Highlights
- /packages
- global: shared TS types & utilities
- service: core backend API modules (core, support, common libs)
- web: standalone React/Next.js frontend packages used by project/app
- plugins: Node worker for external integrations (DuckDuckGo, Feishu, Doc2X, etc.)
- /projects/app: Next.js application combining /packages/web & /packages/service via APIs
- /projects/sandbox: NestJS-based “sandbox” microservice for secure code execution
- /python: several Python microservices for specialized tasks (fetching URLs, Office → text, BGE rerankers)
- /files/docker & /files/helm: infrastructure as code—Docker-compose definitions and Helm charts for Kubernetes

##### README Insights
- Tech stack called out: NextJs + TypeScript + ChakraUI + Mongo + Postgres (Vector plugin)
- Emphasis on LLM model orchestration, knowledge store ingestion, workflow (“Flow”) builder, OpenAPI endpoints, embed-share, voice I/O.

a. Main Components
- Frontend (Next.js app in /projects/app)
- API Gateway / Backend (packages/service HTTP controllers & business logic)
- Sandbox Microservice (NestJS in /projects/sandbox)
- Python Microservices (python/api, python/bge-rerank)
- Plugins Worker (packages/plugins runtime/worker.ts)
- Databases:
- MongoDB for metadata, user, session, logs, etc.
- PostgreSQL + pgvector (or Milvus) for vector store/embeddings
- External services:
- LLM providers via one-API (OpenAI, Baichuan, ChatGLM, etc.)
- Third-party data sources (URLs, Office files, search engines)
- DevOps: Docker, Docker-Compose, Helm, Kubernetes

b. Relationships & Data Flows
- Frontend ⟷ Backend API: REST/GraphQL calls
- Backend ⟷ Sandbox Service: RPC/HTTP to isolate code execution
- Backend ⟷ Python Services: HTTP calls (file conversion, rerank)
- Backend ⟷ Databases:
– Mongo client for system data
– Vector client for embeddings storage & retrieval
- Backend ⟷ External LLMs: via one-API abstraction layer
- Plugins Worker: subscribes to job queue or invoked by backend to run tool templates

c. Architectural Patterns & Principles
- Monorepo with package isolation, code-sharing via Lerna/pnpm workspace
- Layered architecture: API/controllers → core services → data stores → external adapters
- Microservices for sandboxed code execution and specialized algorithms
- Plugin architecture: dynamic tool/third-party integrations loaded at runtime
- Infrastructure as code: reproducible Docker/Helm deployments

d. Key Technologies
- Next.js, React, ChakraUI for UI
- Node.js + TypeScript for API (Express-style controllers under packages/service)
- NestJS for sandbox microservice
- Python (Flask/FastAPI) for auxiliary services
- MongoDB, PostgreSQL + pgvector, Milvus
- Helm charts, Docker-Compose, Kubernetes

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client"
        direction TB
        NextJS["Next.js Frontend"]:::app
    end

    %% Monorepo Packages
    subgraph "Monorepo Packages"
        direction TB
        WebLib["Shared React/Next.js UI Library"]:::app
        GlobalUtils["Shared TypeScript Types & Utilities"]:::app
        BackendAPI["Monolithic Backend API Service"]:::app
        PluginsWorker["Plugins Worker"]:::service
    end

    %% Microservices Layer
    subgraph "Microservices"
        direction TB
        Sandbox["Sandbox Microservice"]:::service
        FileConv["Python File-to-Text Conversion"]:::service
        Reranker["Python BGE Reranker"]:::service
    end

    %% Databases
    subgraph "Databases"
        direction TB
        MongoDB[(MongoDB)]:::db
        Postgres[(PostgreSQL + Vector)]:::db
    end

    %% External Services
    subgraph "External Services"
        direction TB
        LLMProviders((LLM Providers)):::external
        ThirdParty((Third-Party Data Sources)):::external
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        DockerCompose["Docker-Compose Definitions"]:::infra
        HelmCharts["Helm Charts"]:::infra
    end

    %% Connections
    NextJS -->|"REST/GraphQL"| BackendAPI
    WebLib -->|"UI Components"| NextJS
    GlobalUtils -->|"Shared Types"| BackendAPI
    BackendAPI -->|"RPC/HTTP"| Sandbox
    BackendAPI -->|"HTTP"| FileConv
    BackendAPI -->|"HTTP"| Reranker
    BackendAPI -->|"Mongo Client"| MongoDB
    BackendAPI -->|"Vector Client"| Postgres
    BackendAPI -->|"one-API"| LLMProviders
    BackendAPI -->|"Fetch & Conversion"| ThirdParty
    BackendAPI -->|"Job Queue"| PluginsWorker

    %% DevOps Flows
    DockerCompose -->|Deploys| NextJS
    DockerCompose -->|Deploys| BackendAPI
    HelmCharts -->|Deploys| NextJS
    HelmCharts -->|Deploys| BackendAPI
    HelmCharts -->|Deploys| Sandbox
    HelmCharts -->|Deploys| FileConv
    HelmCharts -->|Deploys| Reranker

    %% Click Events
    click NextJS "https://github.com/weirenjie3/fastgpt/tree/main/projects/app"
    click WebLib "https://github.com/weirenjie3/fastgpt/tree/main/packages/web"
    click GlobalUtils "https://github.com/weirenjie3/fastgpt/tree/main/packages/global"
    click BackendAPI "https://github.com/weirenjie3/fastgpt/tree/main/packages/service"
    click PluginsWorker "https://github.com/weirenjie3/fastgpt/blob/main/packages/plugins/runtime/worker.ts"
    click Sandbox "https://github.com/weirenjie3/fastgpt/tree/main/projects/sandbox"
    click FileConv "https://github.com/weirenjie3/fastgpt/tree/main/python/api"
    click Reranker "https://github.com/weirenjie3/fastgpt/tree/main/python/bge-rerank"
    click DockerCompose "https://github.com/weirenjie3/fastgpt/tree/main/files/docker"
    click HelmCharts "https://github.com/weirenjie3/fastgpt/tree/main/files/helm/fastgpt"

    %% Styles
    classDef app fill:#cce5ff,stroke:#004085,color:#004085;
    classDef service fill:#ffe5b4,stroke:#b36b00,color:#b36b00;
    classDef db fill:#d4edda,stroke:#155724,color:#155724;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef infra fill:#f0e6ff,stroke:#4b0082,color:#4b0082;
```
