# bragadeez/research-system architecture

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

- Interactive diagram: https://gitdiagram.com/bragadeez/research-system
- Repository: https://github.com/bragadeez/research-system

## Overview

1. **Repository shape**
   ScholarNode AI is a two-part system: a **Python backend** that runs a multi-agent research pipeline, and a **React/Vite/TypeScript frontend** that visualizes and controls it. The backend is the system of record; the frontend is a dashboard over HTTP and WebSockets.

2. **User-facing entry points**
   There are two main ways to use the project:
   - `api/server.py` exposes the FastAPI service used by the web UI.
   - `main.py` provides a CLI-style entry point for running research from the terminal.
   This means the core research logic is shared, while presentation differs.

3. **Backend API boundary**
   The FastAPI layer is the external interface for:
   - starting research runs,
   - importing/exporting sessions,
   - streaming progress updates over WebSockets,
   - serving chat-with-report queries.
   It acts as a thin orchestration boundary around the pipeline and persistence layers rather than containing research logic itself.

4. **Orchestration core**
   The research process is modeled as a LangGraph state machine in `orchestrator/`.
   There are two pipeline variants:
   - `pipeline.py` for the standard research flow,
   - `heavy_pipeline.py` for academic/literature-review mode.
   Both are stateful workflows that pass structured data through the same general stages.

5. **Pipeline stages and data flow**
   The standard flow follows the pattern:
   **Plan → Search → Rank → Extract → Aggregate → Synthesize → Critique**
   Data is progressively transformed from a user question into:
   - subtopics and search plans,
   - candidate sources,
   - ranked sources,
   - extracted claims/evidence,
   - consolidated findings,
   - a final cited report,
   - critique metrics and retry decisions.
   The critique stage can trigger loops back into synthesis/revision when confidence is too low.

6. **Agent layer**
   The `agents/` directory contains specialized workers for each stage:
   - `planner_agent.py` decomposes the query,
   - `search_agent.py` and `academic_search_agent.py` gather sources,
   - `extraction_agent.py` pulls atomic facts from documents,
   - `synthesis_agent.py` and `heavy_synthesis_agent.py` draft the final output for different modes,
   - `critic_agent.py` evaluates factual quality and completeness.
   This separation is the main functional boundary in the backend.

7. **LLM and retrieval support**
   `core/llm_client.py` centralizes Gemini access, including API-key rotation and model fallback behavior. Other core services add structure around model use:
   - `source_ranker.py` scores candidate sources,
   - `evidence_aggregator.py` clusters and reconciles evidence,
   - `rag_engine.py` indexes completed reports for follow-up Q&A.
   These modules sit between the agents and the external AI/vector services.

8. **Search and scraping subsystem**
   `tools/` contains the non-LLM acquisition layer:
   - `search_tools.py` connects to web and academic search providers,
   - `scraper.py` extracts readable page content,
   - `normalizer.py` cleans and standardizes fetched text.
   This is the input side of the pipeline: raw URLs, abstracts, and page text enter here before ranking and extraction.

9. **Shared data contracts**
   The `models/` package defines the typed schemas used across the graph:
   research plans, sources, findings, extraction batches, critique results, and the global state object.
   These models are the contract between pipeline stages, so the architecture depends on structured intermediate state rather than passing untyped blobs around.

10. **Persistence and artifact storage**
   `db/database.py` provides SQLite persistence for sessions, reports, and chat history.
   The `data/` directory stores durable runtime data, including the database and Chroma vector store.
   The `exports/` directory holds generated deliverables such as Markdown and Word files.
   This cleanly separates operational storage from user-facing exported artifacts.

11. **Frontend architecture**
   The `frontend/` app is a Vite-based React dashboard. Its main responsibilities are:
   - starting research runs,
   - showing live progress/logs,
   - rendering reports and critique metrics,
   - exposing the report chat overlay,
   - handling import/export actions.
   `src/api/client.ts` is the browser-side boundary for REST calls and WebSocket subscriptions.

12. **Configuration and deployment**
   `config.py`, `.env.example`, `requirements.txt`, and `Dockerfile` show that runtime behavior is driven by environment configuration and containerized deployment. The important external dependencies that materially shape the architecture are Gemini for model calls, ChromaDB for semantic retrieval, and SQLite for persistence.

13. **Overall system boundary**
   The key architectural boundary is:
   **UI/API layer** → **orchestrated research pipeline** → **search/scrape + LLM + retrieval utilities** → **persistent session/report stores**.
   If drawing a diagram, the most important arrows are the research request flowing downward into the pipeline, and progress/results flowing back up to the WebSocket-driven frontend.

