A full‑stack system that analyzes news articles to estimate whether content is likely real or fake using an NLP pipeline and machine learning.
- Overview
- Features
- Tech Stack
- Architecture & Flow
- Project Structure
- Requirements
- Setup & Run
- Configuration
- API Reference
- Data Model
- Model & Preprocessing
- Retraining Workflow
- Troubleshooting
- Security & Production Notes
Input
- News title & body text or a source URL to scrape.
Processing
- Clean & lemmatize text
- Vectorize with TF‑IDF
- Classify using a trained ML model
Output
label:real|fakeconfidence: probability score
All predictions are stored in MongoDB for history and analytics.
-
🎨 Responsive React UI with a polished dark theme
-
🔗 URL scraping using Axios + Cheerio
-
⚡ Real‑time classification (Node → Python subprocess)
-
🗂 Persistent prediction history (MongoDB)
-
📊 Analytics dashboard:
- Total predictions
- Real/Fake ratio
- Average confidence
- Confidence histogram
- Top source domains
-
🚀 One‑command setup to install and run everything
-
🔁 Retraining endpoint to rebuild the model from CSV
- React
- Vite
- Tailwind CSS
- Framer Motion
- lucide‑react icons
- Node.js
- Express
- Axios
- Cheerio
- MongoDB (native driver)
- Python
- scikit‑learn
- NLTK
- joblib
---
## Project Structure
NewsLens/ ├─ client/ # React frontend │ ├─ pages/ │ │ ├─ Input (/) │ │ ├─ Result (/result) │ │ └─ Analytics (/analytics) │ ├─ server/ # Express backend │ ├─ index.js │ └─ routes/ │ ├─ predict.js │ ├─ history.js │ ├─ analytics.js │ ├─ retrain.js │ └─ health.js │ ├─ model/ # Python ML pipeline │ ├─ src/ │ │ ├─ preprocess.py │ │ ├─ train.py │ │ └─ predict.py │ ├─ saved_models/ │ │ ├─ model.pkl │ │ ├─ vectorizer.pkl │ │ └─ metrics.json │ └─ requirements.txt │ └─ README.md
---
## Requirements
* **Node.js** ≥ 18
* **npm**
* **Python** ≥ 3.9
* **pip**
* **MongoDB** (local or remote)
---
## Setup & Run
From the project root:
```bash
npm start
This command will:
-
Install frontend & backend dependencies
-
Install Python requirements from
model/requirements.txt -
Start:
- Backend →
http://localhost:3001 - Frontend →
http://localhost:5173
- Backend →
Environment variables (optional):
MONGO_URI=mongodb://127.0.0.1:27017/NewsLens
MONGO_DB=NewsLens
WELFAKE_CSV=WELFake_Dataset.csvBody
{
"title": "optional",
"text": "optional",
"url": "optional"
}Response
{
"status": "ok",
"label": "real | fake",
"confidence": 0.93
}{
"status": "ok",
"items": [ { "input": {}, "result": {}, "ts": 0, "domain": "" } ]
}{
"status": "ok",
"totals": {},
"time": {},
"top_domains": [],
"confidence_hist": []
}{
"status": "ok",
"best_model": "LogisticRegression",
"metrics": {}
}{ "status": "ok" }{
"input": { "title": "...", "url": "...", "text": "..." },
"result": { "label": "real|fake", "confidence": 0.93 },
"ts": 1736450000000,
"domain": "example.com"
}{
"_id": "global",
"total": 120,
"real": 78,
"fake": 42,
"sumConfidence": 98.5,
"updatedAt": "2026-01-09T16:05:00Z"
}-
Label mapping:
0 → real,1 → fake -
Text preprocessing:
- Lowercasing
- HTML & URL removal
- Non‑alphabetic filtering
- Stop‑word removal
- Lemmatization (WordNet)
-
Vectorization:
- TF‑IDF (uni‑grams & bi‑grams)
max_features = 50000min_df = 2max_df = 0.95
-
Models evaluated:
- Multinomial Naive Bayes
- Logistic Regression
-
Model selection: Best F1 score wins
Artifacts are saved in model/saved_models/ and loaded at inference time.
- Call
POST /retrainor run:
python model/src/train.py- Ensure
WELFAKE_CSVpoints to the dataset - New artifacts overwrite old ones
- All future predictions use the updated model
-
pip install errors:
python -m pip install -r model/requirements.txt
-
MongoDB connection issues:
- Verify MongoDB is running
- Check
MONGO_URI
-
NLTK WordNet missing:
nltk.download('wordnet')
-
CORS issues:
- CORS is enabled by default in
server/index.js
- CORS is enabled by default in
- Enable HTTPS
- Add authentication & rate limiting
- Redact or hash sensitive text before storage
- Use managed MongoDB (Atlas) in production
- Store secrets using environment variables
🚀 NewsLens — turning misinformation into insight.



