
LocalGov.AI - AI-Powered Civic Technology Platform
AI-driven platform democratizing access to local government information with streaming responses and smart caching
Timeline
2 months
Role
Full Stack Developer
Team
Solo
Status
CompletedTechnology Stack
Key Challenges
- Streaming SSE Implementation
- Smart Caching with TTL
- PKCE Authentication Flow
- Real-time Response Delivery
- Rate Limiting Middleware
Key Learnings
- Google Gemini API Integration
- Server-Sent Events
- Supabase Auth & Database
- Advanced Caching Strategies
- shadcn/ui Component System
LocalGov.AI - AI-Powered Civic Technology Platform
Overview
LocalGov.AI is a production-grade civic technology platform that democratizes access to local government information by translating complex legal language into plain English. Users can ask natural language questions about local laws, ordinances, and policies and receive instant, AI-powered explanations with real-time streaming responses.
Problem Statement
Government policies and legal documents are often written in complex legal jargon that's difficult for average citizens to understand. This creates a barrier between people and the laws that affect their daily lives.
Solution
LocalGov.AI uses Google Gemini 2.0 Flash API to break down complex legal text into simple, plain language that anyone can understand. The platform features streaming responses for real-time feedback, smart caching for 95% faster repeated queries, and location-specific intelligence covering 500+ cities.
Key Features
Version 2.0 - Latest Features
Streaming Responses (SSE)
- Real-time character-by-character AI responses using Server-Sent Events
- Immediate feedback instead of blocking waits
- Enhanced user experience with live updates
Smart Caching System
- 95% faster repeated queries with intelligent 1-hour TTL cache
- Custom ResponseCache class with automatic cleanup
- Cache key generation from query + location
- Background cleanup every 10 minutes
User Authentication & Personalization
- Secure PKCE (Proof Key for Code Exchange) authentication flow
- Supabase Auth with email verification
- Search history tracking with timestamps
- Bookmark system for saving important responses
- Account management with GDPR-compliant deletion
Location Intelligence
- 500+ city autocomplete suggestions
- Location-specific legal information
- Smart location detection
Modern UI/UX
- Toast notifications for all actions (success, error, info)
- Keyboard shortcuts (Cmd/Ctrl + K for quick search)
- Loading skeletons instead of spinners
- Dark/Light theme with system detection
- Markdown rendering for rich formatted responses
- Framer Motion animations for smooth transitions
- Mobile-first responsive design
Tech Stack
Frontend
- Next.js 14.2.35 - App Router with React Server Components
- TypeScript 5.8.3 - Strict mode for complete type safety
- React 18.2.0 - Latest component architecture
- Tailwind CSS 3.3.3 - Custom design system
- shadcn/ui + Radix UI - 50+ reusable components
- Framer Motion 12.16.0 - Smooth animations and transitions
- react-markdown - Beautiful formatted AI responses
- react-hook-form + Zod - Type-safe form validation
- Sonner - Modern toast notifications
Backend & Infrastructure
- Google Gemini 2.0 Flash - Advanced AI language model
- Supabase - PostgreSQL database with real-time updates
- Supabase Auth - PKCE authentication flow
- Vercel - Edge deployment with global CDN
- Server-Sent Events - Streaming response implementation
Technical Implementation
Streaming API Architecture
- Built custom
/api/searchendpoint with Server-Sent Events (SSE) - Real-time response streaming using async generators
- Proper error handling and connection management
- Automatic response accumulation and storage
Advanced Caching System
- Custom ResponseCache class with Map-based storage
- Time-to-live (TTL) expiration set to 1 hour
- Intelligent cache key generation from query + location
- Background cleanup process every 10 minutes
- Returns cached responses as streams for consistency
- 95% performance improvement on repeated queries
Authentication & Database
- PKCE-based OAuth flow (most secure for client-side apps)
- Supabase PostgreSQL with real-time capabilities
- Auto-refresh token mechanism
- Session persistence with localStorage
- Protected routes with middleware session checking
Database Schema
-- Search History Table
CREATE TABLE search_history (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
query TEXT NOT NULL,
location TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Bookmarks Table
CREATE TABLE bookmarks (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
title TEXT NOT NULL,
query TEXT NOT NULL,
location TEXT NOT NULL,
content TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);Middleware & Security
- Rate limiting: 30 requests per 60 seconds per IP
- IP-based tracking using x-forwarded-for headers
- Content Security Policy (CSP) for XSS protection
- GDPR-compliant account deletion with cascading data removal
- Data encryption in transit and at rest via Supabase
What I Learned
Building LocalGov.AI taught me:
- Streaming Technologies: Implementing Server-Sent Events for real-time data delivery
- Advanced Caching: Building custom caching systems with TTL and automatic cleanup
- Modern Authentication: PKCE flow implementation for secure client-side apps
- AI Integration: Google Gemini API integration with context-aware prompting
- Component Architecture: Building with shadcn/ui and Radix UI primitives
- Database Design: PostgreSQL schema design with proper foreign key relationships
- Performance Optimization: Code splitting, lazy loading, and edge deployment
- User Experience: Toast notifications, loading states, and keyboard shortcuts
- Security Best Practices: Rate limiting, CSP headers, and GDPR compliance
Impact
LocalGov.AI makes government policies accessible to everyone, helping citizens understand their local laws and regulations without needing legal expertise.
Results:
- 95% Performance Improvement: Smart caching for repeated queries
- Real-Time Responses: Streaming SSE for immediate feedback
- 500+ Cities Supported: Location-specific legal information
- 50+ UI Components: Comprehensive component library
- PKCE Authentication: Bank-level security for user data
- GDPR Compliant: Complete data privacy and user control
- Production Ready: Deployed on Vercel with global edge distribution
Architecture Highlights
79 TypeScript/TSX Files organized in a clean, scalable structure:
- App Router with Next.js 14 for optimal routing
- 50+ shadcn/ui Components for consistent design
- Custom Hooks for logic separation
- API Routes for streaming search and auth callbacks
- Middleware for rate limiting and security
- TypeScript Strict Mode for complete type safety
