Skip to content

Sandarsh18/VeritasAI

Repository files navigation

VeritasAI ๐Ÿ”Ž๐Ÿง โš–๏ธ

Explainable Fact-Checking Through Multi-Agent Reasoning

VeritasAI typing banner


๐Ÿ“š Table of Contents


What is VeritasAI?

VeritasAI is an explainable claim verification platform that analyzes misinformation through multi-agent debate and evidence-based reasoning. Instead of providing a black-box verdict, it:

  1. Retrieves evidence from multiple web sources using a hybrid RAG pipeline
  2. Generates arguments through competing AI agents (Prosecutor ๐Ÿ”จ and Defender ๐Ÿ›ก๏ธ)
  3. Synthesizes verdicts via a Judge agent that weighs both sides
  4. Scores disagreement to measure claim contentiousness
  5. Exports results as shareable links, PDFs, and historical records

Perfect for journalists, researchers, and fact-checkers who need transparency, not just accuracy.


๐Ÿš€ Key Features

Core Capabilities

  • โœ… Agentic Multi-Agent Verification โ€” LangGraph-orchestrated Prosecutor/Defender/Judge debate system
  • โœ… RAG-Powered Evidence Retrieval โ€” FAISS semantic ranking + multi-API fallback (SerpAPI, NewsAPI, DuckDuckGo)
  • โœ… Disagreement Scoring โ€” Quantifies claim contentiousness and agent consensus
  • โœ… Batch Verification โ€” Process up to 5 claims concurrently with /api/verify/batch
  • โœ… Confidence Scoring โ€” Normalized 0-100 confidence with reasoning
  • โœ… Source Attribution โ€” Evidence cards with domain credibility scores

User Features

  • โœ… Claim History โ€” Persistent SQLite-backed verification history
  • โœ… Shareable Links โ€” Short IDs for public claim sharing via /api/share/{short_id}
  • โœ… PDF Export โ€” Professional verdict reports with evidence summaries
  • โœ… JWT Authentication โ€” Secure user registration and login
  • โœ… Real-Time Pipeline Visualization โ€” See each reasoning stage as it executes
  • โœ… Responsive UI โ€” Modern React 19 + Vite frontend with animations

Reliability

  • โœ… Multi-LLM Fallback Chain โ€” Gemini โ†’ Groq โ†’ DeepSeek โ†’ Ollama (local fallback)
  • โœ… Semantic Caching โ€” Skip re-processing identical claims
  • โœ… API Resilience โ€” Graceful degradation when external APIs fail
  • โœ… Health Checks โ€” Real-time service and LLM provider status at /api/health

โšก Quick Start

One-Command Setup (with venv)

# Navigate to project root
cd fake-news-ai

# Backend: Setup and start (Terminal 1)
cd backend
python3 -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
python3 -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload

# (In another terminal) Frontend: Setup and start (Terminal 2)
cd frontend/react-app
npm install
npm run dev

# (In third terminal) Optional: Start Ollama for local LLM fallback (Terminal 3)
ollama serve

Result:

  • Backend running on http://localhost:8000
  • Frontend running on http://localhost:5173
  • Database auto-initializes at ./backend/veritas.db

Verify setup:

curl http://localhost:8000/api/health

๐Ÿ—๏ธ System Architecture

High-Level Request Flow

flowchart TD
    User["๐Ÿ‘ค User"]
    UI["๐ŸŽจ React UI"]
    API["โš™๏ธ FastAPI"]
    Cache["๐Ÿ’พ SQLite Cache"]
    Retrieval["๐ŸŒ Evidence Retrieval"]
    LLMs["๐Ÿง  LLM Fallback Chain"]
    Graph["๐Ÿ“Š LangGraph"]
    PDF["๐Ÿ“„ PDF Export"]
    
    User -->|Enter Claim| UI
    UI -->|POST /api/verify| API
    API -->|Check cache| Cache
    Cache -->|Cache Hit| API
    Cache -->|Cache Miss| Retrieval
    Retrieval -->|FAISS Rank| API
    API -->|Run Pipeline| Graph
    Graph -->|Prosecutor Argument| LLMs
    Graph -->|Defender Argument| LLMs
    Graph -->|Judge Synthesis| LLMs
    LLMs -->|Verdict + Confidence| Graph
    Graph -->|Result| API
    API -->|Save History| Cache
    API -->|Generate PDF| PDF
    API -->|JSON Response| UI
    UI -->|Display Results| User
Loading

Backend Flow Architecture

User Input (Claim)
    โ†“
[FastAPI Router] /api/verify
    โ†“
[Cache Check] SQLite claim_hash lookup
    โ”œโ”€โ†’ CACHE HIT โ†’ Return cached result
    โ””โ”€โ†’ CACHE MISS โ†’ Continue to:
    โ†“
