How bragadeez/research-system works
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: pipeline.py Standard Flow · llm_client.py LLM Client · heavy_pipeline.py Heavy Flow · server.py API Server
Components 22
Backend
Python API, orchestration, agents, and persistence
- CLI Run · Terminal entry point for launching research runs
main.py - API Server · HTTP and WebSocket boundary for the web UI
api/server.py - Standard Flow · Main research state machine from planning through critique
orchestrator/pipeline.py - Heavy Flow · Academic and literature-review research variant
orchestrator/heavy_pipeline.py - Planner · Breaks the question into subtopics and search tasks
agents/planner_agent.py - Search · Finds general web sources
agents/search_agent.py - Academic Search · Finds scholarly and literature sources
agents/academic_search_agent.py - Extractor · Pulls atomic facts and evidence from sources
agents/extraction_agent.py - Synthesis · Drafts the standard final report
agents/synthesis_agent.py - Heavy Synthesis · Drafts the academic-mode final report
agents/heavy_synthesis_agent.py - Critic · Checks quality, completeness, and retry conditions
agents/critic_agent.py - LLM Client · Central model access with fallback and key rotation
core/llm_client.py - Ranker · Scores and orders candidate sources
core/source_ranker.py - Aggregator · Clusters and reconciles extracted evidence
core/evidence_aggregator.py - RAG Engine · Indexes reports for follow-up Q&A
core/rag_engine.py - Search Tools · Connects to web and academic search providers
tools/search_tools.py - Scraper · Extracts readable page content from URLs
tools/scraper.py - Normalizer · Cleans and standardizes fetched text
tools/normalizer.py - State Model · Typed research state and intermediate contracts
models/state.py
Frontend
React/Vite dashboard and browser API client
- Dashboard · Frontend UI for control, progress, reports, and chat
frontend/src/App.tsx - API Client · REST and WebSocket boundary from the browser
frontend/src/api/client.ts
Storage
Persistent runtime data and exported artifacts
- SQLite DB · Stores sessions, reports, and chat history
db/database.py
Connections 32
- 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