Main entry points: [`orchestrator/pipeline.py`](https://github.com/bragadeez/research-system/blob/main/orchestrator/pipeline.py) (Standard Flow), [`core/llm_client.py`](https://github.com/bragadeez/research-system/blob/main/core/llm_client.py) (LLM Client), [`orchestrator/heavy_pipeline.py`](https://github.com/bragadeez/research-system/blob/main/orchestrator/heavy_pipeline.py) (Heavy Flow), [`api/server.py`](https://github.com/bragadeez/research-system/blob/main/api/server.py) (API Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_main(("CLI Run<br/>entrypoint<br/>[main.py]"))
  node_server["API Server<br/>fastapi<br/>[server.py]"]
  node_pipeline{{"Standard Flow<br/>langgraph workflow<br/>[pipeline.py]"}}
  node_heavy_pipeline{{"Heavy Flow<br/>langgraph workflow<br/>[heavy_pipeline.py]"}}
  node_planner_agent["Planner<br/>agent<br/>[planner_agent.py]"]
  node_search_agent["Search<br/>agent<br/>[search_agent.py]"]
  node_academic_search_agent["Academic Search<br/>agent"]
  node_extraction_agent["Extractor<br/>agent"]
  node_synthesis_agent["Synthesis<br/>agent<br/>[synthesis_agent.py]"]
  node_heavy_synthesis_agent["Heavy Synthesis<br/>agent"]
  node_critic_agent["Critic<br/>agent<br/>[critic_agent.py]"]
  node_llm_client["LLM Client<br/>gemini adapter<br/>[llm_client.py]"]
  node_source_ranker["Ranker<br/>scoring service<br/>[source_ranker.py]"]
  node_evidence_aggregator["Aggregator<br/>evidence service"]
  node_rag_engine[("RAG Engine<br/>retrieval index<br/>[rag_engine.py]")]
  node_search_tools["Search Tools<br/>acquisition tools<br/>[search_tools.py]"]
  node_scraper["Scraper<br/>content fetcher<br/>[scraper.py]"]
  node_normalizer["Normalizer<br/>text cleanup<br/>[normalizer.py]"]
  node_state_model["State Model<br/>schemas<br/>[state.py]"]
end

subgraph group_frontend["Frontend"]
  node_app["Dashboard<br/>react app<br/>[App.tsx]"]
  node_client["API Client<br/>browser client<br/>[client.ts]"]
end

subgraph group_storage["Storage"]
  node_database[("SQLite DB<br/>persistence<br/>[database.py]")]
end

node_main -->|"runs"| node_pipeline
node_server -->|"starts"| node_pipeline
node_server -->|"starts"| node_heavy_pipeline
node_server -->|"persists"| node_database
node_server -->|"answers chat"| node_rag_engine
node_app -->|"uses"| node_client
node_client -->|"requests"| node_server
node_pipeline -->|"updates"| node_state_model
node_heavy_pipeline -->|"updates"| node_state_model
node_pipeline -->|"plans"| node_planner_agent
node_pipeline -->|"searches"| node_search_agent
node_heavy_pipeline -->|"searches"| node_academic_search_agent
node_pipeline -->|"ranks"| node_source_ranker
node_pipeline -->|"extracts"| node_extraction_agent
node_pipeline -->|"aggregates"| node_evidence_aggregator
node_pipeline -->|"synthesizes"| node_synthesis_agent
node_heavy_pipeline -->|"synthesizes"| node_heavy_synthesis_agent
node_pipeline -->|"checks"| node_critic_agent
node_heavy_pipeline -->|"checks"| node_critic_agent
node_search_agent -->|"uses"| node_search_tools
node_academic_search_agent -->|"uses"| node_search_tools
node_search_tools -->|"fetches"| node_scraper
node_scraper -->|"cleans"| node_normalizer
node_planner_agent -->|"calls"| node_llm_client
node_search_agent -->|"calls"| node_llm_client
node_academic_search_agent -->|"calls"| node_llm_client
node_extraction_agent -->|"calls"| node_llm_client
node_synthesis_agent -->|"calls"| node_llm_client
node_heavy_synthesis_agent -->|"calls"| node_llm_client
node_critic_agent -->|"calls"| node_llm_client
node_evidence_aggregator -->|"calls"| node_llm_client
node_rag_engine -->|"reads/writes"| node_database

click node_main "https://github.com/bragadeez/research-system/blob/main/main.py"
click node_server "https://github.com/bragadeez/research-system/blob/main/api/server.py"
click node_pipeline "https://github.com/bragadeez/research-system/blob/main/orchestrator/pipeline.py"
click node_heavy_pipeline "https://github.com/bragadeez/research-system/blob/main/orchestrator/heavy_pipeline.py"
click node_planner_agent "https://github.com/bragadeez/research-system/blob/main/agents/planner_agent.py"
click node_search_agent "https://github.com/bragadeez/research-system/blob/main/agents/search_agent.py"
click node_academic_search_agent "https://github.com/bragadeez/research-system/blob/main/agents/academic_search_agent.py"
click node_extraction_agent "https://github.com/bragadeez/research-system/blob/main/agents/extraction_agent.py"
click node_synthesis_agent "https://github.com/bragadeez/research-system/blob/main/agents/synthesis_agent.py"
click node_heavy_synthesis_agent "https://github.com/bragadeez/research-system/blob/main/agents/heavy_synthesis_agent.py"
click node_critic_agent "https://github.com/bragadeez/research-system/blob/main/agents/critic_agent.py"
click node_llm_client "https://github.com/bragadeez/research-system/blob/main/core/llm_client.py"
click node_source_ranker "https://github.com/bragadeez/research-system/blob/main/core/source_ranker.py"
click node_evidence_aggregator "https://github.com/bragadeez/research-system/blob/main/core/evidence_aggregator.py"
click node_rag_engine "https://github.com/bragadeez/research-system/blob/main/core/rag_engine.py"
click node_search_tools "https://github.com/bragadeez/research-system/blob/main/tools/search_tools.py"
click node_scraper "https://github.com/bragadeez/research-system/blob/main/tools/scraper.py"
click node_normalizer "https://github.com/bragadeez/research-system/blob/main/tools/normalizer.py"
click node_state_model "https://github.com/bragadeez/research-system/blob/main/models/state.py"
click node_database "https://github.com/bragadeez/research-system/blob/main/db/database.py"
click node_app "https://github.com/bragadeez/research-system/blob/main/frontend/src/App.tsx"
click node_client "https://github.com/bragadeez/research-system/blob/main/frontend/src/api/client.ts"

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_main,node_server,node_pipeline,node_heavy_pipeline,node_planner_agent,node_search_agent,node_academic_search_agent,node_extraction_agent,node_synthesis_agent,node_heavy_synthesis_agent,node_critic_agent,node_llm_client,node_source_ranker,node_evidence_aggregator,node_rag_engine,node_search_tools,node_scraper,node_normalizer,node_state_model toneBlue
class node_app,node_client toneAmber
class node_database toneMint
```

## Components

### Backend

Python API, orchestration, agents, and persistence

- [CLI Run](https://github.com/bragadeez/research-system/blob/main/main.py): entrypoint · Terminal entry point for launching research runs · `main.py`
- [API Server](https://github.com/bragadeez/research-system/blob/main/api/server.py): fastapi · HTTP and WebSocket boundary for the web UI · `api/server.py`
- [Standard Flow](https://github.com/bragadeez/research-system/blob/main/orchestrator/pipeline.py): langgraph workflow · Main research state machine from planning through critique · `orchestrator/pipeline.py`
- [Heavy Flow](https://github.com/bragadeez/research-system/blob/main/orchestrator/heavy_pipeline.py): langgraph workflow · Academic and literature-review research variant · `orchestrator/heavy_pipeline.py`
- [Planner](https://github.com/bragadeez/research-system/blob/main/agents/planner_agent.py): agent · Breaks the question into subtopics and search tasks · `agents/planner_agent.py`
- [Search](https://github.com/bragadeez/research-system/blob/main/agents/search_agent.py): agent · Finds general web sources · `agents/search_agent.py`
- [Academic Search](https://github.com/bragadeez/research-system/blob/main/agents/academic_search_agent.py): agent · Finds scholarly and literature sources · `agents/academic_search_agent.py`
- [Extractor](https://github.com/bragadeez/research-system/blob/main/agents/extraction_agent.py): agent · Pulls atomic facts and evidence from sources · `agents/extraction_agent.py`
- [Synthesis](https://github.com/bragadeez/research-system/blob/main/agents/synthesis_agent.py): agent · Drafts the standard final report · `agents/synthesis_agent.py`
- [Heavy Synthesis](https://github.com/bragadeez/research-system/blob/main/agents/heavy_synthesis_agent.py): agent · Drafts the academic-mode final report · `agents/heavy_synthesis_agent.py`
- [Critic](https://github.com/bragadeez/research-system/blob/main/agents/critic_agent.py): agent · Checks quality, completeness, and retry conditions · `agents/critic_agent.py`
- [LLM Client](https://github.com/bragadeez/research-system/blob/main/core/llm_client.py): gemini adapter · Central model access with fallback and key rotation · `core/llm_client.py`
- [Ranker](https://github.com/bragadeez/research-system/blob/main/core/source_ranker.py): scoring service · Scores and orders candidate sources · `core/source_ranker.py`
- [Aggregator](https://github.com/bragadeez/research-system/blob/main/core/evidence_aggregator.py): evidence service · Clusters and reconciles extracted evidence · `core/evidence_aggregator.py`
- [RAG Engine](https://github.com/bragadeez/research-system/blob/main/core/rag_engine.py): retrieval index · Indexes reports for follow-up Q&A · `core/rag_engine.py`
- [Search Tools](https://github.com/bragadeez/research-system/blob/main/tools/search_tools.py): acquisition tools · Connects to web and academic search providers · `tools/search_tools.py`
- [Scraper](https://github.com/bragadeez/research-system/blob/main/tools/scraper.py): content fetcher · Extracts readable page content from URLs · `tools/scraper.py`
- [Normalizer](https://github.com/bragadeez/research-system/blob/main/tools/normalizer.py): text cleanup · Cleans and standardizes fetched text · `tools/normalizer.py`
- [State Model](https://github.com/bragadeez/research-system/blob/main/models/state.py): schemas · Typed research state and intermediate contracts · `models/state.py`

### Frontend

React/Vite dashboard and browser API client

- [Dashboard](https://github.com/bragadeez/research-system/blob/main/frontend/src/App.tsx): react app · Frontend UI for control, progress, reports, and chat · `frontend/src/App.tsx`
- [API Client](https://github.com/bragadeez/research-system/blob/main/frontend/src/api/client.ts): browser client · REST and WebSocket boundary from the browser · `frontend/src/api/client.ts`

### Storage

Persistent runtime data and exported artifacts

- [SQLite DB](https://github.com/bragadeez/research-system/blob/main/db/database.py): persistence · Stores sessions, reports, and chat history · `db/database.py`

## Connections

- CLI Run → Standard Flow: runs · CLI launches the standard research workflow
- API Server → Standard Flow: starts · API requests create research runs
- API Server → Heavy Flow: starts · API requests can select the academic workflow
- API Server → SQLite DB: persists · Sessions, reports, and chat history are stored
- API Server → RAG Engine: answers chat · Report chat queries are routed through retrieval
- Dashboard → API Client: uses · UI calls the browser-side API wrapper
- API Client → API Server: requests · REST and WebSocket traffic reaches the backend
- Standard Flow → State Model: updates · Workflow stages move structured state forward
- Heavy Flow → State Model: updates · Academic workflow uses the same contract style
- Standard Flow → Planner: plans · Initial decomposition into subtopics and tasks
- Standard Flow → Search: searches · General source discovery stage
- Heavy Flow → Academic Search: searches · Scholarly source discovery stage
- Standard Flow → Ranker: ranks · Candidate sources are scored before extraction
- Standard Flow → Extractor: extracts · Selected sources are turned into evidence
- Standard Flow → Aggregator: aggregates · Evidence is clustered and reconciled
- Standard Flow → Synthesis: synthesizes · Standard report drafting stage
- Heavy Flow → Heavy Synthesis: synthesizes · Academic-mode report drafting stage
- Standard Flow → Critic: checks · Quality review can trigger retry loops
- Heavy Flow → Critic: checks · Academic-mode critique and retry decisions
- Search → Search Tools: uses · Search agents depend on acquisition tools
- Academic Search → Search Tools: uses · Academic search also uses acquisition tools
- Search Tools → Scraper: fetches · Discovered URLs are converted to readable text
- Scraper → Normalizer: cleans · Raw page text is normalized for downstream stages
- Planner → LLM Client: calls · Planning uses model generation
- Search → LLM Client: calls · Search orchestration can use model assistance
- Academic Search → LLM Client: calls · Academic search orchestration can use model assistance
- Extractor → LLM Client: calls · Fact extraction is model-driven
- Synthesis → LLM Client: calls · Report drafting uses the model client
- Heavy Synthesis → LLM Client: calls · Academic drafting uses the model client
- Critic → LLM Client: calls · Critique and retry decisions use model scoring
- Aggregator → LLM Client: calls · Evidence reconciliation may use model assistance
- RAG Engine → SQLite DB: reads/writes · Retrieval index is backed by stored artifacts