[Claim Analysis] โ†’ Domain classification (Politics, Health, Science, etc.)
    โ†“
[Retrieval] SerpAPI + NewsAPI + DuckDuckGo
    โ”œโ”€โ†’ Get 50-100 raw results
    โ”œโ”€โ†’ Filter by relevance (embedding similarity)
    โ”œโ”€โ†’ Filter by source credibility
    โ””โ”€โ†’ Rank by FAISS + BM25 hybrid score
    โ†“
[Context Building] Top 10-15 evidence sources
    โ†“
[Prosecutor Agent] "What's wrong with this claim?" (Gemini โ†’ Ollama fallback)
    โ†“
[Defender Agent] "What's right about this claim?" (Gemini โ†’ Ollama fallback)
    โ†“
[Judge Agent] Final verdict (Gemini โ†’ Ollama fallback)
    โ†“
[Disagreement Scoring] Measure prosecutor-defender disagreement
    โ†“
[PDF Export Prep] Generate shareable verdict
    โ†“
[Database Save] Save to claim_history, create short_id
    โ†“
API Response with:
  - Verdict (TRUE/FALSE/MIXED/INSUFFICIENT_DATA)
  - Confidence (0-100)
  - Evidence cards
  - Prosecutor/Defender arguments
  - Reasoning
  - Timing info

Evidence Retrieval & Ranking Pipeline

flowchart LR
    Claim["๐Ÿ“ Claim"]
    Decompose["Decompose into queries"]
    Search["๐Ÿ” Multi-API Search"]
    Filter["Filter & Prioritize"]
    FAISS["๐Ÿงฎ FAISS Semantic Rank"]
    Context["๐Ÿ“š Build Context"]
    
    Claim --> Decompose
    Decompose --> Search
    Search -->|SerpAPI| Filter
    Search -->|NewsAPI| Filter
    Search -->|DuckDuckGo| Filter
    Filter --> FAISS
    FAISS --> Context
Loading

Multi-Agent Verification Workflow

stateDiagram-v2
    [*] --> AnalyzeClaim: Extract key entities
    AnalyzeClaim --> RetrieveEvidence: Gather supporting/opposing sources
    RetrieveEvidence --> ProsecutorAnalysis: "Challenge the claim โš”๏ธ"
    RetrieveEvidence --> DefenderAnalysis: "Support the claim ๐Ÿ›ก๏ธ"
    ProsecutorAnalysis --> JudgeAnalysis: Synthesize evidence
    DefenderAnalysis --> JudgeAnalysis
    JudgeAnalysis --> Score: Calculate disagreement
    Score --> Verdict: "TRUE | FALSE | MISLEADING | UNVERIFIED"
    Verdict --> Export: Generate shareable link + PDF
    Export --> [*]
Loading

Frontend Component Hierarchy

<App />
โ”œโ”€ <Routes>
โ”œโ”€ <Home />                    # Main verification page
โ”‚  โ”œโ”€ <input> Claim entry
โ”‚  โ”œโ”€ <PipelineProgress />    # Shows processing stages
โ”‚  โ”œโ”€ <VerdictBadge />        # Verdict display
โ”‚  โ”œโ”€ <ConfidenceGauge />     # Confidence visualization
โ”‚  โ”œโ”€ <AgentCard />           # Prosecutor arguments
โ”‚  โ”œโ”€ <AgentCard />           # Defender arguments
โ”‚  โ””โ”€ <EvidenceCard />        # Evidence sources (multiple)
โ”œโ”€ <History />                 # Past claims
โ”‚  โ””โ”€ Replay from cache
โ”œโ”€ <Login /> / <Register />    # Auth pages
โ”œโ”€ <Profile />                 # User settings
โ””โ”€ <Stats />                   # Statistics dashboard

๐Ÿงญ How It Works

1. Claim Submission

User enters a claim via the React UI. The claim is tokenized into searchable sub-queries.

2. Cache Check

System checks SQLite cache for identical claims (hash-based):

  • Hit โ†’ Return cached result immediately
  • Miss โ†’ Proceed to evidence retrieval

3. Evidence Gathering (RAG Pipeline)

  • Query Decomposition โ†’ Break claim into sub-questions
  • Multi-Source Retrieval โ†’ Search SerpAPI, NewsAPI, DuckDuckGo in parallel
  • Relevance Filtering โ†’ Remove off-topic and low-quality sources using embeddings
  • Credibility Scoring โ†’ Rate domain reputation (100 = very trustworthy)
  • FAISS Ranking โ†’ Semantic ranking based on embedding similarity
  • Result โ†’ Top 10-15 high-quality evidence sources

4. Prosecutor Analysis (Agent 1)

