# pranjalg13/fake-news-detection architecture

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

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

## Overview

##### Project Type and Purpose
- This project is a full-stack application with an emphasis on natural language processing tasks. The backend is built in Flask, offering two primary functionalities: detecting fake news (using an LSTM model) and clickbait (using a Multinomial Naive Bayes model).
- The README explains the models, dataset details, and the web GUI. The file tree shows the presence of frontend assets (HTML templates and CSS) and backend Python code (app.py, utils.py, and pre-trained models).

##### File Structure
- Key top-level files such as app.py indicate the Flask entry point.
- The templates directory holds the HTML files that form the web interface.
- The static directory contains CSS files used for styling the website.
- The trained_models folder stores serialized models (e.g., clickbait_model.pkl, final_h5_model.h5, vectorizer.pkl) used by the Flask backend during prediction.
- The colab_notebook directory contains exploratory/experimental notebooks documenting the model development process but is not part of the production system.
- The requirements.txt and other documentation files underscore the dependencies and guidelines for contribution.

##### Main Components
a. Frontend:
- Browser/User Interface: Represented by the HTML pages (index.html, clickbait.html, result.html, navbar.html).
- Static Assets: CSS stylesheets that improve the UI aesthetics.
b. Backend:
- Flask Application (app.py): Acts as the server managing routes for the home page, clickbait detection, and fake news detection.
- Utility Functions (utils.py): Contains helper methods to process input, handle predictions, and possibly pre/post-process data.
c. Machine Learning Models:
- Fake News Model: An LSTM model used to predict fake news based on the article content.
- Clickbait Model: A Multinomial Naive Bayes model chosen for its higher accuracy in clickbait detection.
- Model Artifacts: The pre-trained models and vectorizer files in the trained_models directory.
d. Data Flow Components:
- User Input: Text or news article submitted via the frontend.
- Data Preprocessing: Could be part of the utility functions (utils.py) that prepare the text for predictions.
- Prediction Engine: The backend that loads the models, applies them on user data, and returns a prediction.
- Results Response: The Flask application sends results back to the browser to be rendered using HTML templates.

##### Relationships and Interactions
- A user interacts with the system via a web browser, accessing the relevant HTML pages.
- The front end sends HTTP requests (via form submission or AJAX) to the Flask backend (app.py).
- The Flask application invokes utility functions which load the proper model from the trained_models directory and process the user’s input.
- After prediction, the Flask app sends the results back to the appropriate template (like result.html) for display.
- Additionally, the colab_notebook folder illustrates the experimental training processes for different models but is not part of live operations; you may optionally include an “Exploratory Analysis” note if needed.

##### Architectural Patterns and Technologies
- The application follows a Model-View-Controller-like split (even if not pure MVC, there is a clear separation between presentation (HTML/CSS) and business logic (Flask routes and ML models)).
- Use of Flask for web serving, along with Python’s machine learning libraries used to train and run the models.
- Distinction between frontend (user interface) and backend (API/prediction engine).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Components
    subgraph "Frontend"
        Browser["User Browser"]:::frontend
        HTMLTemplates["HTML Templates"]:::frontend
        CSS["Static CSS"]:::frontend
    end

    %% Backend Components
    subgraph "Backend"
        FlaskApp["Flask Application"]:::backend
        Utils["Utility Functions"]:::backend
    end

    %% Machine Learning Components
    subgraph "Machine Learning"
        ModelArtifacts["Model Artifacts"]:::ml
        LSTM["Fake News Model (LSTM)"]:::ml
        NaiveBayes["Clickbait Model (Multinomial Naive Bayes)"]:::ml
    end

    %% Exploratory / Training Resources
    subgraph "Exploratory"
        Colab["Colab Notebook"]:::exploratory
    end

    %% Data Flow
    Browser -->|"submitsRequest"| FlaskApp
    FlaskApp -->|"invokes"| Utils
    Utils -->|"loadsModel"| ModelArtifacts
    ModelArtifacts --- LSTM
    ModelArtifacts --- NaiveBayes
    Utils -->|"callsLSTM"| LSTM
    Utils -->|"callsNB"| NaiveBayes
    LSTM -->|"returnsResult"| FlaskApp
    NaiveBayes -->|"returnsResult"| FlaskApp
    FlaskApp -->|"rendersResultOn"| HTMLTemplates
    HTMLTemplates -->|"appliesStylesFrom"| CSS
    HTMLTemplates -->|"displaysOutputTo"| Browser

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef ml fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef exploratory fill:#f8d7da,stroke:#721c24,stroke-width:2px;

    %% Click Events
    click HTMLTemplates "https://github.com/pranjalg13/fake-news-detection/tree/main/templates"
    click CSS "https://github.com/pranjalg13/fake-news-detection/tree/main/static/styles"
    click FlaskApp "https://github.com/pranjalg13/fake-news-detection/blob/main/app.py"
    click Utils "https://github.com/pranjalg13/fake-news-detection/blob/main/utils.py"
    click ModelArtifacts "https://github.com/pranjalg13/fake-news-detection/tree/main/trained_models"
    click Colab "https://github.com/pranjalg13/fake-news-detection/tree/main/colab_notebook"
```
