# farhann198/fake-news-detection architecture

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

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

## Overview

1. **Repository shape**
   - This is a small, notebook-driven machine learning project rather than a multi-module application.
   - The main executable artifact is `fake-news-detection.ipynb`; the `.ipynb_checkpoints` copy is just a Jupyter autosave.

2. **Primary inputs**
   - The project ships with two CSV datasets: `True.csv` and `Fake - Fake.csv`.
   - These represent the two classification classes: real news and fake news.
   - The README indicates the original source is Kaggle’s “Fake and Real News Dataset.”

3. **Core workflow**
   - The notebook appears to implement a linear NLP classification pipeline:
     data loading → text cleaning → feature extraction → model training → model comparison.
   - This is an offline batch workflow, not a streaming or interactive inference service.

4. **Text preprocessing boundary**
   - Raw article text is normalized before modeling.
   - The README lists the cleaning steps: lowercasing, punctuation removal, URL removal, special-character removal, number removal, and extra-space trimming.
   - This preprocessing boundary is important because every downstream model consumes the cleaned text, not the original articles.

5. **Feature extraction layer**
   - The main representation step is TF-IDF vectorization with n-grams.
   - The specific configuration noted in the README is `TfidfVectorizer(ngram_range=(1,2))`.
   - This converts the text corpus into sparse numeric features used by all classifiers.

6. **Modeling layer**
   - The project compares several standard scikit-learn classifiers:
     Logistic Regression, Decision Tree, Random Forest, and Gradient Boosting.
   - These models form the core “decision” subsystem and are trained on the same vectorized feature space for fair comparison.

7. **Evaluation flow**
   - The notebook evaluates the models on processed data to compare classification performance.
   - The README emphasizes accuracy comparison rather than deployment metrics, suggesting the goal is model benchmarking and selection.
   - Any diagram should show evaluation branching after training, with multiple model paths converging into comparison.

8. **Technology stack**
   - Python is the runtime.
   - Pandas and NumPy support data handling, while scikit-learn provides preprocessing, vectorization, and classifiers.
   - Jupyter Notebook is the execution environment and the main user interface for the project.

9. **System boundaries**
   - All logic is contained locally in the notebook and CSV files; there is no API layer, database, or external inference endpoint.
   - The Kaggle dataset source is the only external dependency mentioned, and it is used as an offline data source rather than a live integration.

10. **Likely architecture diagram view**
   - A correct diagram would show: two labeled CSV inputs feeding a notebook pipeline, a preprocessing stage, a TF-IDF feature stage, four parallel classifier branches, and an evaluation/comparison output.
   - The repository has no separate service boundaries, so the primary architectural separation is between data, text processing, feature engineering, and model comparison.

