# anikpal-code/multiagent-research-system architecture

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

- Interactive diagram: https://gitdiagram.com/anikpal-code/multiagent-research-system
- Repository: https://github.com/anikpal-code/multiagent-research-system

## Overview

1. **Two main boundaries**
   - The repo is split into a **backend AI service** and a **single Expo frontend codebase**.
   - The frontend runs as **web, iOS, and Android** from `mobile/`.
   - The backend is a **FastAPI** app in the repo root, intended to be deployed separately.

2. **User-facing flow**
   - A user enters a research topic in the mobile/web UI.
   - The frontend sends that topic to the backend.
   - The backend executes a **four-stage research pipeline** and streams intermediate progress back live.
   - The UI updates incrementally instead of waiting for a final response.

3. **Frontend subsystem**
   - `mobile/App.tsx` bootstraps the Expo app.
   - `mobile/src/screens/HomeScreen.tsx` is the main interaction screen.
   - `mobile/src/components/StepTracker.tsx` and `LogCard.tsx` render stage progress and event logs.
   - `mobile/src/api.ts` is the client-side SSE/API bridge.
   - `mobile/src/theme.ts` holds UI styling tokens.

4. **Frontend architecture style**
   - The Expo app is a **presentation layer** plus a small networking layer.
   - It does not implement the research logic locally.
   - Its job is to collect input, subscribe to streamed backend events, and render status/output.

5. **Backend entrypoint and transport**
   - `main.py` is the server entrypoint and FastAPI application.
   - It exposes at least a health endpoint and the research execution endpoint.
   - Progress is delivered through **Server-Sent Events**, which matches the “live progress” UI design.

6. **Core AI orchestration**
   - `agents.py` contains the LangChain-based orchestration.
   - The system is explicitly structured as four sequential agents/chains:
     **search → read → write → critique**.
   - The model referenced in the README is **Mistral (`mistral-small-latest`)** via LangChain `create_agent`.

7. **Tooling and data access**
   - `tools.py` provides the external-data layer.
   - It includes a **web search tool** and a **URL scraping tool**.
   - Scraping uses **requests** and **BeautifulSoup**, so the backend depends on raw HTTP fetches plus HTML parsing rather than a browser automation stack.

8. **Pipeline behavior and state flow**
   - The research pipeline is stateful across stages: search results feed the reader, reader output feeds the writer, and the written report feeds the critic.
   - The backend emits progress as each stage completes, which is what the UI visualizes.
   - This makes the system a **streaming workflow engine** rather than a simple request/response API.

9. **Legacy/alternate execution path**
   - `pipeline.py` is the original **CLI version** of the same research workflow.
   - It likely reuses the same core agent/tool logic but without the web/mobile streaming layer.
   - In architecture terms, it is a secondary entrypoint for running the pipeline outside the UI.

10. **External dependencies that matter architecturally**
   - The system depends on an **LLM provider** for generation and critique.
   - It depends on **web pages/search results** as source material.
   - Hosting is split between **Render** for the backend and **Vercel** for the frontend.

11. **Operational characteristics**
   - The backend is on a free tier and can cold-start after inactivity, so initial latency may be significant.
   - There is no evident auth or rate limiting in the repo, so the backend is meant for demo/internal use rather than open public traffic.
   - The README notes the web search is currently a stub, so the search stage is an integration point rather than a fully productionized dependency.

12. **What to show in an architecture diagram**
   - Draw a **client boundary** for the Expo app.
   - Draw a **backend boundary** for FastAPI.
   - Inside the backend, show a linear pipeline of four stages with shared state.
   - Show **SSE streaming** from backend to client.
   - Show external arrows to **LLM provider** and **web/search + scraped pages**.