The Prosecutor agent (powered by Gemini/Ollama):

  • Identifies weaknesses in the claim
  • Finds contradicting evidence
  • Generates structured counter-arguments (3-5 points)
  • Assigns strength score: weak | medium | strong
  • Cites specific evidence sources

5. Defender Analysis (Agent 2)

The Defender agent (powered by Gemini/Ollama):

  • Identifies strengths in the claim
  • Finds supporting evidence
  • Generates structured pro-arguments (3-5 points)
  • Assigns strength score: weak | medium | strong
  • Cites specific evidence sources

6. Judge Synthesis (Agent 3)

The Judge agent (powered by Gemini/Ollama):

  • Reviews both prosecutor and defender cases
  • Weighs evidence credibility
  • Produces final verdict: TRUE | FALSE | MISLEADING | UNVERIFIED | INSUFFICIENT_DATA
  • Assigns confidence: 0-100 (normalized)
  • Generates structured reasoning with citations

7. Disagreement Scoring

  • Compares Prosecutor and Defender argument strengths
  • Returns disagreement_score: 0.0-1.0
    • 0.0 = Strong consensus (both sides agree)
    • 1.0 = Maximum disagreement
  • Labels as Low | Medium | High contentiousness
  • Tracks support/contradict counts

8. Result Persistence

  • Save to SQLite cache (keyed by claim hash)
  • Generate short ID for sharing
  • Create verifiable history record
  • (Optional) Store to Neo4j knowledge graph
  • Generate PDF report

๐Ÿ› ๏ธ Tech Stack

Frontend

Technology Purpose Version
React Interactive component framework 19.2.4
Vite Lightning-fast dev server & build 8.0.1
React Router Client-side navigation 7.13.1
Axios HTTP client for API calls 1.13.6
Framer Motion Smooth animations & transitions 12.38.0
Chart.js Analytics dashboard charts 4.5.1
Lucide React Beautiful icon library 1.0.0
Tailwind CSS Utility-first styling via tailwind-merge

Backend

Technology Purpose Version
FastAPI High-performance async REST API 0.111.0
Uvicorn ASGI server with auto-reload 0.29.0
SQLAlchemy ORM for database operations 2.0.30
SQLite Local persistent database built-in
LangGraph Agent orchestration & state management 0.2.66
Pydantic Data validation & serialization via SQLAlchemy
JWT + bcrypt Secure authentication python-jose, passlib

AI/ML & Data

Technology Purpose Version
LangChain LLM and agent utilities compatibility layer
FAISS Vector similarity search & ranking 1.8.0 (CPU)
Sentence-Transformers Semantic embeddings 2.7.0
SerpAPI Google Search integration 2.4.2
NewsAPI News articles retrieval 0.2.7
DuckDuckGo Search Privacy-respecting web search 8.1.1

LLM Providers (Fallback Chain)

Provider Model Purpose Status
Google Gemini 2.5-flash Primary fast reasoning โœ… Active
Groq llama-3.3-70b High-quality analysis โš ๏ธ Legacy
DeepSeek reasoner Extended reasoning โš ๏ธ Legacy
Ollama llama3.2:1b Local fallback inference โœ… Recommended

Export & Utilities

Technology Purpose Version
ReportLab PDF generation 4.5.0
Beautiful Soup 4 HTML parsing 4.12.3
lxml XML/HTML processing 5.3.0
FeedParser RSS/feed parsing 6.0.11
Neo4j Graph database (optional) 5.19.0

๐Ÿ“ฆ Installation

Prerequisites

  • Python 3.10 or higher
  • Node.js 18+ and npm 9+
  • Optional: Ollama runtime for local LLM fallback
  • Optional: Neo4j server for knowledge graph features

Backend Setup

Step 1: Create Virtual Environment

cd backend
python3 -m venv venv

Why venv?

  • Isolates Python packages from system Python
  • Prevents dependency conflicts with other projects
  • Makes deployment reproducible
  • Allows exact version pinning

Step 2: Activate Virtual Environment

# macOS/Linux
source venv/bin/activate

# Windows PowerShell
venv\Scripts\Activate.ps1

# Windows Command Prompt
venv\Scripts\activate.bat

You'll see: (venv) prefix in terminal = activated

Step 3: Install Dependencies

pip install --upgrade pip setuptools wheel
pip install -r requirements.txt

Installation time: ~2-5 minutes depending on internet speed

Step 4: Verify Installation

# Check key packages
python3 -c "import fastapi, sentence_transformers, faiss; print('โœ“ All imports OK')"

Step 5: Start Backend

python3 -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload

Health check:

curl http://localhost:8000/api/health

Frontend Setup

Step 1: Install Dependencies

cd frontend/react-app
npm install --legacy-peer-deps
# Or for reproducible install from lock file:
npm ci

Note: npm ci is preferred in CI/production; npm install updates lock file

Step 2: Verify Installation

