Skip to content

Repository files navigation

🗳️ VoterPulse

Real-Time Political Sentiment Intelligence for India

Track, analyze, and forecast political sentiment across all 28 states and 8 union territories

Next.js TypeScript Tailwind CSS Perplexity License

Live Demo · Documentation · Report Bug · Request Feature


📖 Overview

VoterPulse is a sophisticated political analytics platform that leverages real-time web intelligence to monitor and forecast political sentiment across India. Built for the 2029 Indian General Elections, it combines the power of Perplexity's Sonar API with interactive visualizations to deliver actionable political insights.

Why VoterPulse?

  • 🔴 Real-Time Data — No stale polls. Live sentiment from news, social media, and public discourse
  • 🗺️ Complete Coverage — All 28 states + 8 union territories with state-specific analysis
  • 📊 Visual Intelligence — Interactive maps, charts, and trend visualizations
  • ⚡ Instant Results — AI-powered analysis in seconds, not days
  • 💾 Smart Caching — Optimized API usage with SQLite-backed response caching

✨ Features

🔍 Live Sentiment Search

The home page provides a powerful search interface for real-time political intelligence.

  • Natural language queries — Ask about any party, leader, issue, or region
  • Entity extraction — Automatic detection of politicians, parties, states, and topics
  • Source citations — Every insight backed by verifiable sources
  • Trending topics — Quick access to hot political discussions

Example queries:

  • "What is the sentiment towards BJP in Maharashtra?"
  • "How is Congress performing in South India?"
  • "Public opinion on farm laws in Punjab"

📈 Sentiment Drift Tracker

Monitor how political sentiment evolves over time with the Drift page.

  • 7-day rolling analysis — Track daily sentiment changes
  • Trend visualization — Line charts with positive/negative/neutral breakdown
  • Key events timeline — Understand what drove sentiment shifts
  • Summary insights — AI-generated analysis of drift patterns

🗺️ Interactive India Heatmap

The Map page displays a color-coded political sentiment map of India.

  • State-level visualization — Every state colored by ruling party/sentiment
  • Click-to-explore — Click any state to see detailed analysis
  • Real-time data — Live sentiment scores for each region
  • Party-wise breakdown — See BJP, Congress, AAP, and regional party standings
  • Full coverage — All states including northeastern states and union territories

Color Legend:

Color Party
🟠 Orange BJP
🔵 Blue Congress (INC)
🟢 Green Regional/Other
🟡 Yellow AAP
🔴 Red Left Parties

📊 Election Forecasting

The Forecast page provides predictive analytics for upcoming elections.

  • Seat projections — Estimated seat counts with confidence intervals
  • Vote share analysis — Predicted vote percentages by party
  • Trend indicators — Up/down momentum for each party
  • Confidence levels — High/Medium/Low certainty ratings
  • Key battleground states — Focus on decisive regions

🚨 Alerts System

Stay informed about critical political developments.

  • Breaking news detection — Instant alerts for major events
  • Sentiment anomalies — Unusual shifts trigger notifications
  • Custom thresholds — Configure sensitivity levels
  • Historical log — Review past alerts and their accuracy

🏗️ Architecture

┌─────────────────────────────────────────────────────────────────────┐
│                        VOTERPULSE ARCHITECTURE                       │
├─────────────────────────────────────────────────────────────────────┤
│                                                                      │
│   ┌──────────────────────────────────────────────────────────────┐  │
│   │                    FRONTEND (Next.js 14)                      │  │
│   │                                                               │  │
│   │   ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐        │  │
│   │   │ Search  │  │  Drift  │  │   Map   │  │Forecast │        │  │
│   │   │  Page   │  │  Page   │  │  Page   │  │  Page   │        │  │
│   │   └────┬────┘  └────┬────┘  └────┬────┘  └────┬────┘        │  │
│   │        │            │            │            │              │  │
│   │        └────────────┴─────┬──────┴────────────┘              │  │
│   │                           │                                   │  │
│   └───────────────────────────┼───────────────────────────────────┘  │
│                               ▼                                      │
│   ┌──────────────────────────────────────────────────────────────┐  │
│   │                    API LAYER (Route Handlers)                 │  │
│   │                                                               │  │
│   │   /api/search      /api/data/drift     /api/data/map         │  │
│   │   /api/data/forecast    /api/health                          │  │
│   │                                                               │  │
│   └───────────────────────────┬───────────────────────────────────┘  │
│                               │                                      │
│              ┌────────────────┼────────────────┐                    │
│              ▼                ▼                ▼                    │
│   ┌──────────────┐  ┌──────────────┐  ┌──────────────┐             │
│   │  PERPLEXITY  │  │   PROMPTS    │  │   CACHE      │             │
│   │  SONAR API   │  │   ENGINE     │  │   LAYER      │             │
│   │              │  │              │  │              │             │
│   │ • sonar-pro  │  │ • Search     │  │ • SQLite     │             │
│   │ • sonar      │  │ • Map Data   │  │ • Drizzle    │             │
│   │ • Real-time  │  │ • Forecast   │  │ • 1hr TTL    │             │
│   │   web search │  │ • Drift      │  │              │             │
│   └──────────────┘  └──────────────┘  └──────────────┘             │
│                                                                      │
└─────────────────────────────────────────────────────────────────────┘

