A comprehensive, production-ready web application for detecting fake news using AI-powered credibility analysis. Built with React + Vite frontend, Node.js + Express backend, MongoDB database, and Google Gemini API integration, plus a Chrome browser extension.
- Features
- Tech Stack
- Project Structure
- Prerequisites
- Installation
- Configuration
- Running the Application
- API Documentation
- Browser Extension
- Usage Guide
- Database Schema
- Troubleshooting
- Real-time News Detection: Submit headlines or articles for instant credibility analysis
- AI-Powered Analysis: Uses Google Gemini API for advanced fact-checking
- Confidence Scoring: Returns classification (True/Fake/Uncertain) with confidence percentages
- Community Voting: Users can vote on accuracy to build community trust scores
- Detection History: Persistent storage of all analyzed news items
- Browser Extension: Check headlines while browsing the web with hover detection
- Submit news for analysis
- View detailed explanations for each classification
- Vote on accuracy to improve community scores
- Browse detection history with filters
- Responsive design for mobile and desktop
- Toast notifications for success/error feedback
- Track trending fake news patterns
- Monitor community accuracy rates
- View detailed analysis reports
- Export detection history
- React 18.3 - UI library
- Vite 5.0 - Fast build tool and dev server
- TailwindCSS 3.4 - Utility-first CSS framework
- ShadCN UI - Component library
- Axios - HTTP client
- React Router - Client-side routing
- Zustand - State management
- Lucide React - Icon library
- Node.js - JavaScript runtime
- Express.js 4.18 - Web framework
- MongoDB 8.0 - Document database
- Mongoose 8.0 - MongoDB ODM
- Google Generative AI - Gemini API integration
- CORS - Cross-origin resource sharing
- Dotenv - Environment variable management
- Manifest V3 - Latest Chrome extension standard
- Vanilla JavaScript - No dependencies
- Chrome Storage API - Local configuration
- Content Scripts - Page interaction
``` fake-news-detector/ ├── frontend/ # React + Vite frontend app │ ├── public/ │ ├── src/ │ │ ├── components/ # Reusable UI components │ │ ├── pages/ # Page components │ │ ├── App.jsx # Main app component │ │ ├── main.jsx # Entry point │ │ └── index.css # Global styles │ ├── package.json │ ├── vite.config.js │ ├── tailwind.config.js │ └── .env.example │ ├── backend/ # Node.js + Express backend │ ├── db/ │ │ ├── connection.js # MongoDB connection │ │ ├── models.js # Mongoose schemas │ │ └── operations.js # Database operations │ ├── ml/ │ │ ├── predict.py # Python ML model │ │ └── train_model.py # Training script │ ├── gemini-service.js # Gemini API integration │ ├── ai-detection.js # Keyword-based NLP │ ├── ml-server.js # Python process manager │ ├── news-service.js # News fetching service │ ├── feedback-system.js # Feedback management │ ├── server.js # Express server │ ├── package.json │ ├── .env.example │ └── README.md │ ├── extension/ # Chrome browser extension │ ├── manifest.json # Extension configuration │ ├── popup.html # Popup UI │ ├── popup.js # Popup logic │ ├── popup.css # Popup styles │ ├── background.js # Service worker │ ├── content.js # Content script │ ├── styles.css # Main styles │ ├── README.md │ └── images/ │ ├── icon-16.png │ ├── icon-48.png │ └── icon-128.png │ └── README.md # This file ```
Before you begin, ensure you have:
- Node.js 16+ (Download)
- npm or yarn (comes with Node.js)
- MongoDB (local or cloud)
- Python 3.8+ (Download) - For ML model
- Google Gemini API Key (Get one)
- Chrome Browser - For extension testing
```bash
git clone cd fake-news-detector
unzip fake-news-detector.zip cd fake-news-detector ```
```bash cd backend
npm install
cp .env.example .env
nano .env # or use your preferred editor ```
Backend .env configuration:
```env
GEMINI_API_KEY=your_gemini_api_key_here
MONGODB_URI=mongodb://localhost:27017/fake-news-detector
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/fake-news-detector?retryWrites=true&w=majority
PORT=5000 NODE_ENV=development ```
```bash cd ../frontend
npm install
cp .env.example .env
nano .env ```
Frontend .env configuration:
```env VITE_API_URL=http://localhost:5000 ```
The extension is ready to use - no installation steps needed. It will be loaded in Chrome later.
```bash
brew tap mongodb/brew brew install mongodb-community
brew services start mongodb-community
mongo --eval "db.adminCommand('ping')" ```
- Go to MongoDB Atlas
- Create a free account
- Create a cluster
- Get connection string
- Add to
.env:MONGODB_URI=mongodb+srv://...
- Visit Google AI Studio
- Click "Create API Key"
- Copy the key to backend
.env
```bash cd backend/ml
pip install pandas scikit-learn numpy
python train_model.py fake_and_real_news.csv ```
```bash
brew services start mongodb-community ```
```bash
cd backend npm run dev
Output: 🚀 Backend running on http://localhost:5000
```
```bash
cd frontend npm run dev
Output: ➜ Local: http://localhost:5173
```
- Web App: Open http://localhost:5173 in your browser
- Backend API: http://localhost:5000
- Health Check: http://localhost:5000/health
- Open Chrome and go to
chrome://extensions/ - Enable "Developer mode" (toggle in top right)
- Click "Load unpacked"
- Navigate to the
extensionfolder in this project - The extension is now installed and active
POST /api/check-news
Analyze a news headline or article for credibility.
Request: ```json { "text": "Breaking: Major scientific breakthrough discovered" } ```
Response: ```json { "id": "507f1f77bcf86cd799439011", "text": "Breaking: Major scientific breakthrough discovered", "classification": "True", "confidence": 85, "explanation": "This article demonstrates high confidence of credible reporting...", "communityScore": 92, "feedbackCount": 14 } ```
POST /api/feedback
Vote on the accuracy of a detection.
Request: ```json { "newsId": "507f1f77bcf86cd799439011", "isCorrect": true } ```
Response: ```json { "success": true, "message": "Feedback recorded successfully", "communityScore": 93, "feedbackCount": 15 } ```
GET /api/news-history?limit=50&skip=0
Fetch previously analyzed news items.
Response: ```json { "success": true, "count": 20, "data": [ { "_id": "507f1f77bcf86cd799439011", "text": "Article text...", "classification": "Fake", "confidence": 92, "communityScore": 88, "feedbackCount": 12, "createdAt": "2024-01-15T10:30:00Z" } ] } ```
GET /health
Check if backend is running.
Response: ```json { "status": "Backend is running", "timestamp": "2024-01-15T10:30:00Z" } ```
The Chrome extension provides:
- Popup Interface: Manual text input for checking
- Hover Detection: Detects selected text on webpages
- Floating Badge: Quick access buttons for checking
- Result Toast: Inline results display
- Settings Panel: Configure backend API URL
- Real-time credibility checking
- Community accuracy scores
- User feedback integration
- Persistent storage
- CORS-enabled requests
See extension/README.md for detailed extension documentation.
- Visit any news website
- Select a headline or article text
- Click the "FakeCheck AI" badge
- See instant credibility analysis
- Optionally vote on accuracy
- Go to http://localhost:5173
- Click "Detect" in navigation
- Paste a news headline
- Click "Check News"
- View results and community score
- Vote on accuracy
- Go to http://localhost:5173
- Click "History" in navigation
- See all previously analyzed news
- Sort by date or classification
- Check community accuracy rates
```javascript { _id: ObjectId, text: String, // Original news text classification: String, // "True", "Fake", "Uncertain" confidence: Number, // 0-100 explanation: String, // Analysis explanation geminiResult: String, // Gemini API response (optional) communityScore: Number, // 0-100 (community accuracy) feedbackCount: Number, // Total votes received createdAt: Date, updatedAt: Date } ```
```javascript { _id: ObjectId, detectionId: ObjectId, // Reference to Detection isCorrect: Boolean, // User's vote userIp: String, // IP for tracking (optional) createdAt: Date } ```
Error: Cannot connect to MongoDB
Solution: ```bash
mongo --eval "db.adminCommand('ping')"
brew services start mongodb-community
```
Error: GEMINI_API_KEY not set
Solution:
- Get API key from Google AI Studio
- Add to backend/.env
- Restart backend server
Error: Cannot reach http://localhost:5000
Solution: ```bash
cd backend && npm run dev
Should be: http://localhost:5000
rm -rf frontend/node_modules npm install npm run dev ```
Port Already in Use
```bash
lsof -i :5000
kill -9
PORT=5001 ```
Extension not loading:
- Go to chrome://extensions/
- Check "Developer mode"
- Click "Load unpacked"
- Select extension folder
Cannot connect to backend:
- Click extension icon
- Go to Settings
- Update API URL to correct backend URL
- Ensure backend is running
Content script not detecting text:
- Content scripts don't work on Chrome pages, extensions, or secure sites
- Only works on regular websites (http/https)
Edit backend/ai-detection.js to add custom detection logic.
Frontend components are in frontend/src/components/.
Update backend/db/models.js to add new fields.
See backend/ml/README.md for training instructions.
```bash cd frontend npm run build
```
```bash cd backend
```
See Chrome Developer documentation for publishing extension.
MIT License - Feel free to use this project for personal or commercial purposes.
For issues, questions, or contributions:
- Check the Troubleshooting section
- Review API documentation
- Check extension README
- Open an issue on GitHub
- Multi-language support
- Advanced ML models
- Real-time news feeds
- Social media integration
- Detailed analytics dashboard
- API rate limiting
- User authentication system
- Export reports to PDF