Main entry points: [`fake-news-detection.ipynb`](https://github.com/farhann198/fake-news-detection/blob/main/fake-news-detection.ipynb) (Notebook), [`True.csv`](https://github.com/farhann198/fake-news-detection/blob/main/True.csv) (True news), [`Fake - Fake.csv`](https://github.com/farhann198/fake-news-detection/blob/HEAD/Fake%20-%20Fake.csv) (Fake news)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data"]
  node_true_csv[("True news<br/>csv dataset<br/>[True.csv]")]
  node_fake_csv[("Fake news<br/>csv dataset<br/>[Fake - Fake.csv]")]
end

subgraph group_pipeline["Pipeline"]
  node_notebook["Notebook<br/>jupyter entrypoint"]
  node_load_merge["Load data<br/>data prep"]
  node_clean_text["Clean text<br/>nlp preprocessing"]
  node_tfidf["TF-IDF<br/>feature extraction"]
  node_evaluate["Compare models<br/>evaluation"]
  node_accuracy(("Accuracy output<br/>result"))
end

subgraph group_models["Models"]
  node_logreg["Logistic Reg.<br/>classifier"]
  node_tree["Decision Tree<br/>classifier"]
  node_forest["Random Forest<br/>classifier"]
  node_gboost["Gradient Boosting<br/>classifier"]
end

node_true_csv -->|"real articles"| node_load_merge
node_fake_csv -->|"fake articles"| node_load_merge
node_notebook -->|"orchestrates"| node_load_merge
node_load_merge -->|"raw text"| node_clean_text
node_clean_text -->|"normalized text"| node_tfidf
node_tfidf -->|"features"| node_logreg
node_tfidf -->|"features"| node_tree
node_tfidf -->|"features"| node_forest
node_tfidf -->|"features"| node_gboost
node_logreg -->|"score"| node_evaluate
node_tree -->|"score"| node_evaluate
node_forest -->|"score"| node_evaluate
node_gboost -->|"score"| node_evaluate
node_evaluate -->|"report"| node_accuracy
node_notebook -->|"runs"| node_accuracy

click node_notebook "https://github.com/farhann198/fake-news-detection/blob/main/fake-news-detection.ipynb"
click node_true_csv "https://github.com/farhann198/fake-news-detection/blob/main/True.csv"
click node_fake_csv "https://github.com/farhann198/fake-news-detection/blob/main/Fake - Fake.csv"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_true_csv,node_fake_csv toneBlue
class node_notebook,node_load_merge,node_clean_text,node_tfidf,node_evaluate,node_accuracy toneAmber
class node_logreg,node_tree,node_forest,node_gboost toneMint
```

## Components

### Data

Offline CSV sources used for binary news classification.

- [True news](https://github.com/farhann198/fake-news-detection/blob/main/True.csv): csv dataset · Labeled real-news articles. · `True.csv`
- [Fake news](https://github.com/farhann198/fake-news-detection/blob/HEAD/Fake%20-%20Fake.csv): csv dataset · Labeled fake-news articles. · `Fake - Fake.csv`

### Pipeline

Notebook-driven text processing and feature engineering flow.

- [Notebook](https://github.com/farhann198/fake-news-detection/blob/main/fake-news-detection.ipynb): jupyter entrypoint · Main executable notebook that runs the end-to-end experiment. · `fake-news-detection.ipynb`
- **Load data**: data prep · Reads both CSVs and assembles the classification corpus.
- **Clean text**: nlp preprocessing · Lowercases and removes punctuation, URLs, special characters, numbers, and extra spaces.
- **TF-IDF**: feature extraction · Builds n-gram TF-IDF vectors for the cleaned text corpus.
- **Compare models**: evaluation · Ranks classifier performance and selects the strongest model.
- **Accuracy output**: result · Notebook-level comparison of classification accuracy.

### Models

Scikit-learn classifiers compared on the same feature space.

- **Logistic Reg.**: classifier · Linear baseline model trained on TF-IDF features.
- **Decision Tree**: classifier · Tree-based classifier trained on TF-IDF features.
- **Random Forest**: classifier · Ensemble tree classifier trained on TF-IDF features.
- **Gradient Boosting**: classifier · Boosted classifier trained on TF-IDF features.

## Connections

- True news → Load data: real articles · Provides the real-news class.
- Fake news → Load data: fake articles · Provides the fake-news class.
- Notebook → Load data: orchestrates · Notebook executes the data-loading step.
- Load data → Clean text: raw text · Merged corpus enters the cleaning boundary.
- Clean text → TF-IDF: normalized text · Cleaned articles are vectorized into sparse features.
- TF-IDF → Logistic Reg.: features · Shared TF-IDF feature matrix.
- TF-IDF → Decision Tree: features · Shared TF-IDF feature matrix.
- TF-IDF → Random Forest: features · Shared TF-IDF feature matrix.
- TF-IDF → Gradient Boosting: features · Shared TF-IDF feature matrix.
- Logistic Reg. → Compare models: score · Model performance feeds comparison.
- Decision Tree → Compare models: score · Model performance feeds comparison.
- Random Forest → Compare models: score · Model performance feeds comparison.
- Gradient Boosting → Compare models: score · Model performance feeds comparison.
- Compare models → Accuracy output: report · Comparison produces accuracy-focused results.
- Notebook → Accuracy output: runs · Notebook displays the final comparison output.
