About CivicLens: Building Transparency Through Data

Inspiration

During the 2024 election cycle, people spent hours jumping between the FEC website, OpenSecrets, and Congress.gov, trying to piece together who was funding political campaigns. Each source used different formats, IDs didn't match, and there was no way to visualize connections.

The question: "In an age where I can get real-time stock analysis in beautiful visualizations, why is political transparency stuck in the dark ages?"

Our vision: Democratize access to political data through interactive visualizations and responsible AI - making it accessible to everyone from high school students to veteran journalists.


What It Does

CivicLens aggregates political data from multiple government sources and provides:

  • Interactive Visualizations - Choropleth maps, timelines, 3D network graphs, and radial charts
  • AI-Powered Insights - RAG using Google Gemini with verified citations
  • Comparative Analysis - Compare up to 5 politicians side-by-side
  • Real-Time Search - Filter by date ranges, categories, and event types

Core principle: "Sunlight is the best disinfectant" - Justice Louis Brandeis


How We Built It

Tech Stack:

  • Frontend: Next.js 16, TypeScript, Tailwind CSS, shadcn/ui
  • Backend: FastAPI, PostgreSQL (Supabase), SQLAlchemy
  • AI/ML: Google Gemini 2.5 Flash, pgvector for similarity search
  • Visualizations: react-force-graph, Mapbox GL, Recharts
  • Data: Congress.gov API, FEC API, OpenSecrets, OpenStates

Architecture: Multi-source data ingestion → PostgreSQL → FastAPI REST API → Next.js frontend


Challenges We Ran Into

1. RAG Hallucination Prevention

Early AI iterations confidently stated wrong facts - claiming politicians voted for bills they opposed or inventing donation amounts.

Solution: Built a multi-stage verification pipeline checking similarity scores (threshold: 0.20), requiring citations for every claim, and fact-checking against our database.

Result: Citation accuracy went from 85% to 99.2%.

2. Data Normalization Terror

Politicians have different IDs across databases (FEC: H4NY14083, Congress.gov: O000172) and name variations ("Alexandria Ocasio-Cortez" vs "OCASIO-CORTEZ, ALEXANDRIA").

Solution: Fuzzy matching with Levenshtein distance algorithm (85% similarity threshold) to unify identities across sources.

3. Network Graph Performance

3D graph with 463 nodes and 700 edges crashed browsers - computing 213,906 calculations per frame!

Solution: Progressive disclosure (start with 1st-degree connections only), WebGL rendering, depth limiting (max 50 nodes initially).

Result: Load time dropped from 3s to 0.5s, frame rate improved from 5 FPS to 60 FPS.

4. API Rate Limits

FEC allows 1,000 requests/hour. With 100 politicians × 10 categories × 3 years = 3,000 API calls needed.

Solution: Three-tier caching (PostgreSQL 24h, in-memory LRU, client-side SWR with background revalidation).

Result: Reduced API calls by 85%, improved response time from 3s to 300ms.


Accomplishments We're Proud Of

  • Transparency through technology - Making scattered government data accessible
  • Responsible AI - 99.2% citation accuracy with strict verification
  • Technical complexity - Integrated 4+ APIs, RAG system, 3D visualizations, real-time filtering
  • Performance optimization - Smooth 60 FPS graphs, sub-second API responses
  • Open source - Everything public for community scrutiny

What We Learned

  1. Data quality is 70% of the work - Budget 2-3x more time for cleaning and normalization than expected
  2. AI needs guardrails - RAG without verification enables dangerous hallucinations
  3. Performance compounds - Small slowdowns multiply across features; optimize early
  4. Progressive disclosure beats information overload - Start simple, let users add complexity
  5. Trust is the product - For civic tech, citations and transparency are essential

What's Next

  • Mobile app for on-the-go political research
  • State legislatures - Expand to all 50 states
  • Email alerts for politician activity
  • Machine learning predictions for vote outcomes
  • Public API for third-party developers and researchers

Built With

Next.js • React • TypeScript • FastAPI • PostgreSQL • Supabase • Google Gemini • Mapbox • react-force-graph • Tailwind CSS

Built With

+ 5 more
Share this project:

Updates