npm run lint   # Check for syntax errors
npm run build  # Test production build

Build should complete in <30 seconds

Step 3: Start Development Server

npm run dev -- --host 0.0.0.0 --port 5173

Open in browser: http://localhost:5173

Optional: Ollama Setup

For local LLM fallback (recommended for development):

# Download and start Ollama from https://ollama.ai
# In a separate terminal, ensure Ollama is running:
ollama serve

# Pull a model (default is llama3.2):
ollama pull llama3.2:1b

# Verify connection:
curl http://localhost:11434/api/version

๐Ÿ” Configuration

Port Configuration

Service Port Protocol Purpose
Backend API 8000 HTTP FastAPI endpoints
Frontend Dev 5173 HTTP Vite dev server
Ollama LLM 11434 HTTP Local LLM server
SQLite DB - File ./veritas.db
Neo4j (optional) 7687 Bolt Graph database

Environment Variables

Create backend/.env file:

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# SECURITY & CORE
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
SECRET_KEY=change_this_for_production_use_openssl_rand_hex_32
# Used for: JWT token signing, password hashing
# Generate with: openssl rand -hex 32

CORS_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
# For production: https://yourdomain.com

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# DATABASE
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
DATABASE_URL=sqlite:///./veritas.db
# Local SQLite: creates veritas.db in backend/ folder
# PostgreSQL: postgresql://user:password@localhost/veritas
# MySQL: mysql://user:password@localhost/veritas

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# SEARCH APIs (ACTIVE)
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
NEWSAPI_KEY=your_newsapi_key_here
# https://newsapi.org - News aggregation (100 req/day free)
# Sign up: https://newsapi.org/register

SERPAPI_KEY=your_serpapi_key_here
# https://serpapi.com - Google Search results (100 req/month free)
# Sign up: https://serpapi.com

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# LLM PROVIDERS - PRIMARY
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
GEMINI_API_KEY=your_gemini_api_key
# https://ai.google.dev - Get key from Google AI Studio
# Model: gemini-2.5-flash (fast, free tier available)

GEMINI_MODEL=gemini-2.5-flash

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# LLM PROVIDERS - SECONDARY (Legacy, optional)
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
GROQ_API_KEY=your_groq_api_key
GROQ_DEFENDER_MODEL=llama-3.1-8b-instant
GROQ_JUDGE_MODEL=llama-3.3-70b-versatile

DEEPSEEK_API_KEY=your_deepseek_api_key
DEEPSEEK_BASE_URL=https://api.deepseek.com
DEEPSEEK_MODEL=deepseek-reasoner

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# LLM PROVIDERS - FALLBACK (LOCAL)
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_ANALYZER_MODEL=llama3.2:1b
OLLAMA_MODEL=mistral:latest

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# OPTIONAL: Neo4j Knowledge Graph
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your-neo4j-password

Getting API Keys

Service Free Tier Link
SerpAPI 100 req/month serpapi.com
NewsAPI 100 req/day newsapi.org
Google Gemini 60 req/min ai.google.dev
Groq 7500 req/day groq.com
DeepSeek $5 free credit platform.deepseek.com

CORS Configuration

Backend CORS Settings:

CORS_ORIGINS=http://localhost:5173

What this means:

  • Frontend on http://localhost:5173 can make API calls to http://localhost:8000
  • Prevents cross-origin request blocking
  • For production, update to your domain: CORS_ORIGINS=https://yourdomain.com

๐Ÿ“ก API Reference

Verification Endpoints

POST /api/verify

Verify a single claim with full multi-agent pipeline.

Request:

{
  "claim": "The Earth orbits the Sun"
}

Response:

{
  "success": true,
  "claim": "The Earth orbits the Sun",
  "verdict": "TRUE",
  "confidence": 98,
  "disagreement_score": 0.05,
  "contentiousness": "Low",
  "reasoning": "Scientific consensus confirms...",
  "prosecutor_analysis": {
    "arguments": ["..."],
    "strength": "weak"
  },
  "defender_analysis": {
    "arguments": ["..."],
    "strength": "strong"
  },
  "evidence": [
    {
      "title": "Earth's Orbit",
      "url": "https://example.com",
      "domain": "nasa.gov",
      "snippet": "...",
      "relevance_score": 0.95,
      "credibility": 98
    }
  ],
  "history_id": "12345",
  "short_id": "abc123",
  "cache_hit": false,
  "processing_time_seconds": 45.23
}

POST /api/verify/batch

Verify up to 5 claims concurrently.

Request:

{
  "claims": [
    "Claim 1",
    "Claim 2",
    "Claim 3"
  ]
}

Response:

{
  "results": [
    { /* verify response */ },
    { /* verify response */ },
    { /* verify response */ }
  ],
  "total_time_seconds": 120.5
}