Data Flow

User Query → Cache Check → [Cache Hit] → Return Cached Data
                ↓
           [Cache Miss]
                ↓
         Perplexity API (sonar-pro/sonar)
                ↓
         Parse & Validate Response
                ↓
         Store in SQLite Cache
                ↓
         Return to Frontend

🛠️ Tech Stack

Category Technology Purpose
Framework Next.js 14.2 React framework with App Router
Language TypeScript 5.3 Type-safe development
Styling Tailwind CSS 3.4 Utility-first CSS
UI Components Radix UI Accessible component primitives
Charts Recharts 2.15 React charting library
Animations Framer Motion 12 Production-ready animations
Icons Lucide React Beautiful SVG icons
Database SQLite + Drizzle ORM Local caching layer
AI/Search Perplexity Sonar API Real-time web intelligence
Map Custom SVG Interactive India map

🚀 Quick Start

Prerequisites

  • Node.js 18.17 or later
  • npm, pnpm, or yarn
  • Perplexity API Key (Get one here)

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/VoterPulse.git
    cd VoterPulse
  2. Install dependencies

    npm install
  3. Configure environment variables

    cp .env.example .env.local

    Edit .env.local:

    # Required
    PERPLEXITY_API_KEY=pplx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    
    # Optional (for future features)
    GROQ_API_KEY=gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  4. Initialize the database

    npm run db:generate
  5. Start the development server

    npm run dev
  6. Open in browser

    Navigate to http://localhost:3000


📁 Project Structure

VoterPulse/
├── src/
│   ├── app/                          # Next.js App Router
│   │   ├── page.tsx                  # Home - Search page
│   │   ├── layout.tsx                # Root layout with navigation
│   │   ├── globals.css               # Global styles
│   │   ├── drift/
│   │   │   └── page.tsx              # Sentiment drift tracker
│   │   ├── map/
│   │   │   └── page.tsx              # Interactive India map
│   │   ├── forecast/
│   │   │   └── page.tsx              # Election forecasting
│   │   ├── alerts/
│   │   │   └── page.tsx              # Alert notifications
│   │   └── api/
│   │       ├── search/
│   │       │   └── route.ts          # Search endpoint
│   │       ├── data/
│   │       │   ├── map/route.ts      # Map data endpoint
│   │       │   ├── forecast/route.ts # Forecast endpoint
│   │       │   └── drift/route.ts    # Drift data endpoint
│   │       └── health/
│   │           └── route.ts          # Health check
│   │
│   ├── components/
│   │   ├── ui/                       # Reusable UI components
│   │   │   ├── button.tsx
│   │   │   ├── card.tsx
│   │   │   ├── input.tsx
│   │   │   └── ...
│   │   └── layout/
│   │       └── navigation.tsx        # Main navigation
│   │
│   └── lib/
│       ├── perplexity/
│       │   ├── client.ts             # Perplexity API client
│       │   └── prompts.ts            # System prompts for each feature
│       ├── db/
│       │   ├── schema.ts             # Drizzle schema
│       │   └── client.ts             # Database client
│       └── utils.ts                  # Utility functions
│
├── public/
│   └── india-states.svg              # SVG map of India
│
├── drizzle/                          # Database migrations
├── .env.example                      # Environment template
├── VoterPulse-ProjectPlan.md         # Original project specification
├── tailwind.config.ts                # Tailwind configuration
├── next.config.mjs                   # Next.js configuration
└── package.json                      # Dependencies & scripts

🔌 API Documentation

