# guojintseng/deep-research architecture

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

- Interactive diagram: https://gitdiagram.com/guojintseng/deep-research
- Repository: https://github.com/guojintseng/deep-research

## Overview

1. **Project shape**
   This is a Next.js 15 application that acts as both a browser UI and a server-side API host. The architecture is centered on a “deep research” workflow that combines LLM calls, web search, local file knowledge, and report generation.

2. **Primary runtime boundary**
   The app has two major execution planes: client-side React for the interactive workspace, and server-side route handlers under `src/app/api` for proxying AI/search traffic, streaming research progress, and exposing MCP/SSE services. The README’s privacy model is important: most user data and generated artifacts are intended to stay in the browser unless server-side API mode is explicitly used.

3. **User-facing UI subsystem**
   The main interface lives in `src/app/page.tsx` and the component tree under `src/components`. The UI is split into research-specific areas such as topic entry, search results, workflow progress, final report, knowledge graph, history, artifact editing, and settings, plus shared internal controls like header, floating menu, upload wrapper, debugger, and password input.

4. **Research workflow orchestration**
   The research experience is coordinated by hooks in `src/hooks` and domain utilities in `src/utils/deep-research`. These pieces likely manage the stepwise flow described in the README: propose a plan, generate search queries, collect evidence, optionally recurse for deeper research, and finally synthesize a Markdown report.

5. **State and persistence boundary**
   Global client state is organized in `src/store` with slices for history, knowledge, settings, and task progress. This aligns with the “local-first” design: research sessions, uploaded resources, and user preferences are persisted locally rather than being treated as a centralized backend database.

6. **AI provider adapter layer**
   `src/app/api/ai/*` contains per-provider proxy routes for Anthropic, Azure, DeepSeek, Google, Google Vertex, Mistral, Ollama, OpenAI, OpenAI-compatible endpoints, OpenRouter, Pollinations, and xAI. This is a key abstraction boundary: the rest of the app talks to a normalized research workflow, while these adapters handle provider-specific HTTP shapes and credentials.

7. **Web search adapter layer**
   `src/app/api/search/*` implements a similar provider boundary for search backends such as Brave, Exa, Tavily, Firecrawl, SearxNG, and Bocha. The research engine can therefore treat web search as a pluggable capability, independent of the chosen LLM provider.

8. **Streaming and live execution**
   `src/app/api/sse` and `src/app/api/sse/live` provide the real-time research API used to stream progress and final results to clients. This is the main transport for long-running research jobs, so the architecture should show an event-stream path from the research engine back to the UI.

9. **MCP service boundary**
   `src/app/api/mcp` exposes the same research capability through Model Context Protocol, with both streamable HTTP and SSE transport support. The `src/libs/mcp-server` subtree contains the MCP protocol/transport implementation, making this a separate integration surface for external AI tools rather than part of the main browser UI.

10. **Local knowledge ingestion**
   The knowledge subsystem combines upload and parsing utilities with UI components for resources, crawler, and content views. Files such as PDFs, Office docs, text, and crawled content are parsed in `src/utils/parser` and related helpers, then surfaced in the research flow as local context for retrieval and report generation.

11. **Artifacts and report editing**
   The final output is not just a static response; it is editable through the artifact system in `src/components/Artifact` and `src/components/MagicDown`. That subsystem supports markdown/WYSIWYM editing, rendering, code highlighting, Mermaid visualization, and citation-aware report refinement.

12. **Cross-cutting concerns**
   Several shared utilities support the whole system: markdown/text parsing, URL and file helpers, error handling, model metadata, i18n, storage, and vertex auth. `src/middleware.ts` and `src/app/layout.tsx` indicate app-wide concerns such as access control, theming, and localization.

13. **Deployment and platform shape**
   The repo is designed for multiple deployment targets: Vercel, Cloudflare Pages, Docker, and static export. PWA support via `src/app/manifest.json` and `src/app/sw.ts` means the app can behave like an installable offline-capable client, but the architecture still depends on server routes for proxying and streaming where needed.

14. **What to emphasize in a diagram**
   The most important diagram boundaries are: browser UI/state, research orchestration, external LLM/search providers, streaming APIs, MCP integration, and local knowledge/artifact storage. The core data flow is user input → research plan/query generation → search + model calls → streamed progress/results → editable final report, with optional local file knowledge folded into the evidence set.

Main entry points: [`src/hooks/useDeepResearch.ts`](https://github.com/guojintseng/deep-research/blob/main/src/hooks/useDeepResearch.ts) (Deep Research), [`src/store/global.ts`](https://github.com/guojintseng/deep-research/blob/main/src/store/global.ts) (Global State), [`src/app/page.tsx`](https://github.com/guojintseng/deep-research/blob/main/src/app/page.tsx) (Workspace), [`src/utils/deep-research`](https://github.com/guojintseng/deep-research/tree/main/src/utils/deep-research) (Research Engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Browser UI"]
  node_page["Workspace<br/>Next page<br/>[page.tsx]"]
  node_layout["App Shell<br/>Next layout<br/>[layout.tsx]"]
  node_research_ui["Research Views<br/>React components"]
  node_knowledge_ui["Knowledge Views<br/>React components"]
  node_artifact_ui["Artifact Editor<br/>Markdown editor<br/>[Artifact.tsx]"]
  node_magicdown["MagicDown<br/>Markdown renderer"]
end

subgraph group_api["Server APIs"]
  node_ai_api["AI Proxies<br/>API routes"]
  node_search_api["Search Proxies<br/>API routes"]
  node_sse_api["SSE Stream<br/>API routes"]
  node_mcp_api["MCP Service<br/>API routes"]
  node_crawler_api["Crawler API<br/>API route<br/>[route.ts]"]
end

subgraph group_core["Research Core"]
  node_research_hook["Deep Research<br/>Hook orchestration<br/>[useDeepResearch.ts]"]
  node_ai_hook["AI Client<br/>Hook adapter<br/>[useAiProvider.ts]"]
  node_search_hook["Search Client<br/>Hook adapter<br/>[useWebSearch.ts]"]
  node_knowledge_hook["Knowledge Client<br/>Hook adapter<br/>[useKnowledge.ts]"]
  node_deep_research["Research Engine<br/>Workflow utils"]
end

subgraph group_data["Local Data"]
  node_global_store["Global State<br/>Store<br/>[global.ts]"]
  node_history_store["History<br/>Store slice<br/>[history.ts]"]
  node_knowledge_store["Knowledge<br/>Store slice<br/>[knowledge.ts]"]
  node_setting_store["Settings<br/>Store slice<br/>[setting.ts]"]
  node_task_store["Task Progress<br/>Store slice<br/>[task.ts]"]
end

subgraph group_shared["Shared Libs"]
  node_parser["Parsers<br/>File ingestion"]
  node_storage["Storage<br/>Persistence utils<br/>[storage.ts]"]
  node_mcp_lib["MCP Server<br/>Protocol lib"]
end

node_layout -->|"renders"| node_page
node_page -->|"hosts"| node_research_ui
node_page -->|"hosts"| node_knowledge_ui
node_page -->|"hosts"| node_artifact_ui
node_artifact_ui -->|"uses"| node_magicdown
node_research_ui -->|"drives"| node_research_hook
node_knowledge_ui -->|"drives"| node_knowledge_hook
node_research_hook -->|"calls"| node_ai_hook
node_research_hook -->|"calls"| node_search_hook
node_research_hook -->|"folds in"| node_knowledge_hook
node_research_hook -->|"executes"| node_deep_research
node_deep_research -->|"proxies"| node_ai_api
node_deep_research -->|"proxies"| node_search_api
node_deep_research -->|"streams"| node_sse_api
node_mcp_api -->|"implements"| node_mcp_lib
node_crawler_api -->|"feeds"| node_parser
node_knowledge_hook -->|"ingests"| node_parser
node_knowledge_hook -->|"persists"| node_storage
node_research_hook -->|"syncs"| node_global_store
node_global_store -->|"contains"| node_history_store
node_global_store -->|"contains"| node_knowledge_store
node_global_store -->|"contains"| node_setting_store
node_global_store -->|"contains"| node_task_store

click node_page "https://github.com/guojintseng/deep-research/blob/main/src/app/page.tsx"
click node_layout "https://github.com/guojintseng/deep-research/blob/main/src/app/layout.tsx"
click node_research_ui "https://github.com/guojintseng/deep-research/tree/main/src/components/Research"
click node_knowledge_ui "https://github.com/guojintseng/deep-research/tree/main/src/components/Knowledge"
click node_artifact_ui "https://github.com/guojintseng/deep-research/blob/main/src/components/Artifact.tsx"
click node_magicdown "https://github.com/guojintseng/deep-research/tree/main/src/components/MagicDown"
click node_research_hook "https://github.com/guojintseng/deep-research/blob/main/src/hooks/useDeepResearch.ts"
click node_ai_hook "https://github.com/guojintseng/deep-research/blob/main/src/hooks/useAiProvider.ts"
click node_search_hook "https://github.com/guojintseng/deep-research/blob/main/src/hooks/useWebSearch.ts"
click node_knowledge_hook "https://github.com/guojintseng/deep-research/blob/main/src/hooks/useKnowledge.ts"
click node_global_store "https://github.com/guojintseng/deep-research/blob/main/src/store/global.ts"
click node_history_store "https://github.com/guojintseng/deep-research/blob/main/src/store/history.ts"
click node_knowledge_store "https://github.com/guojintseng/deep-research/blob/main/src/store/knowledge.ts"
click node_setting_store "https://github.com/guojintseng/deep-research/blob/main/src/store/setting.ts"
click node_task_store "https://github.com/guojintseng/deep-research/blob/main/src/store/task.ts"
click node_deep_research "https://github.com/guojintseng/deep-research/tree/main/src/utils/deep-research"
click node_parser "https://github.com/guojintseng/deep-research/tree/main/src/utils/parser"
click node_storage "https://github.com/guojintseng/deep-research/blob/main/src/utils/storage.ts"
click node_ai_api "https://github.com/guojintseng/deep-research/tree/main/src/app/api/ai"
click node_search_api "https://github.com/guojintseng/deep-research/tree/main/src/app/api/search"
click node_sse_api "https://github.com/guojintseng/deep-research/tree/main/src/app/api/sse"
click node_mcp_api "https://github.com/guojintseng/deep-research/tree/main/src/app/api/mcp"
click node_crawler_api "https://github.com/guojintseng/deep-research/blob/main/src/app/api/crawler/route.ts"
click node_mcp_lib "https://github.com/guojintseng/deep-research/tree/main/src/libs/mcp-server"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_page,node_layout,node_research_ui,node_knowledge_ui,node_artifact_ui,node_magicdown toneBlue
class node_ai_api,node_search_api,node_sse_api,node_mcp_api,node_crawler_api toneAmber
class node_research_hook,node_ai_hook,node_search_hook,node_knowledge_hook,node_deep_research toneMint
class node_global_store,node_history_store,node_knowledge_store,node_setting_store,node_task_store toneRose
class node_parser,node_storage,node_mcp_lib toneIndigo
```

## Components

### Browser UI

Client-side workspace and interactive research views.

- [Workspace](https://github.com/guojintseng/deep-research/blob/main/src/app/page.tsx): Next page · Main app shell and entrypoint for the research workspace. · `src/app/page.tsx`
- [App Shell](https://github.com/guojintseng/deep-research/blob/main/src/app/layout.tsx): Next layout · Global providers, theming, and app-level wiring. · `src/app/layout.tsx`
- [Research Views](https://github.com/guojintseng/deep-research/tree/main/src/components/Research): React components · Topic entry, results, progress, and final report UI. · `src/components/Research`
- [Knowledge Views](https://github.com/guojintseng/deep-research/tree/main/src/components/Knowledge): React components · Local resources, crawler, and content surfaces. · `src/components/Knowledge`
- [Artifact Editor](https://github.com/guojintseng/deep-research/blob/main/src/components/Artifact.tsx): Markdown editor · Editable report rendering, markdown editing, and rich content views. · `src/components/Artifact.tsx`
- [MagicDown](https://github.com/guojintseng/deep-research/tree/main/src/components/MagicDown): Markdown renderer · Editor, viewer, code highlighting, and Mermaid rendering. · `src/components/MagicDown`

### Server APIs

Route handlers for AI, search, streaming, crawler, and MCP.

- [AI Proxies](https://github.com/guojintseng/deep-research/tree/main/src/app/api/ai): API routes · Provider-specific LLM proxy routes. · `src/app/api/ai`
- [Search Proxies](https://github.com/guojintseng/deep-research/tree/main/src/app/api/search): API routes · Provider-specific web search proxy routes. · `src/app/api/search`
- [SSE Stream](https://github.com/guojintseng/deep-research/tree/main/src/app/api/sse): API routes · Long-running research progress and live result streaming. · `src/app/api/sse`
- [MCP Service](https://github.com/guojintseng/deep-research/tree/main/src/app/api/mcp): API routes · Model Context Protocol transport and server entrypoints. · `src/app/api/mcp`
- [Crawler API](https://github.com/guojintseng/deep-research/blob/main/src/app/api/crawler/route.ts): API route · Server-side crawler endpoint for fetching web content. · `src/app/api/crawler/route.ts`

### Research Core

Workflow orchestration, hooks, and domain utilities.

- [Deep Research](https://github.com/guojintseng/deep-research/blob/main/src/hooks/useDeepResearch.ts): Hook orchestration · Client workflow controller for planning, searching, and synthesis. · `src/hooks/useDeepResearch.ts`
- [AI Client](https://github.com/guojintseng/deep-research/blob/main/src/hooks/useAiProvider.ts): Hook adapter · Client-side provider selection and model access. · `src/hooks/useAiProvider.ts`
- [Search Client](https://github.com/guojintseng/deep-research/blob/main/src/hooks/useWebSearch.ts): Hook adapter · Client-side web search integration and query execution. · `src/hooks/useWebSearch.ts`
- [Knowledge Client](https://github.com/guojintseng/deep-research/blob/main/src/hooks/useKnowledge.ts): Hook adapter · Local knowledge and resource management on the client. · `src/hooks/useKnowledge.ts`
- [Research Engine](https://github.com/guojintseng/deep-research/tree/main/src/utils/deep-research): Workflow utils · Prompting, query generation, provider abstraction, and synthesis logic. · `src/utils/deep-research`

### Local Data

Client state, storage, and knowledge/artifact persistence.

- [Global State](https://github.com/guojintseng/deep-research/blob/main/src/store/global.ts): Store · Shared client state root for app-wide data. · `src/store/global.ts`
- [History](https://github.com/guojintseng/deep-research/blob/main/src/store/history.ts): Store slice · Persisted research session history. · `src/store/history.ts`
- [Knowledge](https://github.com/guojintseng/deep-research/blob/main/src/store/knowledge.ts): Store slice · Persisted local resources and knowledge records. · `src/store/knowledge.ts`
- [Settings](https://github.com/guojintseng/deep-research/blob/main/src/store/setting.ts): Store slice · Provider, locale, and preference persistence. · `src/store/setting.ts`
- [Task Progress](https://github.com/guojintseng/deep-research/blob/main/src/store/task.ts): Store slice · Running research job status and progress state. · `src/store/task.ts`

### Shared Libs

Cross-cutting utilities and protocol implementations.

- [Parsers](https://github.com/guojintseng/deep-research/tree/main/src/utils/parser): File ingestion · PDF, office, and text parsing for local knowledge ingestion. · `src/utils/parser`
- [Storage](https://github.com/guojintseng/deep-research/blob/main/src/utils/storage.ts): Persistence utils · Browser-side persistence and artifact storage helpers. · `src/utils/storage.ts`
- [MCP Server](https://github.com/guojintseng/deep-research/tree/main/src/libs/mcp-server): Protocol lib · Protocol, transport, and streamable HTTP/SSE implementation. · `src/libs/mcp-server`

## Connections

- App Shell → Workspace: renders · App shell provides global providers and layout around the workspace.
- Workspace → Research Views: hosts · Main page composes the research-specific interface.
- Workspace → Knowledge Views: hosts · Main page surfaces local knowledge panels.
- Workspace → Artifact Editor: hosts · Main page exposes editable report artifacts.
- Artifact Editor → MagicDown: uses · Artifact editing is built on the markdown editor/viewer stack.
- Research Views → Deep Research: drives · UI actions trigger the research workflow hook.
- Knowledge Views → Knowledge Client: drives · Knowledge panels use the local knowledge hook.
- Deep Research → AI Client: calls · Research orchestration selects and uses model providers.
- Deep Research → Search Client: calls · Research orchestration issues web searches.
- Deep Research → Knowledge Client: folds in · Local knowledge is incorporated into the research flow.
- Deep Research → Research Engine: executes · The hook coordinates the domain research engine.
- Research Engine → AI Proxies: proxies · Server API routes normalize provider-specific LLM traffic.
- Research Engine → Search Proxies: proxies · Server API routes normalize search backend traffic.
- Research Engine → SSE Stream: streams · Progress and final results are emitted over SSE.
- MCP Service → MCP Server: implements · MCP routes are backed by the local MCP server library.
- Crawler API → Parsers: feeds · Fetched content is parsed before entering the knowledge flow.
- Knowledge Client → Parsers: ingests · Uploads and crawled files are parsed into local knowledge.
- Knowledge Client → Storage: persists · Knowledge resources are stored locally.
- Deep Research → Global State: syncs · Research workflow state is reflected in shared client state.
- Global State → History: contains · Global state includes session history.
- Global State → Knowledge: contains · Global state includes knowledge records.
- Global State → Settings: contains · Global state includes user settings.
- Global State → Task Progress: contains · Global state includes task progress.