POST /api/verify/quick

Quick verification wrapper around /verify.


History & Sharing

GET /api/claims/history

Retrieve user's claim verification history.

Response:

{
  "claims": [
    {
      "id": 1,
      "claim": "Sample claim",
      "verdict": "TRUE",
      "confidence": 85,
      "timestamp": "2026-05-11T10:30:00Z",
      "short_id": "abc123",
      "domain": "health"
    }
  ],
  "is_authenticated": true,
  "total": 42
}

GET /api/claims/history/{history_id}

Retrieve detailed verification snapshot.

Response: Full verification response (same as /api/verify)

GET|HEAD /api/export/pdf/{history_id}

Download PDF report for a verification.

Example:

curl -o verdict.pdf http://localhost:8000/api/export/pdf/12345

GET /api/share/{short_id}

Public view of a shared verification (no auth required).


Authentication

POST /api/auth/register

Register new user.

Request:

{
  "username": "johndoe",
  "email": "john@example.com",
  "password": "securepassword123"
}

Response:

{
  "id": 1,
  "username": "johndoe",
  "email": "john@example.com",
  "created_at": "2026-05-11T10:30:00Z"
}

POST /api/auth/login

Login user.

Request:

{
  "username": "johndoe",
  "password": "securepassword123"
}

Response:

{
  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
  "token_type": "bearer",
  "user": {
    "id": 1,
    "username": "johndoe",
    "email": "john@example.com"
  }
}

GET /api/auth/me

Get current authenticated user.

GET /api/auth/check-username

Check username availability.

GET /api/auth/check-email

Check email availability.


Utility Endpoints

Endpoint Method Description
/api/health GET Service health + LLM provider status
/api/stats GET Aggregate verification statistics
/api/trending GET Top trending claims being verified
/api/sources GET Supported evidence sources metadata

๐Ÿ“ Project Structure