POST /api/search

Search for political sentiment and information.

Request:

{
  "query": "BJP sentiment in Gujarat"
}

Response:

{
  "answer": "BJP enjoys strong support in Gujarat...",
  "citations": ["https://source1.com", "https://source2.com"],
  "entities": {
    "politicians": ["Narendra Modi", "Bhupendra Patel"],
    "parties": ["BJP"],
    "states": ["Gujarat"],
    "topics": ["governance", "development"]
  }
}

GET /api/data/map

Get sentiment data for all Indian states.

Response:

{
  "states": [
    {
      "code": "IN-MH",
      "name": "Maharashtra",
      "sentiment": 62,
      "trend": "up",
      "rulingParty": "Mahayuti (BJP+)",
      "chiefMinister": "Devendra Fadnavis",
      "keyIssues": ["Infrastructure", "Farmers"]
    }
    // ... all 36 states/UTs
  ],
  "nationalSentiment": 58,
  "lastUpdated": "2026-01-20T12:00:00Z"
}

GET /api/data/forecast

Get election forecasting data.

Response:

{
  "projections": [
    {
      "party": "BJP",
      "seats": { "low": 280, "mid": 310, "high": 340 },
      "voteShare": 38.5,
      "trend": "stable",
      "confidence": "high"
    }
    // ... other parties
  ],
  "battlegroundStates": ["Maharashtra", "UP", "West Bengal"],
  "lastUpdated": "2026-01-20T12:00:00Z"
}

GET /api/data/drift?topic={topic}

Get 7-day sentiment drift for a topic.

Response:

{
  "topic": "BJP",
  "dailyData": [
    { "date": "2026-01-14", "positive": 45, "negative": 30, "neutral": 25 }
    // ... 7 days
  ],
  "overallTrend": "improving",
  "keyEvents": [
    { "date": "2026-01-16", "event": "PM announces new policy", "impact": "positive" }
  ],
  "summary": "Sentiment has improved by 5% over the week..."
}

🔑 Environment Variables

Variable Required Description
PERPLEXITY_API_KEY ✅ Yes Your Perplexity API key for Sonar
GROQ_API_KEY ❌ No Groq API key (reserved for future use)

📜 Available Scripts

Command Description
npm run dev Start development server on port 3000
npm run build Build for production
npm run start Start production server
npm run lint Run ESLint
npm run db:generate Generate Drizzle migrations
npm run test Run tests (when configured)

🎨 Design Philosophy

VoterPulse follows a data-forward, insight-driven design inspired by modern analytics platforms:

  1. Clarity over complexity — Clean interfaces that surface insights, not noise
  2. Real-time authenticity — Fresh data beats cached assumptions
  3. Visual storytelling — Charts and maps that tell the political story at a glance
  4. Mobile-first responsive — Works seamlessly on any device
  5. Accessible design — WCAG-compliant components via Radix UI

🗺️ State Coverage

VoterPulse provides complete coverage of India:

Major States: Maharashtra, Uttar Pradesh, Bihar, West Bengal, Madhya Pradesh, Tamil Nadu, Rajasthan, Karnataka, Gujarat, Andhra Pradesh, Odisha, Telangana, Kerala, Punjab, Haryana, Jharkhand, Chhattisgarh, Assam

Northeastern States: Arunachal Pradesh, Nagaland, Manipur, Mizoram, Tripura, Meghalaya, Sikkim

Union Territories: Delhi, Jammu & Kashmir, Ladakh, Chandigarh, Puducherry, Goa, Himachal Pradesh, Uttarakhand


📈 Roadmap

Phase Feature Status
v1.0 Core search, map, forecast, drift ✅ Complete
v1.1 Enhanced alerts system 🔄 In Progress
v1.2 Historical data comparison ⬜ Planned
v1.3 Constituency-level analysis ⬜ Planned
v1.4 Social media sentiment integration ⬜ Planned
v2.0 What-if scenario simulator ⬜ Planned

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please ensure your code follows the existing style and includes appropriate tests.


📝 License

This project is licensed under the MIT License — see the LICENSE file for details.


Acknowledgments

  • Radix UI — For accessible, unstyled component primitives
  • Recharts — For beautiful React charting
  • Tailwind CSS — For rapid UI development
  • India SVG Map — Based on simplemaps.com data

Built with ❤️ for Indian Democracy

Empowering citizens with political intelligence

⬆ Back to Top

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages