# simo2610/gpt-researcher architecture

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

- Interactive diagram: https://gitdiagram.com/simo2610/gpt-researcher
- Repository: https://github.com/simo2610/gpt-researcher

## Overview

##### Main System Components
- Frontend Applications:
- A lightweight static version (plain HTML/CSS/JS) and a production-ready NextJS application (found in the frontend/nextjs folder). They provide the user interface for entering research queries, displaying research progress, and viewing final reports.
- Backend Server:
- Located in the backend/server folder, this component (with app.py, server.py, logging, and WebSocket management) handles API requests, manages client connections, and coordinates research queries.
- Core Research Engine:
- The gpt_researcher directory holds key modules such as agent creation, configuration, document processing (loaders and scrapers), LLM provider integrations, memory management, retrievers, and report generation.
- Multi-Agent System:
- The multi_agents directory implements an orchestration of different agents (planner, researchers, reviewers, etc.) for a coordinated deep research process using LangGraph. This module is designed to work concurrently, managing different specialized agents.
- Utilities and Supporting Libraries:
- Additional directories like backend/chat, backend/memory, backend/report_type, and docs provide extra components for chat interactions, data retention, different report formats, and documentation.
- External Integration and Deployment:
- The Dockerfile, docker-compose.yml, and Procfile indicate containerization and deployment practices.
- Environment configuration files (.env.example) and CI/CD (GitHub workflows) signal automated build and deployment pipelines.

##### Relationships & Interactions
- NextJS-based frontend along with the lightweight static version.
- Backend API and Server:
- Backend server as a central hub that accepts requests from the frontend and manages task orchestration.
- Backend server to the core research engine (gpt_researcher) and, optionally, to the multi_agents module.
- Research Engine & Agent Workflow:
- Inside the core research engine, illustrate separate modules:
▪ Planner Agent: Generates the research questions.
▪ Execution Agents & Scrapers: Fetch and process data from web or local sources.
▪ Aggregator/Publisher: Combines the gathered information into a coherent report.
- External Services:
- Data Flow & Local Document Integration:
- Support for processing local documents (PDF, Markdown, Excel, etc.) that are loaded and parsed via document loaders (located in gpt_researcher/document) and routed through the research process.

##### Important Architectural Patterns
- Modular Design:
- Separation of concerns with directories clearly separating the backend server, research logic (agents, planners, and scrapers), and frontend operations.
- Agent-Based & Pipeline Workflow:
- “planner – executor – publisher” pattern, showing parallelized execution (concurrent processing in deep research).
- Extensibility:
- Areas (like multiple retriever integrations and multi-agent orchestration) that allow easy extension or plugging of additional agents or data sources.

##### Relevant Technologies & Frameworks
- Languages & Frameworks:
- Python is used on the backend; Node/NextJS for the frontend.
- Docker for containerization and deployment.
- Libraries & Tools:
- Mention LangGraph (for multi-agent orchestration), Uvicorn (for the FastAPI server), and Tailwind (in the NextJS frontend).
- Testing frameworks evidenced by the tests directory.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FS("Frontend (Static Version)"):::frontend
        FNS("Frontend (NextJS Application)"):::frontend
    end

    %% Backend/API Layer
    subgraph "Backend Layer"
        BS("Backend Server"):::backend
        subgraph "Backend Utilities"
            CU("Chat Utilities"):::backend_util
            MU("Memory Utilities"):::backend_util
            RT("Report Types"):::backend_util
        end
    end

    %% Core Research Engine & Agents
    subgraph "Core Research & Agents"
        subgraph "Core Research Engine"
            PA("Planner Agent"):::research
            EA("Execution Agent / Data Scraper"):::research
            AP("Aggregator / Publisher"):::research
            LDP("Local Document Processing"):::research
            PA -->|"flow"| EA
            EA -->|"flow"| AP
            EA -->|"loads"| LDP
        end
        MA("Multi-Agent Orchestrator"):::research
    end

    %% External Services & Deployment
    subgraph "External & Deployment"
        EAS("External API Services"):::external
        subgraph "Deployment & CI/CD"
            DF("Dockerfile"):::deployment
            DC("docker-compose.yml"):::deployment
            PF("Procfile"):::deployment
            ENV(".env.example"):::deployment
        end
    end

    %% Connections between layers
    FS -->|"APIcalls"| BS
    FNS -->|"APIcalls"| BS

    BS -->|"orchestrates"| PA
    BS -->|"orchestrates"| MA
    BS -->|"uses"| CU
    BS -->|"uses"| MU
    BS -->|"fetchesReports"| RT

    AP -->|"generatesReport"| RT
    MA -->|"coordinatesAgents"| PA
    PA -->|"callsLLM"| EAS
    RT -->|"sendsReport"| FS
    RT -->|"sendsReport"| FNS

    %% Deployment connectivity (ancillary)
    DF --- BS
    DC --- BS
    PF --- BS
    ENV --- BS

    %% Class Definitions
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef research fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef deployment fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef backend_util fill:#98FB98,stroke:#000,stroke-width:1px;

    %% Click Events
    click FS "https://github.com/simo2610/gpt-researcher/blob/master/frontend/index.html"
    click FNS "https://github.com/simo2610/gpt-researcher/tree/master/frontend/nextjs"
    click BS "https://github.com/simo2610/gpt-researcher/tree/master/backend/server"
    click PA "https://github.com/simo2610/gpt-researcher/tree/master/gpt_researcher"
    click EA "https://github.com/simo2610/gpt-researcher/tree/master/gpt_researcher"
    click AP "https://github.com/simo2610/gpt-researcher/tree/master/gpt_researcher"
    click LDP "https://github.com/simo2610/gpt-researcher/tree/master/gpt_researcher"
    click MA "https://github.com/simo2610/gpt-researcher/tree/master/multi_agents"
    click CU "https://github.com/simo2610/gpt-researcher/tree/master/backend/chat"
    click MU "https://github.com/simo2610/gpt-researcher/tree/master/backend/memory"
    click RT "https://github.com/simo2610/gpt-researcher/tree/master/backend/report_type"
    click DF "https://github.com/simo2610/gpt-researcher/tree/master/Dockerfile"
    click DC "https://github.com/simo2610/gpt-researcher/blob/master/docker-compose.yml"
    click PF "https://github.com/simo2610/gpt-researcher/tree/master/Procfile"
    click ENV "https://github.com/simo2610/gpt-researcher/blob/master/.env.example"
```