fake-news-ai/
โ”œโ”€โ”€ README.md                          # Main documentation (this file)
โ”œโ”€โ”€ PROJECT_SETUP_GUIDE.md            # Detailed setup reference (deprecated, merged here)
โ”œโ”€โ”€ .github/
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ””โ”€โ”€ secret-scan.yml           # GitHub Actions CI/CD
โ”œโ”€โ”€ .gitleaks.toml                    # Secret scanning config
โ”œโ”€โ”€ .pre-commit-config.yaml           # Pre-commit hooks
โ”‚
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ main.py                       # FastAPI app + route handlers
โ”‚   โ”œโ”€โ”€ agents.py                     # LangGraph orchestrator
โ”‚   โ”œโ”€โ”€ state.py                      # VerificationState definition
โ”‚   โ”œโ”€โ”€ rag_core.py                   # RAG pipeline (FAISS ranking)
โ”‚   โ”œโ”€โ”€ retrieval.py                  # Multi-source evidence retrieval
โ”‚   โ”œโ”€โ”€ filters.py                    # Source quality filters
โ”‚   โ”œโ”€โ”€ credibility.py                # Domain credibility scoring
โ”‚   โ”œโ”€โ”€ database.py                   # SQLAlchemy models + ORM
โ”‚   โ”œโ”€โ”€ auth.py                       # JWT authentication logic
โ”‚   โ”œโ”€โ”€ pdf_export.py                 # ReportLab PDF generation
โ”‚   โ”œโ”€โ”€ llm_client.py                 # Multi-LLM fallback chain
โ”‚   โ”œโ”€โ”€ gemini_client.py              # Gemini-specific client
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ agents/
โ”‚   โ”‚   โ”œโ”€โ”€ claim_analyzer.py         # Entity extraction + analysis
โ”‚   โ”‚   โ”œโ”€โ”€ prosecutor.py             # Prosecutor agent
โ”‚   โ”‚   โ”œโ”€โ”€ defender.py               # Defender agent
โ”‚   โ”‚   โ”œโ”€โ”€ judge.py                  # Judge agent (verdict synthesis)
โ”‚   โ”‚   โ””โ”€โ”€ source_tracker.py         # Evidence attribution
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ rag/
โ”‚   โ”‚   โ”œโ”€โ”€ embeddings.py             # Sentence transformer wrappers
โ”‚   โ”‚   โ”œโ”€โ”€ faiss_store.py            # FAISS vector store
โ”‚   โ”‚   โ”œโ”€โ”€ retriever.py              # RAG retriever interface
โ”‚   โ”‚   โ”œโ”€โ”€ knowledge_base.py         # Knowledge base indexing
โ”‚   โ”‚   โ””โ”€โ”€ realtime_fetcher.py       # Real-time source fetching
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ cache_service.py          # Semantic caching
โ”‚   โ”‚   โ”œโ”€โ”€ credibility_service.py    # Credibility scoring
โ”‚   โ”‚   โ”œโ”€โ”€ evidence_classifier.py    # Evidence categorization
โ”‚   โ”‚   โ”œโ”€โ”€ metrics_service.py        # Analytics/metrics
โ”‚   โ”‚   โ”œโ”€โ”€ ranking_service.py        # Evidence ranking utilities
โ”‚   โ”‚   โ””โ”€โ”€ llm_client.py             # LLM provider integration
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ tests/
โ”‚   โ”‚   โ”œโ”€โ”€ conftest.py               # pytest configuration
โ”‚   โ”‚   โ”œโ”€โ”€ test_gemini.py            # Gemini integration tests
โ”‚   โ”‚   โ”œโ”€โ”€ test_pipeline_recovery.py # Fallback mechanism tests
โ”‚   โ”‚   โ”œโ”€โ”€ test_retriever_*.py       # RAG pipeline tests
โ”‚   โ”‚   โ””โ”€โ”€ test_search_apis.py       # Search API tests
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ data/
โ”‚   โ”‚   โ”œโ”€โ”€ news_articles.json        # Sample dataset
โ”‚   โ”‚   โ””โ”€โ”€ faiss_vectors.npy         # Pre-computed embeddings
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ requirements.txt              # Python dependencies (100+ packages)
โ”‚   โ”œโ”€โ”€ .env.example                  # Environment variable template
โ”‚   โ”œโ”€โ”€ start.sh                      # Backend startup script
โ”‚   โ””โ”€โ”€ veritas.db                    # SQLite database (auto-created)
โ”‚
โ””โ”€โ”€ frontend/react-app/
    โ”œโ”€โ”€ package.json                  # Node dependencies
    โ”œโ”€โ”€ vite.config.js               # Vite build configuration
    โ”œโ”€โ”€ eslint.config.js             # Linting rules
    โ”‚
    โ”œโ”€โ”€ src/
    โ”‚   โ”œโ”€โ”€ main.jsx                 # App entry point
    โ”‚   โ”œโ”€โ”€ App.jsx                  # Root component
    โ”‚   โ”œโ”€โ”€ App.css                  # Global styles
    โ”‚   โ”‚
    โ”‚   โ”œโ”€โ”€ pages/
    โ”‚   โ”‚   โ”œโ”€โ”€ Home.jsx             # Main verification workflow
    โ”‚   โ”‚   โ”œโ”€โ”€ History.jsx          # Claim history + replay
    โ”‚   โ”‚   โ”œโ”€โ”€ Stats.jsx            # Analytics dashboard
    โ”‚   โ”‚   โ”œโ”€โ”€ Login.jsx            # User login
    โ”‚   โ”‚   โ”œโ”€โ”€ Register.jsx         # User registration
    โ”‚   โ”‚   โ””โ”€โ”€ Profile.jsx          # User profile
    โ”‚   โ”‚
    โ”‚   โ”œโ”€โ”€ components/
    โ”‚   โ”‚   โ”œโ”€โ”€ AgentCard.jsx        # Prosecutor/Defender card
    โ”‚   โ”‚   โ”œโ”€โ”€ EvidenceCard.jsx     # Evidence item display
    โ”‚   โ”‚   โ”œโ”€โ”€ ConfidenceGauge.jsx  # Confidence meter
    โ”‚   โ”‚   โ”œโ”€โ”€ VerdictBadge.jsx     # Verdict display badge
    โ”‚   โ”‚   โ”œโ”€โ”€ PipelineProgress.jsx # Real-time pipeline stages
    โ”‚   โ”‚   โ”œโ”€โ”€ SkeletonLoader.jsx   # Loading placeholder
    โ”‚   โ”‚   โ”œโ”€โ”€ MetricsPanel.jsx     # Statistics panel
    โ”‚   โ”‚   โ””โ”€โ”€ ui/                  # Reusable UI elements
    โ”‚   โ”‚
    โ”‚   โ”œโ”€โ”€ hooks/
    โ”‚   โ”‚   โ””โ”€โ”€ useVoice.js          # Voice input/output (optional)
    โ”‚   โ”‚
    โ”‚   โ”œโ”€โ”€ services/
    โ”‚   โ”‚   โ””โ”€โ”€ api.js               # Axios API client
    โ”‚   โ”‚
    โ”‚   โ”œโ”€โ”€ lib/
    โ”‚   โ”‚   โ””โ”€โ”€ utils.ts             # Utility functions
    โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€ assets/                  # Images, logos, icons
    โ”‚
    โ”œโ”€โ”€ public/                       # Static assets
    โ”œโ”€โ”€ start.sh                      # Frontend startup script
    โ””โ”€โ”€ index.html                    # HTML entry point

๐Ÿ—ƒ๏ธ Database & Authentication

Database Models

User Table

CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  username VARCHAR(64) UNIQUE NOT NULL,
  email VARCHAR(128) UNIQUE NOT NULL,
  hashed_password VARCHAR(256) NOT NULL,
  created_at DATETIME DEFAULT NOW(),
  is_active BOOLEAN DEFAULT TRUE
);

ClaimHistory Table

CREATE TABLE claim_history (
  id INTEGER PRIMARY KEY,
  user_id INTEGER FOREIGN KEY,
  claim_text TEXT NOT NULL,
  verdict VARCHAR(32) NOT NULL,        -- TRUE/FALSE/MIXED/INSUFFICIENT_DATA
  confidence FLOAT NOT NULL,            -- 0.0-100.0
  domain VARCHAR(64) DEFAULT "general", -- Category (Politics, Health, etc.)
  timestamp DATETIME DEFAULT NOW(),
  short_id VARCHAR(16) UNIQUE,          -- For sharing
  bookmarked BOOLEAN DEFAULT FALSE,
  details_json TEXT                     -- Full response JSON
);

ClaimCache Table

CREATE TABLE claim_cache (
  claim_hash VARCHAR(64) PRIMARY KEY,  -- SHA256 hash
  result_json TEXT NOT NULL,
  timestamp DATETIME DEFAULT NOW(),
  ttl_seconds INTEGER DEFAULT 604800   -- 7 days
);

Authentication Flow

  1. Registration โ†’ Backend hashes password with bcrypt โ†’ Stores in DB
  2. Login โ†’ Verifies password โ†’ Generates JWT token (24-hour expiration)
  3. API Requests โ†’ Include Authorization: Bearer <token> header
  4. Token Verification โ†’ JWT decoded and validated on each request
  5. Logout โ†’ Frontend removes token from localStorage

Token Structure (JWT):

Header: {"alg": "HS256", "typ": "JWT"}
Payload: {"sub": "username", "exp": 1234567890, "iat": 1234567890}
Signature: HMACSHA256(header.payload, SECRET_KEY)

๐Ÿš€ Development

Running Both Services Locally

Terminal 1 โ€” Backend:

cd fake-news-ai/backend
source venv/bin/activate
python3 -m uvicorn main:app --reload --port 8000

Terminal 2 โ€” Frontend:

cd fake-news-ai/frontend/react-app
npm run dev -- --host 0.0.0.0 --port 5173

Terminal 3 โ€” Ollama (optional):

ollama serve

Building for Production

Backend:

# Create optimized build
cd backend
python3 -m uvicorn main:app --host 0.0.0.0 --port 8000
# With gunicorn for production:
gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app

Frontend:

cd frontend/react-app
npm run build   # Creates dist/ folder (~500KB minified)
npm run preview # Preview production build locally

Testing

Backend Tests:

cd backend
pytest tests/ -v

Frontend Build Check:

cd frontend/react-app
npm run lint
npm run build

Code Quality

Pre-commit Hooks (Secret Scanning):

# Install pre-commit
pip install pre-commit

# Setup git hooks
pre-commit install

# Run gitleaks scan
pre-commit run gitleaks --all-files

โšก Performance

Benchmarks (CPU-Only Inference, Ollama)

Stage Duration Notes
Claim Analysis 5-10s Entity extraction + decomposition
Evidence Retrieval 8-15s Multi-API search + FAISS ranking
Prosecutor Agent 60-90s Argument generation
Defender Agent 60-90s Argument generation
Judge Agent 90-120s Verdict synthesis
Total Pipeline 220-325s Full end-to-end processing

Optimization Strategies:

  • โœ… Semantic caching (skip re-processing identical claims)
  • โœ… Parallel evidence retrieval across APIs
  • โœ… FAISS indexing for fast semantic search
  • โœ… Frontend request timeout: 600s (10 minutes)
  • โœ… LLM context window limits to prevent slowdown
  • โœ… Keep-alive settings on Ollama for warm model state

Fallback Chain Behavior

If primary LLM fails:

  1. Gemini (primary) โ†’ timeout
  2. Groq (secondary) โ†’ timeout
  3. DeepSeek (tertiary) โ†’ timeout
  4. Ollama (local fallback) โ†’ use local inference
  5. Deterministic โ†’ return structured placeholder verdict

API remains responsive even when external services degrade.


๐Ÿ›ก๏ธ Security & Privacy

Authentication

  • JWT-based stateless auth
  • bcrypt password hashing (cost factor: 12)
  • Secure token expiration (24 hours)
  • HTTPS support (production deployment)

Data Privacy

  • Local SQLite storage (no cloud transmission by default)
  • Optional Neo4j isolation
  • CORS restrictions (configurable per domain)

Secret Management

  • .env files (ignored in version control)
  • GitHub Actions secret scanning (gitleaks)
  • Pre-commit hooks for leak prevention
  • No hardcoded credentials in source code

