# sakshamagarwalm2/reasearchpaperagent architecture

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

- Interactive diagram: https://gitdiagram.com/sakshamagarwalm2/reasearchpaperagent
- Repository: https://github.com/sakshamagarwalm2/reasearchpaperagent

## Overview

##### Project type and purpose
- This is a single-page, Streamlit-based full-stack web application (“AI Research Paper Companion”) that serves as a research assistant.
- It orchestrates a multi-agent AI framework (CrewAI) to explain topics, fetch literature from arXiv, and analyze research gaps using OpenAI and Groq models.

##### File structure
- Top-level files only:
- research_companion.py (the Streamlit app entry point)
- requirements.txt (Python dependencies, including Streamlit, python-dotenv, CrewAI framework, OpenAI, Groq clients)
- .gitignore, README, demo video.
- No separate “frontend” or “backend” folders—UI and orchestration logic are co-located in one Python module.
- Configuration via a `.env` file (loaded by python-dotenv) supplies API keys.

##### README for insights
- Technologies: Python 3.8+, Streamlit, CrewAI, OpenAI API, Groq API, arXiv API.
- Agents: Topic Explainer, Literature Finder, Gap Analyzer.
- Runtime flow: user selects model and options in the sidebar → starts analysis → CrewAI spawns agents → agents call external services → results returned to the UI.

##### Main components & interactions
- User’s Web Browser (Client)
- Streamlit Application (research_companion.py)
- CrewAI Orchestrator / Agent Manager
– Topic Explainer Agent
– Literature Finder Agent
– Gap Analyzer Agent
- External AI Model Providers
– OpenAI API
– Groq API
- External Data Source
– arXiv API
- Configuration Store
– `.env` file via python-dotenv

1. Browser → Streamlit App: HTTP/WebSocket request when user clicks “Start Analysis.”
2. Streamlit App → CrewAI Orchestrator: invoke multi-agent workflow.
3. Orchestrator → Agents: dispatch tasks (Explain, Find Papers, Find Gaps).
4. Agents → OpenAI/Groq API: send prompts and receive completions.
5. Literature Finder Agent → arXiv API: execute search queries, retrieve paper metadata/abstracts.
6. Agents → Orchestrator: return processed results.
7. Orchestrator → Streamlit App: aggregate agent outputs.
8. Streamlit App → Browser: update UI with explanations, paper summaries, gap analysis.

c. Architectural patterns & principles
- Multi-Agent Orchestration Pattern: decouple responsibilities into specialized agents under a central manager.
- MVC-ish separation: Streamlit UI (View/Controller) vs. Agent logic (Model/Service).
- API Integration Pattern for external services (OpenAI, Groq, arXiv).
- Configuration isolation via environment variables.

d. Key technologies & libraries
- Streamlit (UI layer)
- CrewAI framework (agent orchestration)
- python-dotenv (configuration)
- OpenAI & Groq Python SDKs (LLM providers)
- HTTP client for arXiv (e.g., `requests`)
- Core language: Python 3.8+

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    Browser["User’s Web Browser"]:::ui
    Config["Configuration Store (.env)"]:::config
    Dependencies["Python Dependencies & API Clients"]:::config
    StreamlitApp["Streamlit Application"]:::ui

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        Orchestrator["CrewAI Orchestrator / Agent Manager"]:::orchestration
        subgraph Agents
            Explainer["Topic Explainer Agent"]:::orchestration
            Finder["Literature Finder Agent"]:::orchestration
            Analyzer["Gap Analyzer Agent"]:::orchestration
        end
    end

    %% External Services
    OpenAIAPI["OpenAI API"]:::external
    GroqAPI["Groq API"]:::external
    ArxivAPI["arXiv API"]:::external

    %% Data Flows
    Browser -->|"1. HTTP/WebSocket Start Analysis"| StreamlitApp
    Config -->|"Load configuration"| StreamlitApp
    Dependencies -->|"Installed APIs & SDKs"| StreamlitApp
    StreamlitApp -->|"2. invoke multi-agent workflow"| Orchestrator
    Orchestrator -->|"3a. dispatch Explain task"| Explainer
    Orchestrator -->|"3b. dispatch Find Papers task"| Finder
    Orchestrator -->|"3c. dispatch Gap Analysis task"| Analyzer
    Explainer -->|"4. POST prompt"| OpenAIAPI
    Finder -->|"5a. POST prompt"| OpenAIAPI
    Finder -->|"5b. GET query"| ArxivAPI
    Analyzer -->|"6. POST prompt"| GroqAPI
    Explainer -->|"6a. return processed data"| Orchestrator
    Finder -->|"6b. return processed data"| Orchestrator
    Analyzer -->|"6c. return processed data"| Orchestrator
    Orchestrator -->|"7. aggregate agent outputs"| StreamlitApp
    StreamlitApp -->|"8. update UI"| Browser

    %% Click Events
    click StreamlitApp "https://github.com/sakshamagarwalm2/reasearchpaperagent/blob/main/research_companion.py"
    click Orchestrator "https://github.com/sakshamagarwalm2/reasearchpaperagent/blob/main/research_companion.py"
    click Config "https://github.com/sakshamagarwalm2/reasearchpaperagent/blob/main/.env"
    click Dependencies "https://github.com/sakshamagarwalm2/reasearchpaperagent/blob/main/requirements.txt"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#21618C,stroke-width:2px;
    classDef orchestration fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef external fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef config fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
