# mehulsingh08/kg-summarizer architecture

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

- Interactive diagram: https://gitdiagram.com/mehulsingh08/kg-summarizer
- Repository: https://github.com/mehulsingh08/kg-summarizer

## Overview

##### Project Type and Purpose
- This is a two‐tier full-stack NLP web application for “Educational Text Summarization using Knowledge Graphs.”
- Frontend: a Streamlit UI (`frontend/app.py`) that users interact with in the browser (http://localhost:8501).
- Backend: a Flask API server (`backend/app.py`) that hosts the summarization logic and ML components (http://127.0.0.1:5000).
- Purpose: take input text (e.g., arXiv abstracts), apply a hybrid unsupervised summarization pipeline (TF-IDF vectorizer, K-Means clustering, sentence-importance learner, enhanced TextRank), and return a summary.

##### File Structure
- Top-level directories:
- backend/ – Flask app, ML logic (model.py), utilities (utils.py), pre-trained artifacts (`.pkl`) and dependencies.
- frontend/ – Streamlit app presenting the web UI and calling the backend API.
- data/ – static CSV datasets (arxiv_data.csv, test_set.csv).
- Important files:
- backend/models/*.pkl – pre-trained vectorizer, cluster model, weights, etc.
- test_setup.py – likely orchestration or CI checks.
- requirements.txt in each tier – defines Python dependencies.
- Architectural hints:
- Clear separation of concerns: UI vs API vs ML pipeline.
- No external database—uses file‐based persisted models and CSV.

##### README for Additional Insights
- The README confirms a two-process setup (Flask + Streamlit).
- Lists the four ML components that form the hybrid summarizer.

##### Detail
- Every .pkl artifact as a child node of the Model Store.
- Utils.py usage: preprocessing → vectorizer.
- Sequence: vectorizer → clustering → sentence scorer → TextRank → postprocessing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User("User"):::external
    Test["Test Orchestration / CI"]:::external

    subgraph "Presentation Layer"
        UI["Streamlit UI"]:::frontend
        FDeps["requirements.txt"]:::deps
    end

    subgraph "Service Layer"
        API["Flask API Server"]:::backend
        BDeps["requirements.txt"]:::deps
        Utils["Preprocessing Utilities"]:::util
        ModelEntry["Pipeline Entry (model.py)"]:::backend
    end

    subgraph "Summarization Pipeline"
        TFIDF["TF-IDF Vectorizer"]:::ml
        KMeans["K-Means Topic Clusterer"]:::ml
        Importance["Sentence Importance Learner"]:::ml
        TRank["Enhanced TextRank Scorer"]:::ml
    end

    subgraph "Data & Model Stores"
        ModelStore["Model Artifacts Store"]:::store
        Arxiv["arxiv_data.csv"]:::store
        TestSet["test_set.csv"]:::store
    end

    %% User Flow
    User --> UI
    UI -->|"POST /summarize"| API
    API --> ModelEntry
    ModelEntry --> TFIDF
    TFIDF --> KMeans
    KMeans --> Importance
    Importance --> TRank
    TRank -->|"summary JSON"| API
    API --> UI

    %% Utilities & Stores
    API --> Utils
    Utils --> TFIDF
    API --> ModelStore
    API --> Arxiv
    API --> TestSet

    %% CI Tests
    Test --> API
    Test --> UI

    %% Click Events
    click UI "https://github.com/mehulsingh08/kg-summarizer/blob/main/frontend/app.py"
    click FDeps "https://github.com/mehulsingh08/kg-summarizer/blob/main/frontend/requirements.txt"
    click API "https://github.com/mehulsingh08/kg-summarizer/blob/main/backend/app.py"
    click BDeps "https://github.com/mehulsingh08/kg-summarizer/blob/main/backend/requirements.txt"
    click Utils "https://github.com/mehulsingh08/kg-summarizer/blob/main/backend/utils.py"
    click ModelEntry "https://github.com/mehulsingh08/kg-summarizer/blob/main/backend/model.py"
    click TFIDF "https://github.com/mehulsingh08/kg-summarizer/blob/main/backend/models/vectorizer.pkl"
    click KMeans "https://github.com/mehulsingh08/kg-summarizer/blob/main/backend/models/topic_clusters.pkl"
    click Importance "https://github.com/mehulsingh08/kg-summarizer/blob/main/backend/models/importance_weights.pkl"
    click TRank "https://github.com/mehulsingh08/kg-summarizer/blob/main/backend/model.py"
    click ModelStore "https://github.com/mehulsingh08/kg-summarizer/tree/main/backend/models/"
    click Arxiv "https://github.com/mehulsingh08/kg-summarizer/blob/main/data/arxiv_data.csv"
    click TestSet "https://github.com/mehulsingh08/kg-summarizer/blob/main/data/test_set.csv"
    click Test "https://github.com/mehulsingh08/kg-summarizer/blob/main/test_setup.py"

    %% Styles
    classDef frontend fill:#D6EFFF,stroke:#333,stroke-width:1px
    classDef backend fill:#D4F8E8,stroke:#333,stroke-width:1px
    classDef ml fill:#FFE2A3,stroke:#333,stroke-width:1px
    classDef store fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef util fill:#FFF5BA,stroke:#333,stroke-width:1px
    classDef deps fill:#EAD1DC,stroke:#333,stroke-width:1px
    classDef external fill:#F5F5F5,stroke:#333,stroke-width:1px
```
