# anmol-bhatta/pubmed architecture

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

- Interactive diagram: https://gitdiagram.com/anmol-bhatta/pubmed
- Repository: https://github.com/anmol-bhatta/pubmed

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“ResearchLens”) for searching and summarizing PubMed papers.
- Frontend: React + TypeScript (Vite) with real-time filters and dark mode.
- Backend: Python Flask service providing search, caching, summarization (using BART or similar transformer models).

##### File Structure Analysis
- Top-level:
- backend/ – Python Flask service, model orchestration, local SQLite DB, caching
- frontend/ – Vite-powered React app (TSX), styling, assets, ESLint and TS config
- backend/ key files:
- app.py – Flask entrypoint, HTTP API endpoints
- pubmed.py – PubMed query logic (external REST API)
- cache_manager.py – local caching of PubMed results (articles.db)
- summarizer.py – transformer model wrapper (BART)
- frontend/ key files:
- src/App.tsx – main React component, API client calls
- components/ArticleList.tsx – list & filter UI
- assets/, public/ – static resources
- Config & deployment hints: Procfile (Heroku), requirements.txt, package.json, Vite config, TS configs

##### README Insights
- Describes component roles (search, summarize, progressive loading)
- Lists tech stack (Python 3.8+, Node 16+, transformer model)
- Deployment targets (Vercel, Heroku, etc.)
- Mentions updating frontend API URL for separate deployments

##### Main Components
a. Frontend (React + Vite)
b. Backend API (Flask app)
c. PubMed External Service (REST API)
d. Summarization Service (Transformer model runtime)
e. Local SQLite Database (articles.db for caching)
f. Optional GPU (if available for model inference)

##### Relationships and Data Flow
- User → Frontend: UI interactions (search criteria, filters)
- Frontend ↔ Backend: JSON over HTTP (search requests, summary requests)
- Backend → PubMed API: fetch paper metadata & abstracts
- Backend ↔ SQLite DB: read/write cached query results
- Backend → Summarizer: feed abstracts to ML model → return summaries
- Backend → Frontend: return search results + summaries

##### Architectural Patterns & Principles
- Separation of concerns: UI vs. data/model logic
- Stateless frontend, stateful backend with caching layer
- Single HTTP API layer for all client interactions
- Modular Python services (pubmed, cache, summarizer) behind Flask
- Progressive loading: stream or batch results to UI

##### Technology Highlights
- Frontend: React, TypeScript, Vite, CSS modules, ESLint
- Backend: Flask, Python 3.8+, SQLite, Hugging Face transformers (BART)
- Deployment: Procfile (Heroku), optional GPU for faster ML

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Zone
    subgraph "Client (Browser)"
        U((User))
        FE["Frontend – React/TS (Vite)"]:::frontend
        A["App.tsx"]:::frontend
        AL["ArticleList.tsx"]:::frontend
        VITE["vite.config.ts"]:::frontend
        ESL["eslint.config.js"]:::frontend
        PKG["package.json"]:::frontend
    end

    %% Server Zone
    subgraph "Server (Cloud/VM)"
        subgraph "API Layer"
            API["Backend API – Flask/Python (app.py)"]:::backend
            PUBMED["pubmed.py"]:::backend
            CACHE["cache_manager.py"]:::backend
            SUMMOD["summarizer.py"]:::backend
            REQ["requirements.txt"]:::backend
            PROC["Procfile"]:::backend
        end
        subgraph "Data Layer"
            DB[(articles.db)]:::storage
        end
        subgraph "External Service"
            EXTPUB[(PubMed REST API)]:::external
        end
        GPU([GPU Accelerator]):::external
    end

    %% Connections
    U --> FE
    FE -->|"HTTP/JSON"| API
    API -->|"lookup cache"| DB
    DB -->|"cached results"| API
    API -->|"fetch papers"| EXTPUB
    EXTPUB -->|"metadata & abstracts"| API
    API -->|"summarize abstracts"| SUMMOD
    SUMMOD -->|"summaries"| API
    API -->|"results+summaries"| FE
    SUMMOD -.->|"optional GPU accel"| GPU

    %% Click Events
    click FE "https://github.com/anmol-bhatta/pubmed/tree/main/frontend/"
    click A "https://github.com/anmol-bhatta/pubmed/blob/main/frontend/src/App.tsx"
    click AL "https://github.com/anmol-bhatta/pubmed/blob/main/frontend/src/components/ArticleList.tsx"
    click VITE "https://github.com/anmol-bhatta/pubmed/blob/main/frontend/vite.config.ts"
    click ESL "https://github.com/anmol-bhatta/pubmed/blob/main/frontend/eslint.config.js"
    click PKG "https://github.com/anmol-bhatta/pubmed/blob/main/frontend/package.json"
    click API "https://github.com/anmol-bhatta/pubmed/blob/main/backend/app.py"
    click PUBMED "https://github.com/anmol-bhatta/pubmed/blob/main/backend/pubmed.py"
    click CACHE "https://github.com/anmol-bhatta/pubmed/blob/main/backend/cache_manager.py"
    click SUMMOD "https://github.com/anmol-bhatta/pubmed/blob/main/backend/summarizer.py"
    click DB "https://github.com/anmol-bhatta/pubmed/blob/main/backend/articles.db"
    click REQ "https://github.com/anmol-bhatta/pubmed/blob/main/backend/requirements.txt"
    click PROC "https://github.com/anmol-bhatta/pubmed/tree/main/backend/Procfile"

    %% Styles
    classDef frontend fill:#ddeeff,stroke:#0000ff,color:#000000
    classDef backend fill:#ddffdd,stroke:#008800,color:#000000
    classDef external fill:#ffe5cc,stroke:#ff7700,color:#000000
    classDef storage fill:#eeeeee,stroke:#888888,color:#000000
```
