# rezabonyadi/digitalra architecture

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

- Interactive diagram: https://gitdiagram.com/rezabonyadi/digitalra
- Repository: https://github.com/rezabonyadi/digitalra

## Overview

##### Project type and purpose
- This is a hybrid full-stack research assistant application offering both a Streamlit web UI (`app.py` + `app_pages/…`) and a CLI interface (`main.py`).
- Its goal is to take a short research idea, generate search queries, fetch papers via the Publish & Perish CLI tool (in `assets/`), score/filter them, and then call OpenAI’s GPT models to summarize/write literature review sections or chat interactively.

##### File structure
- Top‐level entrypoints:
- `app.py` — Streamlit app
- `main.py` — CLI runner
- UI layer:
- `app_pages/` — Streamlit “multi-page” modules (`hire_page.py`, `research.py`, `write_review.py`, `chat.py`, `prepare_ra.py`)
- Core logic (business layer):
- `utils/`
– `prompts.py` (builds GPT prompts)
– `llm_connection.py` (wraps OpenAI API calls)
– `papers_interactions.py` (invokes Publish & Perish CLI, parses results)
– `operations.py` (filters, relevance scoring, sorting)
- Supporting artifacts:
- `assets/` — holds the external CLI executables (Publish & Perish)
- `digitalRA.ipynb` — exploratory notebook
- Config and dependencies:
- `requirements.txt`
- No persistent database; data flows in memory or via temporary files.

##### README for additional insights
- Uses OpenAI GPT models for NLP tasks.
- Integrates PubMed, Semantic Scholar, Google Scholar searches through Publish & Perish.
- Offers two modalities: web (Streamlit) and CLI.
- Emphasizes iterative, user-in-the-loop curation at each step.

##### Main components and their interactions
a. Components
- User (Researcher)
- Frontend
- Streamlit UI (multiple pages)
- CLI interface
- Application Server / Controller
- Orchestrates calls between UI/CLI and core logic
- Core Logic Modules (in `utils/`)
- Prompt Builder (`prompts.py`)
- Paper Fetcher (`papers_interactions.py`)
- Business Rules (`operations.py`)
- LLM Client (`llm_connection.py`)
- External Services
- Publish & Perish CLI (executes search queries)
- OpenAI API (for chat, summarization, review generation)
- Assets Folder (where CLI executables reside)

b. Relationships & Data Flow
1. User → UI/CLI: enters research idea & parameters
2. UI/CLI → Controller: invokes core workflow
3. Controller → Prompt Builder: generates search queries
4. Controller → Paper Fetcher: calls Publish & Perish CLI (from `assets/`), receives raw metadata
5. Controller → Business Rules: relevance scoring, filtering, sorting
6. Controller → LLM Client: passes prompts + selected paper metadata to OpenAI
7. OpenAI → LLM Client → Controller → UI/CLI: returns generated text (chat, section, summary)

c. Architectural patterns & design principles
- Layered separation: Presentation (UI/CLI) → Orchestration → Domain logic (utils) → Integration adapters
- Single-responsibility modules in `utils/`
- Externalization of third-party CLI tools (assets) and APIs (OpenAI)
- User-in-the-loop iterations at each major step

d. Key technologies/frameworks
- Python 3.x
- Streamlit (web UI)
- Publish & Perish CLI (paper search)
- OpenAI GPT models (via HTTP API)
- Jupyter Notebook for prototyping

##### Detail
- Streamlit page as a subcomponent of the Frontend.
- CLI tool path separately (it reuses the same utils modules).
- Don’t omit the assets folder; that’s where the Publish & Perish executables live.
- Flow for “chat with RA” versus “automated review generation” branches are visible.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User["User (Researcher)"]

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        App["Streamlit UI\n(app.py)"]:::frontend
        subgraph "Streamlit Pages"
            direction TB
            Chat["Chat Interface\n(chat.py)"]:::frontend
            Hire["Hire Page\n(hire_page.py)"]:::frontend
            Prepare["Prepare RA\n(prepare_ra.py)"]:::frontend
            Research["Research Workflows\n(research.py)"]:::frontend
            WriteReview["Automated Review\n(write_review.py)"]:::frontend
        end
        CLI["CLI Interface\n(main.py)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        Controller["Controller / Orchestrator"]:::backend
        Prompts["Prompt Builder\n(prompts.py)"]:::core
        Fetcher["Paper Fetcher\n(papers_interactions.py)"]:::core
        Operations["Business Rules\n(operations.py)"]:::core
        LLMClient["LLM Client\n(llm_connection.py)"]:::core
    end

    %% External Layer
    subgraph "External & Assets"
        direction TB
        Assets["Assets Folder\n(assets/)"]:::asset
        PublishPerish["Publish & Perish CLI"]:::external
        OpenAI["OpenAI API"]:::external
    end

    %% Supporting Artifacts
    subgraph "Supporting Artifacts"
        direction TB
        Notebook["Exploratory Notebook\n(digitalRA.ipynb)"]
        Requirements["Dependencies\n(requirements.txt)"]
    end

    %% Data Flow
    User -->|"enter research idea"| App
    User -->|"enter research idea"| CLI

    App -->|"invoke workflow"| Controller
    CLI -->|"invoke workflow"| Controller

    Controller -->|"build search queries"| Prompts
    Controller -->|"fetch papers"| Fetcher
    Controller -->|"score & filter"| Operations
    Controller -->|"call GPT"| LLMClient

    Fetcher -->|"executes CLI"| Assets
    Assets --> PublishPerish

    LLMClient -->|"HTTP POST"| OpenAI
    OpenAI -->|"response"| LLMClient

    LLMClient --> Controller
    Controller --> App
    Controller --> CLI

    App --> User
    CLI --> User

    %% Click Events
    click App "https://github.com/rezabonyadi/digitalra/blob/main/app.py"
    click Chat "https://github.com/rezabonyadi/digitalra/blob/main/app_pages/chat.py"
    click Hire "https://github.com/rezabonyadi/digitalra/blob/main/app_pages/hire_page.py"
    click Prepare "https://github.com/rezabonyadi/digitalra/blob/main/app_pages/prepare_ra.py"
    click Research "https://github.com/rezabonyadi/digitalra/blob/main/app_pages/research.py"
    click WriteReview "https://github.com/rezabonyadi/digitalra/blob/main/app_pages/write_review.py"
    click CLI "https://github.com/rezabonyadi/digitalra/blob/main/main.py"
    click Prompts "https://github.com/rezabonyadi/digitalra/blob/main/utils/prompts.py"
    click Fetcher "https://github.com/rezabonyadi/digitalra/blob/main/utils/papers_interactions.py"
    click Operations "https://github.com/rezabonyadi/digitalra/blob/main/utils/operations.py"
    click LLMClient "https://github.com/rezabonyadi/digitalra/blob/main/utils/llm_connection.py"
    click Assets "https://github.com/rezabonyadi/digitalra/tree/main/assets/"
    click Notebook "https://github.com/rezabonyadi/digitalra/blob/main/digitalRA.ipynb"
    click Requirements "https://github.com/rezabonyadi/digitalra/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#FFFFFF,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef asset fill:#D3D3D3,stroke:#333,stroke-width:1px
```
