# vanshpatel024/fake-news-detector architecture

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

- Interactive diagram: https://gitdiagram.com/vanshpatel024/fake-news-detector
- Repository: https://github.com/vanshpatel024/fake-news-detector

## Overview

##### Project type and purpose
- This is a full-stack web application called “Fake News Detector.”
- The user interacts via a React/Vite frontend. The frontend calls a FastAPI backend, which loads a serialized ML model (Tfidf + LogisticRegression) to predict whether a submitted URL or text is “fake news.”

##### File structure
- Top-level directories:
- backend/ – contains the FastAPI service and model code
- client/ – contains the React/Vite application
- backend/app/
- main.py – defines API routes (POST endpoints for URL or text submission)
- main_model.pkl – the pre-trained ML model artifact
- model/fetcher.py – logic to fetch and sanitize HTML/text from a URL
- model/predictor.py – wraps the ML model, performs feature extraction (Tfidf) and inference
- requirements.txt – Python dependencies for FastAPI, scikit-learn, etc.
- client/src/
- Components/ – React UI elements (Header, Footer, cards, notifications)
- Pages/Home.jsx – the main page with input form and result display
- Utils/Api.js – encapsulates HTTP calls to FastAPI endpoints
- StyleSheets/ – CSS modules per component
- main.jsx / index.html – Vite entrypoints
- Deployment config:
- client/vite.config.js – build settings for Vite
- .gitignore files in both subprojects

##### README for additional insights
- Frontend deployed on Vercel, backend on Render.
- No persistent database; the primary state is the loaded ML model.
- Two user flows: “Analyze by URL” and “Analyze by Text.”

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Global Entities
    User["Web Browser (User)"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer (Vercel)"
        direction TB
        SPA["React SPA"]:::frontend
        ApiUtil["Api.js"]:::frontend
        HomePage["Home.jsx"]:::frontend
        HeaderComp["Header.jsx"]:::frontend
        FooterComp["Footer.jsx"]:::frontend
        InfoCardsComp["InfoCards.jsx"]:::frontend
        NotificationComp["Notification.jsx"]:::frontend
        ResultCardComp["ResultCard.jsx"]:::frontend
        FNDCardComp["FNDCard.jsx"]:::frontend
        Styles["StyleSheets/"]:::frontend
        ViteConf["vite.config.js"]:::frontend
        HTMLTemp["index.html"]:::frontend
        Entry["main.jsx"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer (Render)"
        direction TB
        FastAPI["FastAPI Service"]:::backend
        ModelModule["Model Module"]:::ml
        Requirements["requirements.txt"]:::backend

        subgraph "Model Module"
            direction TB
            Predictor["predictor.py"]:::ml
            Fetcher["fetcher.py"]:::ml
            ModelFile["main_model.pkl"]:::ml
        end
    end

    %% External Service
    NewsSource["External News Source"]:::external

    %% Deployment
    subgraph Deployment
        direction TB
        Vercel["Vercel"]:::infra
        RenderHost["Render"]:::infra
    end

    %% Connections
    User -->|"interacts with"| SPA
    SPA -->|"calls Api.js"| ApiUtil
    SPA -->|"renders Home Page"| HomePage
    HomePage --> HeaderComp
    HomePage --> FooterComp
    HomePage --> InfoCardsComp
    HomePage --> NotificationComp
    HomePage --> ResultCardComp
    HomePage --> FNDCardComp
    HomePage --> Styles
    SPA -->|"POST /predict-url or /predict-json"| FastAPI
    ApiUtil --> FastAPI
    FastAPI -->|"loads on startup"| ModelFile
    FastAPI -->|"calls predictor.predict()"| Predictor
    Predictor -->|"for URL flow"| Fetcher
    Fetcher -->|"fetches text"| NewsSource
    Predictor -->|"returns label & confidence"| FastAPI
    FastAPI -->|"returns JSON"| SPA

    %% Click Events
    click SPA "https://github.com/vanshpatel024/fake-news-detector/tree/main/client/"
    click Entry "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/src/main.jsx"
    click HTMLTemp "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/index.html"
    click ApiUtil "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/src/Utils/Api.js"
    click HomePage "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/src/Pages/Home.jsx"
    click HeaderComp "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/src/Components/Header.jsx"
    click FooterComp "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/src/Components/Footer.jsx"
    click InfoCardsComp "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/src/Components/InfoCards.jsx"
    click NotificationComp "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/src/Components/Notification.jsx"
    click ResultCardComp "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/src/Components/ResultCard.jsx"
    click FNDCardComp "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/src/Components/FNDCard.jsx"
    click Styles "https://github.com/vanshpatel024/fake-news-detector/tree/main/client/src/StyleSheets/"
    click ViteConf "https://github.com/vanshpatel024/fake-news-detector/blob/main/client/vite.config.js"
    click FastAPI "https://github.com/vanshpatel024/fake-news-detector/blob/main/backend/app/main.py"
    click ModelFile "https://github.com/vanshpatel024/fake-news-detector/blob/main/backend/app/main_model.pkl"
    click Fetcher "https://github.com/vanshpatel024/fake-news-detector/blob/main/backend/app/model/fetcher.py"
    click Predictor "https://github.com/vanshpatel024/fake-news-detector/blob/main/backend/app/model/predictor.py"
    click Requirements "https://github.com/vanshpatel024/fake-news-detector/blob/main/backend/requirements.txt"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366d6,color:#032f62
    classDef backend fill:#DFFFE0,stroke:#28a745,color:#1e4620
    classDef ml fill:#FFE4B2,stroke:#d18b00,color:#663c00
    classDef external fill:#F0F0F0,stroke:#6a737d,color:#1f1f1f
    classDef infra fill:#E8E8E8,stroke:#a0a0a0,color:#333333
```