Main entry points: [`mobile/src/screens/HomeScreen.tsx`](https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/screens/HomeScreen.tsx) (Home screen), [`main.py`](https://github.com/anikpal-code/multiagent-research-system/blob/main/main.py) (FastAPI app), [`mobile/src/api.ts`](https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/api.ts) (API bridge), [`agents.py`](https://github.com/anikpal-code/multiagent-research-system/blob/main/agents.py) (Orchestrator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Expo client"]
  node_mobile_app["App bootstrap<br/>expo entrypoint<br/>[App.tsx]"]
  node_home_screen["Home screen<br/>ui screen<br/>[HomeScreen.tsx]"]
  node_api_bridge["API bridge<br/>sse client<br/>[api.ts]"]
  node_step_tracker["Step tracker<br/>ui component<br/>[StepTracker.tsx]"]
  node_log_card["Log card<br/>ui component<br/>[LogCard.tsx]"]
  node_theme_tokens["Theme tokens<br/>ui theme<br/>[theme.ts]"]
end

subgraph group_backend["FastAPI backend"]
  node_server_main["FastAPI app<br/>server entrypoint<br/>[main.py]"]
  node_orchestrator["Orchestrator<br/>workflow core<br/>[agents.py]"]
  node_search_stage["Search<br/>pipeline stage"]
  node_read_stage["Read<br/>pipeline stage"]
  node_write_stage["Write<br/>pipeline stage"]
  node_critique_stage["Critique<br/>pipeline stage"]
  node_tools_layer["Tools<br/>data access<br/>[tools.py]"]
end

subgraph group_cli["CLI pipeline"]
  node_pipeline_cli["CLI pipeline<br/>legacy runner<br/>[pipeline.py]"]
end

subgraph group_external["External systems"]
  node_llm_provider[("LLM provider<br/>external service")]
  node_web_sources[("Web sources<br/>external data")]
end

node_mobile_app -->|"boots"| node_home_screen
node_home_screen -->|"submits topic"| node_api_bridge
node_home_screen -->|"shows progress"| node_step_tracker
node_home_screen -->|"shows logs"| node_log_card
node_home_screen -->|"uses theme"| node_theme_tokens
node_api_bridge -->|"SSE request"| node_server_main
node_server_main -->|"starts run"| node_orchestrator
node_orchestrator -->|"stage 1"| node_search_stage
node_search_stage -->|"feeds evidence"| node_read_stage
node_read_stage -->|"feeds notes"| node_write_stage
node_write_stage -->|"feeds draft"| node_critique_stage
node_search_stage -->|"searches"| node_tools_layer
node_read_stage -->|"scrapes"| node_tools_layer
node_write_stage -->|"generates"| node_llm_provider
node_critique_stage -->|"reviews"| node_llm_provider
node_tools_layer -->|"queries"| node_web_sources
node_server_main -->|"streams events"| node_api_bridge
node_pipeline_cli -->|"reuses core"| node_orchestrator

click node_mobile_app "https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/App.tsx"
click node_home_screen "https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/screens/HomeScreen.tsx"
click node_api_bridge "https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/api.ts"
click node_step_tracker "https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/components/StepTracker.tsx"
click node_log_card "https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/components/LogCard.tsx"
click node_theme_tokens "https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/theme.ts"
click node_server_main "https://github.com/anikpal-code/multiagent-research-system/blob/main/main.py"
click node_orchestrator "https://github.com/anikpal-code/multiagent-research-system/blob/main/agents.py"
click node_tools_layer "https://github.com/anikpal-code/multiagent-research-system/blob/main/tools.py"
click node_pipeline_cli "https://github.com/anikpal-code/multiagent-research-system/blob/main/pipeline.py"

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_mobile_app,node_home_screen,node_api_bridge,node_step_tracker,node_log_card,node_theme_tokens toneBlue
class node_server_main,node_orchestrator,node_search_stage,node_read_stage,node_write_stage,node_critique_stage,node_tools_layer toneAmber
class node_pipeline_cli toneMint
class node_llm_provider,node_web_sources toneRose
```

## Components

### Expo client

Mobile/web presentation layer in the Expo app

- [App bootstrap](https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/App.tsx): expo entrypoint · Starts the Expo application and wires the root UI · `mobile/App.tsx`
- [Home screen](https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/screens/HomeScreen.tsx): ui screen · Main input and results screen for research requests · `mobile/src/screens/HomeScreen.tsx`
- [API bridge](https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/api.ts): sse client · Client-side API and Server-Sent Events connection · `mobile/src/api.ts`
- [Step tracker](https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/components/StepTracker.tsx): ui component · Renders stage progress in the research workflow · `mobile/src/components/StepTracker.tsx`
- [Log card](https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/components/LogCard.tsx): ui component · Displays streamed event logs and updates · `mobile/src/components/LogCard.tsx`
- [Theme tokens](https://github.com/anikpal-code/multiagent-research-system/blob/main/mobile/src/theme.ts): ui theme · Shared styling and design tokens for the Expo app · `mobile/src/theme.ts`

### FastAPI backend

Streaming research service and orchestration pipeline

- [FastAPI app](https://github.com/anikpal-code/multiagent-research-system/blob/main/main.py): server entrypoint · Backend entrypoint exposing health and research endpoints · `main.py`
- [Orchestrator](https://github.com/anikpal-code/multiagent-research-system/blob/main/agents.py): workflow core · Coordinates the sequential research workflow and streaming events · `agents.py`
- **Search**: pipeline stage · Finds relevant sources and prepares initial evidence
- **Read**: pipeline stage · Extracts and interprets content from discovered sources
- **Write**: pipeline stage · Drafts the research report from gathered evidence
- **Critique**: pipeline stage · Reviews and refines the drafted report
- [Tools](https://github.com/anikpal-code/multiagent-research-system/blob/main/tools.py): data access · Web search and URL scraping utilities · `tools.py`

### CLI pipeline

Legacy non-UI execution path

- [CLI pipeline](https://github.com/anikpal-code/multiagent-research-system/blob/main/pipeline.py): legacy runner · Standalone non-web entrypoint for running the workflow · `pipeline.py`

### External systems

LLM and web data sources

- **LLM provider**: external service · Hosted model used for generation and critique
- **Web sources**: external data · Search results and scraped pages used as research input

## Connections

- App bootstrap → Home screen: boots · Root app renders the main screen
- Home screen → API bridge: submits topic · User input is sent to the streaming API layer
- Home screen → Step tracker: shows progress · Main screen displays current workflow stage
- Home screen → Log card: shows logs · Main screen renders streamed events and messages
- Home screen → Theme tokens: uses theme · UI styling is shared through theme tokens
- API bridge → FastAPI app: SSE request · Client connects to backend research endpoint over streaming transport
- FastAPI app → Orchestrator: starts run · FastAPI hands each request to the research workflow
- Orchestrator → Search: stage 1 · Workflow begins with discovery of sources
- Search → Read: feeds evidence · Search output becomes input to reading
- Read → Write: feeds notes · Extracted content drives report drafting
- Write → Critique: feeds draft · Draft is reviewed and improved in the final stage
- Search → Tools: searches · Search stage uses external lookup tools
- Read → Tools: scrapes · Reading stage fetches and parses source pages
- Write → LLM provider: generates · LLM is used to write the report
- Critique → LLM provider: reviews · LLM is used for critique and refinement
- Tools → Web sources: queries · Tools access search results and page content
- FastAPI app → API bridge: streams events · Backend sends progress updates back to the client
- CLI pipeline → Orchestrator: reuses core · Legacy CLI path invokes the same workflow core
