# omspatil/news-classifier architecture

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

## Overview

##### Project type and purpose
- This is a full-stack web application built in Python using Flask.
- Purpose: allow users to input news URLs or raw text, scrape/parse the article, classify it as real or fake with a pre-trained scikit-learn model, show the result, record query history, and accept feedback.

##### File structure
Top-level items:
- app.py – Flask application entry point and controller logic
- New Preditor/ – data folder (Fake.csv, True.csv), sample texts (fake_news.txt, true_news.txt), images, plus the Jinja templates and static assets for the UI
- README.md – project overview
- (Note: README refers to a models/ directory containing classifier.pkl)

Inside New Preditor/:
- Data/ – CSVs of labeled news examples; likely used for retraining or feedback persistence
- static/ – styles.css for the frontend
- templates/ – index.html Jinja template
- Images/ – UI screenshots
- fake_news.txt / true_news.txt – sample text inputs

##### Key components & interactions
a. Client (Browser)
- Renders the HTML/CSS (index.html + styles.css)
- Sends HTTP POST requests with URL or text payload when user clicks “Predict”
- Displays prediction results and history UI

b. Flask Backend (app.py)
- Routes:
- GET “/” → serves index.html
- POST “/predict” → handles input, orchestrates scraping, classification, history update
- GET/POST “/history” → returns or manages past queries
- POST “/feedback” → records user feedback
- Uses Beautiful Soup + requests to fetch & parse article from a URL
- Loads pre-trained scikit-learn model (classifier.pkl) to predict
- Persists query details & feedback to Data/Fake.csv or Data/True.csv (or other storage)

c. ML Model Store
- classifier.pkl – pre-trained model file on disk
- Loaded once at startup by app.py

d. Data Storage
- CSV files under New Preditor/Data – used for history & feedback
- ASCII text files (fake_news.txt, true_news.txt) for testing or training samples

e. External Services
- Internet (news websites) via HTTP requests for scraping
- (Optionally) any logging/monitoring or future DB

##### Architectural patterns & design principles
- MVC-ish:
- Model: ML model + data CSVs
- View: Jinja2 templates + static CSS
- Controller: Flask routes in app.py
- Single process monolith with clear separation of concerns
- Dependency injection principle: load model at startup, reuse for all predictions
- Stateless request handling; small stateful CSV appends for history

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        Browser["Client Browser\n(index.html, styles.css)"]:::ui
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Flask["Flask Server\n(app.py)"]:::backend
    end

    %% Data & Model Layer
    subgraph "Data & Model Layer"
        Model["Classifier (classifier.pkl)"]:::model
        DataStore["CSV Data Store\nFake.csv, True.csv"]:::data
        Samples["Sample Text Inputs\nfake_news.txt, true_news.txt"]:::data
    end

    %% External Services
    subgraph "External Services"
        Web["External News Websites"]:::external
    end

    %% Connections
    Browser -->|"HTTP POST /predict"| Flask
    Flask -->|"HTTP GET URL"| Web
    Web -->|"raw HTML"| Flask
    Flask -->|"parse (Beautiful Soup)"| Flask
    Flask -->|"predict (scikit-learn)"| Model
    Model -->|"prediction label"| Flask
    Flask -->|"append record"| DataStore
    Flask -->|"HTTP Response"| Browser

    %% Click Events
    click Browser "https://github.com/omspatil/news-classifier/blob/main/New Preditor/templates/index.html"
    click Browser "https://github.com/omspatil/news-classifier/blob/main/New Preditor/static/styles.css"
    click Flask "https://github.com/omspatil/news-classifier/blob/main/New Preditor/app.py"
    click Model "https://github.com/omspatil/news-classifier/blob/main/models/classifier.pkl"
    click DataStore "https://github.com/omspatil/news-classifier/blob/main/New Preditor/Data/Fake.csv"
    click DataStore "https://github.com/omspatil/news-classifier/blob/main/New Preditor/Data/True.csv"
    click Samples "https://github.com/omspatil/news-classifier/blob/main/New Preditor/fake_news.txt"
    click Samples "https://github.com/omspatil/news-classifier/blob/main/New Preditor/true_news.txt"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#4da3ff,color:#004085;
    classDef backend fill:#d4edda,stroke:#28a745,color:#155724;
    classDef data fill:#fff3cd,stroke:#ffc107,color:#856404;
    classDef model fill:#ffe5b4,stroke:#ff8c00,color:#8b4513;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#343a40;
```
