# nishitpatel01/fake_news_detection architecture

> Architecture diagram of the GitHub repository nishitpatel01/fake_news_detection, 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/nishitpatel01/fake_news_detection
- Repository: https://github.com/nishitpatel01/fake_news_detection

## Overview

##### Project Type and Purpose
- This is a machine-learning pipeline for Fake News Detection written in Python. It contains an offline training pipeline (data preparation → feature engineering → model training) and an online inference layer (prediction via CLI or a lightweight web front end).

##### Main Components
a. Data Layer
- Raw data: `liar_dataset/*.tsv` (original Liar dataset)
- Flattened CSVs: `train.csv`, `valid.csv`, `test.csv`
b. Offline Training Pipeline
- DataPrep.py – reads raw CSV/TSV, tokenizes, stems, cleans, performs EDA
- FeatureSelection.py – vectorizes text (BOW, n-grams, TF-IDF), (optional Word2Vec/POS)
- classifier.py – trains multiple sklearn classifiers (Naive Bayes, LR, SVM, RF), performs grid search, evaluates, selects best models
- Model Artifacts – `final_model.sav`, `model.pkl`, `my_model/`
c. Online Inference Layer
- prediction.py – CLI script that loads the saved model and classifies a user-provided headline, outputs class & probability
- front.py + `index` + CSS/JS assets (`bootstrap.css`, `animate.css`, `project.css`, etc.) – lightweight web front end serving an HTML form that sends text to the backend for prediction
d. Environment & Dependencies
- Python 3.6 runtime
- Libraries: scikit-learn, numpy, scipy (installed via pip or conda)

##### Relationships & Data Flow
1. Raw TSV/CSV data → DataPrep.py → cleaned DataFrames
2. Cleaned data → FeatureSelection.py → feature matrices (X_train, X_test, X_valid)
3. Feature matrices → classifier.py → trained model(s) → serialized to disk
4. Online: User input (CLI or Web UI) → prediction.py (or front.py invokes prediction) → load model → return “True/False” + probability → display to user

##### Architectural Patterns & Design Principles
- Linear ETL pipeline for offline processing
- Separation of Concerns:
- Preprocessing, feature engineering, and model training are isolated modules
- Inference (prediction) is decoupled from training
- Web UI (front.py + static files) separated from the core ML code
- MVC-style for the web front end:
- View: `index` HTML + CSS
- Controller: front.py
- Model: prediction.py + serialized model

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        RawData["Raw Data\n(liar_dataset/*.tsv)"]:::datastore
        Flattened["Flattened CSVs\n(train.csv, valid.csv, test.csv)"]:::datastore
    end

    %% Offline Training
    subgraph "Offline Training"
        direction TB
        DataPrep["DataPrep.py\n(tokenize, clean, EDA)"]:::process
        FeatureSel["FeatureSelection.py\n(TF-IDF, n-grams)"]:::process
        Classifier["classifier.py\n(GridSearchCV, ML models)"]:::process
        Notebook["final-fnd.ipynb"]:::process
    end

    %% Model Artifacts
    subgraph "Model Artifacts"
        direction TB
        ModelSav["final_model.sav"]:::datastore
        ModelPkl["model.pkl"]:::datastore
        ModelDir["my_model/"]:::datastore
    end

    %% Inference Layer
    subgraph "Online Inference"
        direction TB
        CLI["prediction.py\n(CLI)"]:::inference
        Front["front.py\n(Web Controller)"]:::inference
        View["index (HTML)"]:::ui
        Assets["Static Assets\n(CSS/JS)"]:::ui
        Images["images/"]:::ui
    end

    %% Data Flow
    RawData -->|"raw data"| DataPrep
    DataPrep -->|"cleaned data"| Flattened
    Flattened -->|"X_train, X_test, X_valid"| FeatureSel
    FeatureSel -->|"feature matrices"| Classifier
    Classifier -->|"serialize model"| ModelSav
    Classifier --> ModelPkl
    Classifier --> ModelDir
    Classifier --> Notebook

    %% Inference Connections
    ModelSav -->|"load model"| CLI
    ModelPkl --> CLI
    ModelDir --> CLI
    ModelSav -->|"load model"| Front
    ModelPkl --> Front
    ModelDir --> Front
    Front -->|"serves form"| View
    Front -->|"serves assets"| Assets
    Front -->|"serves images"| Images
    CLI -->|"prediction & prob"| User["User"]:::external
    Front -->|"prediction & prob"| User

    %% Legend
    subgraph "Legend"
        direction TB
        subgraph Colors
            A1["Rectangle = Process"]:::process
            A2["Cylinder = Data Store"]:::datastore
            A3["Parallelogram = Interface/UI"]:::ui
        end
    end

    %% Click Events
    click RawData "https://github.com/nishitpatel01/fake_news_detection/tree/master/liar_dataset/"
    click Flattened "https://github.com/nishitpatel01/fake_news_detection/blob/master/train.csv"
    click Flattened "https://github.com/nishitpatel01/fake_news_detection/blob/master/valid.csv"
    click Flattened "https://github.com/nishitpatel01/fake_news_detection/blob/master/test.csv"
    click DataPrep "https://github.com/nishitpatel01/fake_news_detection/blob/master/DataPrep.py"
    click FeatureSel "https://github.com/nishitpatel01/fake_news_detection/blob/master/FeatureSelection.py"
    click Classifier "https://github.com/nishitpatel01/fake_news_detection/blob/master/classifier.py"
    click Notebook "https://github.com/nishitpatel01/fake_news_detection/blob/master/final-fnd.ipynb"
    click ModelSav "https://github.com/nishitpatel01/fake_news_detection/blob/master/final_model.sav"
    click ModelPkl "https://github.com/nishitpatel01/fake_news_detection/blob/master/model.pkl"
    click ModelDir "https://github.com/nishitpatel01/fake_news_detection/tree/master/my_model/"
    click CLI "https://github.com/nishitpatel01/fake_news_detection/blob/master/prediction.py"
    click Front "https://github.com/nishitpatel01/fake_news_detection/blob/master/front.py"
    click View "https://github.com/nishitpatel01/fake_news_detection/tree/master/index"
    click Assets "https://github.com/nishitpatel01/fake_news_detection/blob/master/animate.css"
    click Assets "https://github.com/nishitpatel01/fake_news_detection/blob/master/bootstrap.css"
    click Assets "https://github.com/nishitpatel01/fake_news_detection/blob/master/project.css"
    click Assets "https://github.com/nishitpatel01/fake_news_detection/blob/master/font.css"
    click Assets "https://github.com/nishitpatel01/fake_news_detection/blob/master/li-scroller.css"
    click Assets "https://github.com/nishitpatel01/fake_news_detection/blob/master/style.css"
    click Assets "https://github.com/nishitpatel01/fake_news_detection/blob/master/theme.css"
    click Images "https://github.com/nishitpatel01/fake_news_detection/tree/master/images/"

    %% Styles
    classDef datastore fill:#D8BFD8,stroke:#8B008B,color:#000
    classDef process fill:#ADD8E6,stroke:#00008B,color:#000
    classDef inference fill:#90EE90,stroke:#006400,color:#000
    classDef ui fill:#FFA500,stroke:#FF8C00,color:#000
    classDef external fill:#ffffff,stroke:#000,color:#000,stroke-dasharray: 5 5
```
