๐ TruthLens - Real-Time Crisis Misinformation Detector

TruthLens is a full-stack MERN (MongoDB, Express, React, Node.js) application that detects and verifies misinformation in real-time during crisis situations. It provides users with verified facts, identifies false claims, and delivers multilingual alerts.
๐ฏ Features โ Real-Time Misinformation Detection - Live feed of verified/unverified claims โ JWT Authentication - Secure signup and login system with bcrypt password hashing โ WebSocket Real-Time Updates - Socket.io powered live notifications โ Location-Based Alerts - Personalized misinformation feed based on user location โ Multi-Language Support - Interface available in EN, HI, FR, ES, DE, AR โ User Preferences - Customize trusted sources, notifications, and language โ Fact-Check Timeline - View verification history and credibility scores โ Responsive Design - Mobile-friendly UI with Tailwind CSS โ Interactive Dashboard - Beautiful glassmorphism UI with live updates โ Protected Routes - Authentication middleware for secure access
๐ Prerequisites Before you begin, ensure you have:
Node.js (v16 or higher) - Download npm or yarn - Comes with Node.js MongoDB (local or cloud) - Download or Atlas Git - Download Code Editor - VS Code recommended - Download
๐ Quick Start
- Clone or Extract Project bash# If from GitHub git clone cd truthlens
unzip truthlens.zip cd truthlens 2. Setup Backend bashcd server
npm install
cp .env.example .env
See .env.example for all required variables. 3. Setup Frontend bashcd client
npm install
cp .env.example .env
See .env.example for all required variables. 4. Start MongoDB Local MongoDB: bash# Windows mongod
brew services start mongodb-community
sudo systemctl start mongod Or use MongoDB Atlas (Cloud):
Create account at https://www.mongodb.com/cloud/atlas Get connection string Add to server/.env:
envMONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/truthlens 5. Run Both Servers Terminal 1 - Backend (from server folder): bashnpm run dev You should see: โ MongoDB Connected: localhost ๐ Server running on port 5000 ๐ก Socket.io ready for real-time updates Terminal 2 - Frontend (from client folder): bashnpm run dev You should see: VITE v4.4.9 ready in 500 ms โ Local: http://localhost:5173/ 6. Open in Browser Navigate to: http://localhost:5173
๐ Project Structure TruthLens/ โ โโโ server/ # Backend (Node.js + Express) โ โโโ config/ โ โ โโโ db.js # MongoDB connection โ โโโ controllers/ โ โ โโโ authController.js # Authentication logic โ โ โโโ userController.js # User profile & preferences โ โ โโโ streamController.js # Live feed management โ โโโ middleware/ โ โ โโโ authMiddleware.js # JWT protection โ โโโ models/ โ โ โโโ User.js # User schema โ โ โโโ Alert.js # Alert/misinformation schema โ โโโ routes/ โ โ โโโ authRoutes.js # Auth endpoints โ โ โโโ userRoutes.js # User endpoints โ โ โโโ streamRoutes.js # Stream endpoints โ โโโ utils/ โ โ โโโ fakeFeedGenerator.js # Mock data generator โ โโโ .env # Environment variables โ โโโ .env.example # Example env file โ โโโ package.json # Dependencies โ โโโ server.js # Entry point โ โโโ client/ # Frontend (React + Vite) โ โโโ src/ โ โ โโโ api/ โ โ โ โโโ axios.js # API configuration โ โ โโโ components/ โ โ โ โโโ common/ โ โ โ โโโ PrivateRoute.jsx # Protected routes โ โ โโโ context/ โ โ โ โโโ AuthContext.jsx # Auth state management โ โ โโโ pages/ โ โ โ โโโ LandingPage.jsx โ โ โ โโโ SignupPage.jsx โ โ โ โโโ LoginPage.jsx โ โ โ โโโ SetLocationPage.jsx โ โ โ โโโ Dashboard.jsx โ โ โ โโโ SettingsPage.jsx โ โ โโโ services/ โ โ โ โโโ authService.js โ โ โ โโโ userService.js โ โ โ โโโ streamService.js โ โ โโโ socket/ โ โ โ โโโ socket.js # WebSocket client โ โ โโโ App.jsx # Main component โ โ โโโ main.jsx # Entry point โ โ โโโ index.css # Tailwind styles โ โโโ .env # Environment variables โ โโโ .env.example # Example env file โ โโโ package.json # Dependencies โ โโโ vite.config.js # Vite configuration โ โโโ tailwind.config.js # Tailwind configuration โ โโโ index.html # HTML template โ โโโ README.md # This file
๐ API Endpoints Authentication MethodEndpointDescriptionAuthPOST/api/auth/signupRegister new userโPOST/api/auth/loginLogin user, get JWTโGET/api/auth/meGet current userโ User Management MethodEndpointDescriptionAuthGET/api/user/profileGet user profileโ PUT/api/user/locationUpdate user locationโ PUT/api/user/preferencesUpdate preferencesโ Stream/Feed MethodEndpointDescriptionAuthGET/api/stream/liveGet live misinformation feedโ GET/api/stream/alerts/:idGet specific alert detailsโ Health Check MethodEndpointDescriptionGET/healthAPI health status WebSocket Events EventDirectionDataDescriptioninitialFeedServer โ ClientArray of alertsInitial feed on connectionnewUpdateServer โ ClientAlert objectNew alert in real-timeconnectClient โ Server-Connection establisheddisconnectClient โ Server-Connection lost
๐ Environment Variables Backend (server/.env.example) env# Server Configuration PORT=5000 NODE_ENV=development
MONGODB_URI=your_mongodb_uri
JWT_SECRET=your_jwt_secret_key_minimum_32_characters
CLIENT_URL=http://localhost:5173 Frontend (client/.env.example) env# API Configuration VITE_API_URL=http://localhost:5000/api VITE_SOCKET_URL=http://localhost:5000 Important: Never commit .env files to version control. Use .env.example as a template for configuration.
๐งช User Flow
Landing Page - User sees TruthLens intro Sign Up - Create account with name, email, password Set Location - Select city/region for personalized alerts Dashboard - View live misinformation feed with verification status Settings - Customize language, notifications, trusted sources Real-Time Updates - Receive instant alerts via WebSocket
๐ Key Technologies Frontend
React 18 - UI library Vite - Lightning-fast build tool React Router - Page navigation Tailwind CSS - Styling Axios - HTTP client Socket.io Client - Real-time communication Lucide React - Icon library
Backend
Node.js - JavaScript runtime Express.js - Web framework MongoDB - NoSQL database Mongoose - ODM for MongoDB JWT - Authentication tokens bcryptjs - Password hashing Socket.io - Real-time WebSocket CORS - Cross-origin requests
DevTools
Vite - Frontend bundler Tailwind CSS - Utility-first CSS PostCSS - CSS processing Autoprefixer - Browser compatibility
๐ Troubleshooting MongoDB Connection Error MongoServerError: connect ECONNREFUSED Fix: bash# Start MongoDB mongod # Windows/Mac/Linux
Port Already in Use Error: listen EADDRINUSE: address already in use :::5000 Fix: bash# Change PORT in server/.env to 5001 PORT=5001
VITE_API_URL=http://localhost:5001/api VITE_SOCKET_URL=http://localhost:5001 CORS Error Access to XMLHttpRequest blocked by CORS policy Fix:
Make sure CLIENT_URL in server/.env matches your frontend URL Frontend .env has correct VITE_API_URL
"Cannot find module" Error Fix: bash# Delete node_modules and reinstall rm -rf node_modules package-lock.json npm install Tailwind Styles Not Working Fix: bash# Restart frontend after modifying config npm run dev
npm install npm run dev API Calls Failing (500 Error) Check backend terminal for error messages Common causes:
Missing environment variables in .env JWT_SECRET too short (must be 32+ characters) MongoDB not connected Authentication middleware issue
๐ API Examples
Signup
bashcurl -X POST http://localhost:5000/api/auth/signup
-H "Content-Type: application/json"
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}'
Response:
json{
"_id": "507f1f77bcf86cd799439011",
"name": "John Doe",
"email": "john@example.com",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
Login
bashcurl -X POST http://localhost:5000/api/auth/login
-H "Content-Type: application/json"
-d '{
"email": "john@example.com",
"password": "password123"
}'
Update Location (Protected)
bashcurl -X PUT http://localhost:5000/api/user/location
-H "Content-Type: application/json"
-H "Authorization: Bearer "
-d '{
"city": "Mumbai",
"country": "India"
}'
Get Live Feed (Protected)
bashcurl -X GET http://localhost:5000/api/stream/live?limit=20
-H "Authorization: Bearer "
๐ Deployment Deploy Frontend (Vercel) bashcd client
npm run build
git add . git commit -m "Deploy TruthLens frontend" git push origin main
Deploy Backend (Heroku/Render) bashcd server
echo "web: node server.js" > Procfile
git add . git commit -m "Deploy TruthLens backend" git push origin main
Environment Variables for Production env# Backend NODE_ENV=production MONGODB_URI= JWT_SECRET= CLIENT_URL=
VITE_API_URL=/api VITE_SOCKET_URL= Important: Use strong, unique secrets in production. Never commit sensitive data to version control.
๐ Mock Data Generator The application includes a fake data generator for testing: File: server/utils/fakeFeedGenerator.js Generates mock alerts with:
Random sources (Twitter, Facebook, News, etc.) Random categories (Health, Disaster, Politics, etc.) Verified/Misinformation status Random locations Auto-updating every 10 seconds
To modify, edit fakeFeedGenerator.js and restart the server.
๐ฎ Future Features
Integration with real fact-checking APIs (Google Fact Check, Snopes) AI/ML model for automatic misinformation detection Push notifications via Firebase Cloud Messaging Advanced search and filtering User reputation/credibility system Social sharing features Mobile app (React Native) Email verification Password reset functionality Two-factor authentication Admin dashboard Analytics and reporting
๐ค Contributing Contributions are welcome! Please follow these steps:
Fork the repository Create feature branch (git checkout -b feature/AmazingFeature) Commit changes (git commit -m 'Add AmazingFeature') Push to branch (git push origin feature/AmazingFeature) Open Pull Request
๐ License This project is licensed under the MIT License - see LICENSE file for details.
๐จโ๐ป Author Nikita Pandey
GitHub: @Nikitaa104 Email: pandeynikita190@gmail.com
๐ Support For support, open an issue on GitHub or contact the project maintainers.
๐ Acknowledgments
Tailwind CSS - For beautiful utility-first styling Socket.io - For real-time WebSocket communication MongoDB - For flexible NoSQL database React - For powerful UI library Node.js - For reliable backend runtime
๐ Documentation
React Documentation Express.js Guide MongoDB Manual Tailwind CSS Docs Socket.io Documentation
Made with โค๏ธ using MERN Stack โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ TruthLens v1.0.0 โ โ Real-Time Crisis Misinformation Detector โ โ Stay Informed. Stay Accurate. โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