How guojintseng/deep-research works
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: useDeepResearch.ts Deep Research · global.ts Global State · page.tsx Workspace · deep-research Research Engine
Components 24
Browser UI
Client-side workspace and interactive research views.
- Workspace · Main app shell and entrypoint for the research workspace.
src/app/page.tsx - App Shell · Global providers, theming, and app-level wiring.
src/app/layout.tsx - Research Views · Topic entry, results, progress, and final report UI.
src/components/Research - Knowledge Views · Local resources, crawler, and content surfaces.
src/components/Knowledge - Artifact Editor · Editable report rendering, markdown editing, and rich content views.
src/components/Artifact.tsx - MagicDown · Editor, viewer, code highlighting, and Mermaid rendering.
src/components/MagicDown
Server APIs
Route handlers for AI, search, streaming, crawler, and MCP.
- AI Proxies · Provider-specific LLM proxy routes.
src/app/api/ai - Search Proxies · Provider-specific web search proxy routes.
src/app/api/search - SSE Stream · Long-running research progress and live result streaming.
src/app/api/sse - MCP Service · Model Context Protocol transport and server entrypoints.
src/app/api/mcp - Crawler API · Server-side crawler endpoint for fetching web content.
src/app/api/crawler/route.ts
Research Core
Workflow orchestration, hooks, and domain utilities.
- Deep Research · Client workflow controller for planning, searching, and synthesis.
src/hooks/useDeepResearch.ts - AI Client · Client-side provider selection and model access.
src/hooks/useAiProvider.ts - Search Client · Client-side web search integration and query execution.
src/hooks/useWebSearch.ts - Knowledge Client · Local knowledge and resource management on the client.
src/hooks/useKnowledge.ts - Research Engine · Prompting, query generation, provider abstraction, and synthesis logic.
src/utils/deep-research
Local Data
Client state, storage, and knowledge/artifact persistence.
- Global State · Shared client state root for app-wide data.
src/store/global.ts - History · Persisted research session history.
src/store/history.ts - Knowledge · Persisted local resources and knowledge records.
src/store/knowledge.ts - Settings · Provider, locale, and preference persistence.
src/store/setting.ts - Task Progress · Running research job status and progress state.
src/store/task.ts
Shared Libs
Cross-cutting utilities and protocol implementations.
- Parsers · PDF, office, and text parsing for local knowledge ingestion.
src/utils/parser - Storage · Browser-side persistence and artifact storage helpers.
src/utils/storage.ts - MCP Server · Protocol, transport, and streamable HTTP/SSE implementation.
src/libs/mcp-server
Connections 23
- 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.