API Security

  • Rate limiting (configurable)
  • Input validation via Pydantic
  • SQL injection prevention (SQLAlchemy ORM)
  • CSRF protection (session-based)

๐Ÿšฆ Troubleshooting

Backend Issues

Error: ModuleNotFoundError: No module named 'fastapi'

# Forgot to activate venv
source venv/bin/activate
pip install -r requirements.txt

Error: Port 8000 already in use

# Kill process using port
lsof -ti:8000 | xargs kill -9
# Or use different port
python3 -m uvicorn main:app --port 8001

Error: [LLM] Gemini: DISABLED and OLLAMA: http://localhost:11434 unreachable

# Check Gemini key in .env
grep GEMINI_API_KEY backend/.env

# Or start Ollama
ollama serve  # In another terminal

Error: sqlite3.OperationalError: database is locked

# Close any connections, then try again
# Or remove old database and restart
rm backend/veritas.db
python3 -m uvicorn main:app --port 8000 --reload

Frontend Issues

Error: npm: command not found

# Install Node.js from https://nodejs.org
node --version  # Should be 16+
npm --version   # Should be 8+

Error: Cannot GET http://localhost:5173

# Vite dev server not running
cd frontend/react-app
npm install
npm run dev

Error: POST /api/verify 500 Internal Server Error

  1. Check backend logs: tail -f backend/veritas_debug.log
  2. Verify .env files are correct
  3. Check API keys (Gemini, NewsAPI, SerpAPI)
  4. Ensure Ollama is running if using fallback

Frontend Cannot Connect to Backend

Error: ERR_CONNECTION_REFUSED or CORS error

# 1. Verify backend is running on port 8000
curl http://localhost:8000/docs

# 2. Check CORS_ORIGINS in backend/.env
cat backend/.env | grep CORS_ORIGINS
# Should be: http://localhost:5173

# 3. Check frontend .env
cat frontend/react-app/.env
# Should be: VITE_API_BASE_URL=http://localhost:8000

# 4. Check CORS middleware in backend/main.py

Error: npm install fails with peer dependency warnings

npm install --legacy-peer-deps

API Key Issues

NewsAPI 401 Unauthorized:

# Check key in .env
grep NEWSAPI_KEY backend/.env

# Test key manually
curl "https://newsapi.org/v2/everything?q=covid&apiKey=YOUR_KEY"

Gemini API quota exceeded:

# Check quota at https://console.cloud.google.com
# Or switch to Ollama for local-only operation
# Edit .env: GEMINI_API_KEY=DISABLED

Performance Issues

Verification takes >10 seconds:

  1. Check retrieval: Is NewsAPI/SerpAPI responding?

    curl https://newsapi.org/v2/everything?q=test
    curl https://serpapi.com/search?q=test
  2. Check LLM provider: Are Gemini/Ollama responsive?

    curl http://localhost:11434/api/generate
  3. Enable query caching:

    # In backend/main.py, set:
    ENABLE_ADVANCED_CACHE = True
  4. Check database size:

    ls -lh backend/veritas.db
    # If >100MB, consider archive old data

Database Issues

Lost data in veritas.db?

# Backup database before deleting
cp backend/veritas.db backend/veritas.db.backup
rm backend/veritas.db
# Restart backend to recreate with fresh schema

๐Ÿค Contributing

Code of Conduct

Be respectful, inclusive, and constructive in all interactions.

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Commit with clear messages: git commit -m "Add feature X"
  4. Run tests: pytest tests/ or npm run lint
  5. Push to your fork
  6. Open a Pull Request with description

Reporting Bugs

  • Use GitHub Issues
  • Include: Python/Node version, environment, reproduction steps, error logs
  • Attach relevant code snippets

Suggesting Features

  • Open a GitHub Discussion
  • Explain use case and expected behavior
  • Reference related issues

Code Standards

  • Python: PEP 8 (via pylint/flake8)
  • JavaScript: ESLint with React rules
  • Commits: Clear, descriptive messages
  • Documentation: Docstrings and comments for complex logic

๐Ÿ“Š Key Statistics

Metric Value
Python Files 40+
React Components 15+
API Endpoints 11
Database Tables 3
Dependencies 100+
Test Suite 8+ test files
Documentation 2000+ lines

๐Ÿ™ Acknowledgments

Built with:

  • LangGraph for agent orchestration
  • FastAPI for REST API
  • React + Vite for frontend
  • FAISS for vector search
  • LLM Providers (Gemini, Groq, DeepSeek, Ollama)

๐Ÿ“ฎ Support


๐Ÿ“„ License

This project is provided as-is for educational and research purposes.


Made with โค๏ธ for transparent, explainable AI fact-checking

Last Updated: May 11, 2026

โฌ† Back to top