Skip to content

Nikitaa104/TruthLine-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒ TruthLens - Real-Time Crisis Misinformation Detector image image

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

  1. Clone or Extract Project bash# If from GitHub git clone cd truthlens

If from ZIP

unzip truthlens.zip cd truthlens 2. Setup Backend bashcd server

Install dependencies

npm install

Create .env file

cp .env.example .env

Update with your configuration

See .env.example for all required variables. 3. Setup Frontend bashcd client

Install dependencies

npm install

Create .env file

cp .env.example .env

Update with your configuration

See .env.example for all required variables. 4. Start MongoDB Local MongoDB: bash# Windows mongod

Mac

brew services start mongodb-community

Linux

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 Configuration

MONGODB_URI=your_mongodb_uri

JWT Configuration

JWT_SECRET=your_jwt_secret_key_minimum_32_characters

Client Configuration

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

OR use MongoDB Atlas (cloud)

Update MONGODB_URI in server/.env

Port Already in Use Error: listen EADDRINUSE: address already in use :::5000 Fix: bash# Change PORT in server/.env to 5001 PORT=5001

Update frontend .env

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

Or clear cache

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

Build

npm run build

Push to GitHub

git add . git commit -m "Deploy TruthLens frontend" git push origin main

Connect to Vercel and deploy

vercel.com โ†’ Import Project โ†’ Select GitHub repo

Deploy Backend (Heroku/Render) bashcd server

Create Procfile

echo "web: node server.js" > Procfile

Push to GitHub

git add . git commit -m "Deploy TruthLens backend" git push origin main

Deploy on Heroku/Render/Railway

Environment Variables for Production env# Backend NODE_ENV=production MONGODB_URI= JWT_SECRET= CLIENT_URL=

Frontend

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. โ•‘ โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published