# ali26m/top_fake_news_classifier architecture

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

- Interactive diagram: https://gitdiagram.com/ali26m/top_fake_news_classifier
- Repository: https://github.com/ali26m/top_fake_news_classifier

## Overview

##### Main Components
- Core AI & Model Training:
- Training Module: Represented by the “Training/TOP.ipynb” which demonstrates the process of data processing, NLP techniques, TF-IDF analysis, and decision tree model training.
- Pickled Objects: These include “api/dt.pkl”, “api/transformer.pkl”, and “api/vectorizer.pkl” that store the pre-trained models and vectorizers used at runtime.
- API Layer:
- The “api” directory contains “topapi.py” (the FastAPI-based code) coupled with “requirements.txt” (dependencies) that expose a cloud-based RESTful API (as mentioned in the README when hosted on KOYEB).
- User Interfaces:
- Chrome Extension: Found in the “extension” directory with its manifest, popup.html, popup.css, and popup.js files. This module provides quick classification directly within the browser.
- Web Application: The “web” directory contains HTML, CSS, JS files, and media assets. This module provides a user-friendly interface where users can input text and get predictions.

##### Out the Data Flow & Interactions
- Users are interacting with either the Web App or the Chrome Extension.
- Both front-ends send requests to the API endpoint provided by the FastAPI server.
- The API Layer:
- Upon receiving a request, it loads the pre-trained models (decision tree, TF-IDF transformer, etc.) from the saved pickle files.
- The API then processes the input data (news article content) using the AI model pipeline (NLP, TF-IDF, decision tree) to produce a classification (fake or real).
- The prediction result is then returned to the calling front-end.
- Optional: The Training module (TOP.ipynb) could be annotated to show that it was used to set up or update the models. It is not part of the live pipeline but is vital during development and model improvement cycles.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Clear distinction between data/model training (Training) and the production-level inference service (API).
- Separation between the front-end clients (Web vs. Extension) and the backend API.
- Cloud-Native & Scalability:
- The API is deployed in a cloud environment (KOYEB) ensuring scalability and accessibility.
- Modularity:
- Each component (Training, API, Chrome Extension, Web App) has its own directory, indicating that they are developed as separate but interrelated modules.

##### Relevant Technologies & Frameworks
- FastAPI: Powers the RESTful API.
- Python Libraries for Machine Learning: Including scikit-learn for the decision tree, NLP, and TF-IDF functionalities.
- Frontend Web Technologies: HTML, CSS, JavaScript for the web client.
- Chrome Extension APIs: For integrating the extension interface.
- Cloud Hosting Platform: KOYEB for deploying the API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Users
    U["User"]:::user

    %% Frontend Interfaces
    subgraph "User Interfaces"
        EXT["Chrome Extension"]:::frontend
        WEB["Web Application"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
        API["API Server (FastAPI on KOYEB)"]:::api
        MF["Model Files<br/>(dt.pkl, transformer.pkl, vectorizer.pkl)"]:::ai
        TR["Training/Model Development<br/>(TOP.ipynb)"]:::ai
    end

    %% Data Flow
    U -->|"interacts"| EXT
    U -->|"interacts"| WEB

    EXT -->|"sendsRequest"| API
    WEB -->|"sendsRequest"| API

    API -->|"loadsModels"| MF
    MF -->|"providesPredictions"| API

    API -->|"returnsResult"| EXT
    API -->|"returnsResult"| WEB

    TR -.->|"updatesModels"| MF

    %% Click Events
    click TR "https://github.com/ali26m/top_fake_news_classifier/blob/main/Training/TOP.ipynb"
    click API "https://github.com/ali26m/top_fake_news_classifier/blob/main/api/topapi.py"
    click EXT "https://github.com/ali26m/top_fake_news_classifier/blob/main/extension/manifest.json"
    click WEB "https://github.com/ali26m/top_fake_news_classifier/blob/main/web/home.html"
    click MF "https://github.com/ali26m/top_fake_news_classifier/blob/main/api/dt.pkl"

    %% Styles
    classDef user fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef frontend fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef api fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef ai fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
```
