# shrutijaiswal2905/fake-news-detection-website architecture

> Architecture diagram of the GitHub repository shrutijaiswal2905/fake-news-detection-website, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shrutijaiswal2905/fake-news-detection-website
- Repository: https://github.com/shrutijaiswal2905/fake-news-detection-website

## Overview

##### Project Type and Purpose
- This is a data-science-driven, single-page Streamlit application for **real-time fake-news detection**.
- It combines a **lightweight frontend** (Streamlit UI) with a **backend ML inference pipeline** (TF-IDF vectorization + Logistic Regression), plus calls to **external services** (GNews API, Newspaper3k).

##### File Structure
Top-level:
- .gitignore, LICENSE, README.md
- Fake-News-Detection/
– .streamlit/config.toml (UI theming & Streamlit config)
– .vscode/ (IDE settings)
– app.py (main Streamlit app entry point)
– appbackup.py (previous iteration of app.py)
– Fake.csv, True.csv (training data snapshots)
– vectorizer.jb, lr_model.jb (serialized TF-IDF vectorizer & Logistic Regression model)
– requirements.txt (python dependencies)

##### Key Insights from README
- **Frontend**: Single Streamlit dashboard, dark theme, multiple input modes (URL, keyword, text).
- **Backend**: Loads a pre-trained TF-IDF vectorizer + Logistic Regression model via Joblib; uses Newspaper3k for parsing URL content, GNews API for live headlines.
- **Flow**: Input → fetch & preprocess → vectorize → model.predict → display result.

##### Main Components
a. User Interface (Streamlit App)
b. Input Handler
- URL fetcher (Newspaper3k)
- GNews API client
- Text ingestion (manual input)
c. Preprocessing Pipeline
- Text cleaning & normalization
- TF-IDF Vectorizer (vectorizer.jb)
d. Inference Engine
- Logistic Regression Classifier (lr_model.jb)
e. Results Renderer (Streamlit)
f. External Services
- GNews API
- Newspaper3k extraction
g. Local Artifacts
- Fake.csv / True.csv (training data) – optional, shown for context
- vectorizer.jb, lr_model.jb (model artifacts)

##### Relationships & Data Flows
- (Optionally) show model artifacts loaded from disk at app startup

##### Architectural Patterns & Principles
- **Separation of Concerns**: UI, data fetching, preprocessing, inference all distinct
- **Initialization-Time Loading**: Load vectorizer & model once to minimize latency
- **Stateless Requests**: Each user action is handled independently
- **External-Service Adapters**: Wrap GNews API & Newspaper3k in dedicated modules

##### Final Checklist
[ ] Clear labels for each component
[ ] A container or boundary showing “Streamlit App” vs. “External Services” vs. “Local Artifacts”

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User["User"]:::external

    %% Streamlit App
    subgraph "Streamlit App"
        UI["Streamlit UI"]:::frontend
        Config["config.toml"]:::frontend
        URLHandler["URL Fetcher (Newspaper3k)"]:::frontend
        GNewsHandler["GNews API Client"]:::frontend
        TextHandler["Manual Text Ingestion"]:::frontend
        Results["Results Renderer"]:::frontend
    end

    %% Preprocessing Pipeline
    subgraph "Preprocessing Pipeline"
        Cleaning["Text Cleaning & Normalization"]:::ml
        Vectorizer["TF-IDF Vectorizer"]:::ml
    end

    %% Inference Engine
    subgraph "Inference Engine"
        LRModel["Logistic Regression Classifier"]:::ml
    end

    %% External Services
    subgraph "External Services"
        GNewsAPI["GNews API"]:::external
        Newspaper["Newspaper3k"]:::external
    end

    %% Local Artifacts
    subgraph "Local Artifacts"
        FakeData["Fake.csv"]:::artifacts
        TrueData["True.csv"]:::artifacts
        Requirements["requirements.txt"]:::artifacts
        VectorArtifact["vectorizer.jb"]:::artifacts
        ModelArtifact["lr_model.jb"]:::artifacts
    end

    %% Data Flows
    User -->|"1. select mode"| UI
    UI -->|"2a. URL mode"| URLHandler
    UI -->|"2b. Keyword mode"| GNewsHandler
    UI -->|"2c. Text mode"| TextHandler

    URLHandler -->|"raw HTML/text"| Cleaning
    GNewsHandler -->|"raw JSON/text"| Cleaning
    TextHandler -->|"raw text"| Cleaning

    Cleaning -->|"feature vector"| Vectorizer
    Vectorizer --> LRModel
    LRModel -->|"prediction"| Results
    Results -->|"5. display result"| User

    %% Artifact Loading at Startup
    VectorArtifact -.-> Vectorizer
    ModelArtifact -.-> LRModel

    %% External calls
    URLHandler --> Newspaper
    GNewsHandler --> GNewsAPI

    %% Click Events
    click UI "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/app.py"
    click URLHandler "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/app.py"
    click GNewsHandler "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/app.py"
    click TextHandler "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/app.py"
    click Cleaning "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/app.py"
    click Results "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/app.py"
    click Config "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/.streamlit/config.toml"
    click VectorArtifact "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/vectorizer.jb"
    click ModelArtifact "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/lr_model.jb"
    click FakeData "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/Fake.csv"
    click TrueData "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/True.csv"
    click Requirements "https://github.com/shrutijaiswal2905/fake-news-detection-website/blob/main/Fake-News-Detection/requirements.txt"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef ml fill:#90EE90,stroke:#000,stroke-width:1px
    classDef external fill:#FFD580,stroke:#000,stroke-width:1px
    classDef artifacts fill:#D3D3D3,stroke:#000,stroke-width:1px
```
