Skip to content

KanishJebaMathewM/CivicLens

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

47 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” CivicLens

AI-Powered Civic Issue Reporting & Resolution Platform

Report infrastructure issues Β· AI-verified image analysis Β· Real-time tracking Β· Admin & Worker portals


πŸ“– Overview

CivicLens is a full-stack civic issue reporting platform that empowers citizens to report infrastructure problems (potholes, broken streetlights, garbage overflow, drainage issues, etc.) using AI-powered image analysis. The platform features three interconnected applications β€” a Citizen App, an Admin Panel, and a Worker App β€” creating a complete end-to-end lifecycle for civic issue management, from submission to resolution.

Key Highlights

  • πŸ€– AI-Powered: Google Gemini automatically generates titles, descriptions, and categories from uploaded images
  • πŸ”’ AI Image Verification: Sightengine detects and blocks AI-generated/fake images to ensure authenticity
  • πŸ—ΊοΈ Interactive Maps: Leaflet-powered map with severity-coded markers and location-based geocoding
  • πŸ“Š Real-time Updates: Supabase real-time subscriptions for live status tracking
  • πŸ“± Mobile-First + Native: Built for mobile web with Capacitor for Android APK builds
  • πŸ“§ Email Notifications: Automated email alerts when reports are assigned to officers
  • πŸ“„ PDF Reports: Client-side A4 PDF generation with embedded images and styled layout
  • 🌐 Offline Support: SQLite-based caching for offline report browsing on native devices

πŸ—οΈ Architecture

CivicLens/
β”œβ”€β”€ src/                  # πŸ“± Citizen App (Vite + React + TypeScript)
β”œβ”€β”€ admin/                # πŸ›‘οΈ Admin Panel (Vite + React + TypeScript)
β”œβ”€β”€ worker-app/           # πŸ‘· Worker App (Vite + React + TypeScript)
β”œβ”€β”€ backend/              # βš™οΈ Backend API (Node.js + Express)
β”œβ”€β”€ android/              # πŸ“² Capacitor Android project
β”œβ”€β”€ supabase/             # πŸ—„οΈ Supabase migrations & config
└── *.sql                 # πŸ“‹ Database schema files

Tech Stack

Layer Technology
Frontend React 18, TypeScript, Vite, TailwindCSS, Shadcn/UI, Radix UI, Framer Motion
Backend Node.js, Express, Multer, Nodemailer, Sharp
Database Supabase (PostgreSQL) with Row-Level Security & Real-time subscriptions
AI/ML Google Gemini 2.5 Flash (vision), Sightengine (AI image detection)
Maps Leaflet + React-Leaflet, Nominatim (geocoding via backend proxy)
Auth Clerk (citizen app), Custom auth (admin & worker)
Mobile Capacitor (Android), SQLite (offline storage)
PDF pdf-lib (client-side A4 report generation)
Hosting Render (backend), Supabase (database), Any static host (frontend)

πŸ”„ End-to-End Workflow

flowchart TD
    A[πŸ‘€ Citizen Opens App] --> B[πŸ“Έ Uploads Photo of Issue]
    B --> C{πŸ”’ AI Image Verification}
    C -->|Fake/AI Image| D[❌ Image Rejected]
    C -->|Real Image| E[πŸ€– Gemini AI Analyzes Image]
    E --> F[Auto-fills Title, Description & Category]
    F --> G[πŸ“ Citizen Picks Location on Map]
    G --> H[πŸ‘οΈ Issue Preview Screen]
    H --> I[βœ… Submit to Supabase Database]
    I --> J[πŸ“Š Admin Dashboard - Real-time]
    J --> K[πŸ›‘οΈ Admin Reviews & Assigns to Worker]
    K --> L[πŸ“§ Email Notification Sent to Worker]
    L --> M[πŸ‘· Worker App - Views Assigned Task]
    M --> N[πŸ”§ Worker Resolves Issue]
    N --> O[πŸ“Έ Worker Uploads Resolution Proof]
    O --> P[βœ… Admin Marks as Resolved]
    P --> Q[πŸ“± Citizen Sees Updated Status in Real-time]
    Q --> R[πŸ“„ Download PDF Report]
Loading

Detailed Flow

  1. Citizen submits a report β†’ Takes a photo or uploads from gallery
  2. AI Image Verification β†’ Sightengine checks if the image is real (β‰₯85% human probability required)
  3. Gemini AI Analysis β†’ Automatically generates title, description, and category from the image
  4. Location Selection β†’ Pick location on an interactive Leaflet map with reverse geocoding
  5. Preview & Submit β†’ Review all details before submitting to Supabase
  6. Real-time Sync β†’ Report instantly appears on Admin Dashboard via Supabase real-time
  7. Admin Action β†’ Admin reviews, assigns to officer/worker, sends email notification
  8. Worker Resolution β†’ Worker views assigned tasks, resolves, uploads proof
  9. Status Tracking β†’ Citizen tracks progress (Submitted β†’ Viewed by Admin β†’ Resolved)
  10. PDF Download β†’ Generate and download a professional A4 PDF report

πŸ“± Application Modules

1. Citizen App (/src)

The main mobile-first web application for citizens to report and track civic issues.

Feature Description
Onboarding Splash screen β†’ Guided onboarding β†’ Sign up / Login via Clerk
Home Dashboard Weather widget, report statistics, quick actions, latest pending issues feed
Report an Issue Photo upload β†’ AI verification β†’ Gemini auto-fill β†’ Location picker β†’ Preview β†’ Submit
My Reports View all submitted reports with status filters (Pending/Resolved/Rejected)
Report Details Full issue details, progress timeline, upvote system, admin view status, PDF download
Map View Interactive Leaflet map with severity-coded markers, geolocation, map clustering
Nearby Alerts Location-aware feed of reported issues sorted by proximity
Profile View & edit profile, manage account settings
Offline Mode SQLite-based caching of reports, weather, stats for offline browsing (native)
Push Notifications FCM token registration for push notification support (native)

Key Pages: Splash β†’ Onboarding β†’ Login / Signup β†’ Home β†’ ReportIssue β†’ ChooseLocation β†’ IssuePreview β†’ MyReports β†’ ReportDetails β†’ MapView β†’ NearbyAlerts β†’ Profile β†’ EditProfile


2. Admin Panel (/admin)

A desktop-optimized administrative dashboard for municipal authorities.

Feature Description
Dashboard Real-time stats (total, pending, resolved, rejected), recent reports table, summary panel
Issues Management Full list of all reports with sorting, filtering, and bulk actions
Report Details Detailed view, assign to officer, update status, add resolution notes
Worker Management Register, edit, and manage field workers/officers
Approvals Review and approve/reject submitted reports
Map View Geo-visualize all reported issues across the city
Analytics Charts and statistics for report trends, category breakdown
Profile Admin profile and account management
Email Notifications Sends styled HTML emails to officers when reports are assigned

Key Pages: SignIn β†’ Dashboard β†’ Issues β†’ ReportDetails β†’ Workers β†’ Approvals β†’ MapPage β†’ Analytics β†’ Profile


3. Worker App (/worker-app)

A mobile-first application for field workers to manage assigned tasks.

Feature Description
Splash & Login Animated splash screen β†’ Worker credential login
Onboarding Interactive walkthrough for new workers
Issues Near You Browse civic issues nearby with location context
My Tasks View all assigned tasks with status tracking
Issue Details View full issue details, upload resolution proof, mark as resolved
Task Review Review completed tasks and upload verification images
Profile Worker profile and settings management
AI Verification Resolution proof images are verified for authenticity

Key Pages: SplashScreen β†’ LoginPage β†’ OnboardingPage β†’ IssuesListPage β†’ IssueDetailsPage β†’ TaskReviewPage β†’ ProfilePage


4. Backend API (/backend)

A Node.js/Express server handling sensitive operations and third-party integrations.

Endpoint Method Description
/health GET Health check
/detect-ai-image POST AI image detection via Sightengine (multipart upload)
/api/reverse-geocode GET Reverse geocoding with Supabase caching (~200m radius)
/api/search-location GET Forward geocoding (text β†’ coordinates) via Nominatim proxy
/api/send-email POST Send generic HTML email
/api/send-report-assignment POST Send styled report assignment email to officers
/api/notifications/register POST Register FCM push notification token
/api/notifications/unregister POST Unregister FCM token (on logout)
/api/notifications/tokens/:userId GET Get active tokens for a user
/api/clear-cache POST Clear geocoding cache (debug)
/api/view-cache GET View cached geocoding entries (debug)

πŸ”‘ Environment Variables

⚠️ IMPORTANT: Never commit .env files. Use .env.example as a template.

The project uses environment variables across four applications. Copy the respective .env.example file to .env in each directory.

Required API Keys

Service Purpose Get it from
Clerk User authentication (citizen app) clerk.com
Supabase Database, auth, real-time subscriptions supabase.com
Google Gemini AI image analysis (vision model) makersuite.google.com
OpenWeatherMap Weather data for home dashboard openweathermap.org
Sightengine AI-generated image detection sightengine.com
Gmail SMTP Email notifications (backend) Google App Passwords

Configuration Files

CivicLens/.env.example        β†’ Citizen App (VITE_* prefixed)
CivicLens/backend/.env.example β†’ Backend Server
CivicLens/admin/.env.example   β†’ Admin Panel
CivicLens/worker-app/.env.example β†’ Worker App

πŸš€ Getting Started

Prerequisites

  • Node.js β‰₯ 18
  • npm or bun
  • A Supabase project (free tier works)
  • API keys for Clerk, Gemini, OpenWeatherMap, and Sightengine

1. Clone the Repository

git clone https://github.com/KanishJebaMathewM/CivicLens.git
cd CivicLens

2. Database Setup

Run the following SQL files in your Supabase SQL Editor (in order):

# 1. Core reports table
database-schema-reports.sql

# 2. Admin tracking columns
database-schema-admin-tracking.sql

# 3. Officers table
CREATE_OFFICERS_TABLE.sql

# 4. Worker flow migration
WORKER_FLOW_MIGRATION.sql

# 5. Any missing columns
ADD_MISSING_COLUMNS.sql

3. Setup Citizen App (Root)

# Install dependencies
npm install

# Copy environment template and fill in your keys
cp .env.example .env

# Start development server
npm run dev

The app will be available at http://localhost:5173

4. Setup Backend

cd backend

# Install dependencies
npm install

# Copy environment template and fill in your keys
cp .env.example .env

# Start development server (with auto-restart)
npm run dev

The API will be available at http://localhost:3001

5. Setup Admin Panel

cd admin

# Install dependencies
npm install

# Copy environment template and fill in your keys
cp .env.example .env

# Start development server
npm run dev

The admin panel will be available at http://localhost:5174

6. Setup Worker App

cd worker-app

# Install dependencies
npm install

# Copy environment template and fill in your keys
cp .env.example .env

# Start development server
npm run dev

The worker app will be available at http://localhost:5175

7. Android Build (Optional)

# From root directory
npm run build              # Build the Vite app
npx cap sync android       # Sync web assets to Android
npx cap open android       # Open in Android Studio

πŸ—„οΈ Database Schema

reports Table (Core)

Column Type Description
id UUID Primary key (auto-generated)
title TEXT Issue title
description TEXT Detailed description
category TEXT Road Issues, Garbage, Water/Drainage, Streetlight, etc.
status TEXT pending / resolved / rejected
severity TEXT low / medium / high
location_name TEXT Human-readable address
latitude DECIMAL GPS latitude
longitude DECIMAL GPS longitude
image_url TEXT Uploaded image URL/base64
user_id TEXT Reporter's user ID
upvotes INTEGER Community upvote count
viewed_by_admin BOOLEAN Whether admin has seen it
admin_viewed_at TIMESTAMP When admin viewed it
resolved_by TEXT Worker who resolved
resolved_at TIMESTAMP Resolution timestamp
created_at TIMESTAMP Submission time
updated_at TIMESTAMP Last update time

Supporting Tables

  • reverse_geocache β€” Caches reverse geocoding results (~200m radius)
  • fcm_tokens β€” FCM push notification tokens per user
  • officers β€” Municipal officers/workers registry
  • notifications β€” Notification events for broadcasts

πŸ€– AI Features

1. Gemini Vision Analysis

  • Auto-generates issue title (max 8 words)
  • Auto-generates concise description (1–2 sentences)
  • Auto-suggests category from predefined list
  • Uses gemini-2.5-flash-preview model with system instructions

2. Sightengine AI Image Detection

  • Detects AI-generated/fake images before submission
  • Images must be β‰₯ 85% human probability to pass
  • Compresses images server-side (via Sharp) before analysis
  • 60-second timeout with graceful fallback

3. Issue Categories (AI-classified)

  • Road Issues
  • Garbage & Cleanliness
  • Water / Drainage
  • Streetlight / Electricity
  • Public Safety
  • Public Facilities
  • Parks & Environment
  • Other

πŸ“„ PDF Report Generation

CivicLens generates professional A4 PDF reports client-side using pdf-lib:

  • Branded header with CivicLens logo and status badge
  • Issue details β€” title, category, severity, date, location
  • Description section with multi-line text wrapping
  • Evidence images β€” original issue + resolution proof (side-by-side)
  • Footer with generation timestamp and page numbers
  • Supports both web download and native (Capacitor Filesystem) save

🌐 Offline Support

On native Android builds, CivicLens uses Capacitor SQLite for offline data:

Cached Data Auto-Refresh
Home feed reports On reconnect
Nearby alerts On reconnect
My reports list On reconnect
Map markers On reconnect
Weather data 1-hour TTL
User profile On login
Report statistics On reconnect
Location history Last 20 entries

πŸ”’ Security

  • All API keys are loaded from environment variables (.env)
  • .env files are excluded from version control via .gitignore
  • Backend uses Supabase Service Role Key (never exposed to client)
  • Client uses Supabase Anon Key with Row-Level Security (RLS)
  • Sightengine API credentials are server-side only
  • SMTP credentials are server-side only
  • CORS enabled on backend for cross-origin requests
  • google-services.json is gitignored (download from Firebase Console)

πŸ“ Project Structure

CivicLens/
β”œβ”€β”€ src/                        # πŸ“± Citizen App
β”‚   β”œβ”€β”€ pages/                  # All page components
β”‚   β”‚   β”œβ”€β”€ Home.tsx            # Dashboard with weather, stats, issues
β”‚   β”‚   β”œβ”€β”€ ReportIssue.tsx     # Report form with AI analysis
β”‚   β”‚   β”œβ”€β”€ ChooseLocation.tsx  # Interactive map location picker
β”‚   β”‚   β”œβ”€β”€ IssuePreview.tsx    # Preview & submit report
β”‚   β”‚   β”œβ”€β”€ MyReports.tsx       # User's submitted reports
β”‚   β”‚   β”œβ”€β”€ ReportDetails.tsx   # Full report with progress tracker
β”‚   β”‚   β”œβ”€β”€ MapView.tsx         # City-wide issue map
β”‚   β”‚   β”œβ”€β”€ NearbyAlerts.tsx    # Proximity-based issue feed
β”‚   β”‚   β”œβ”€β”€ Profile.tsx         # User profile
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ services/               # Business logic
β”‚   β”‚   β”œβ”€β”€ geminiVision.ts     # Gemini AI image analysis
β”‚   β”‚   β”œβ”€β”€ aiImageDetectionService.ts  # Sightengine client
β”‚   β”‚   β”œβ”€β”€ WeatherService.ts   # OpenWeatherMap integration
β”‚   β”‚   β”œβ”€β”€ offlineService.ts   # SQLite offline caching
β”‚   β”‚   β”œβ”€β”€ pdfService.ts       # A4 PDF generation
β”‚   β”‚   β”œβ”€β”€ notificationService.ts  # FCM token management
β”‚   β”‚   β”œβ”€β”€ upvoteService.ts    # Upvote toggle logic
β”‚   β”‚   └── authService.ts      # Auth state management
β”‚   β”œβ”€β”€ components/             # Reusable UI components
β”‚   β”œβ”€β”€ hooks/                  # Custom React hooks
β”‚   β”œβ”€β”€ lib/                    # Utilities (Supabase client, etc.)
β”‚   └── utils/                  # Helper functions
β”‚
β”œβ”€β”€ admin/src/                  # πŸ›‘οΈ Admin Panel
β”‚   β”œβ”€β”€ pages/admin/            # Admin page components
β”‚   β”œβ”€β”€ services/               # Admin business logic
β”‚   β”œβ”€β”€ components/             # Admin UI components
β”‚   └── contexts/               # Auth context
β”‚
β”œβ”€β”€ worker-app/src/             # πŸ‘· Worker App
β”‚   β”œβ”€β”€ pages/                  # Worker page components
β”‚   β”œβ”€β”€ services/               # Worker business logic
β”‚   └── components/             # Worker UI components
β”‚
β”œβ”€β”€ backend/                    # βš™οΈ Express API Server
β”‚   β”œβ”€β”€ server.js               # Main server with all routes
β”‚   └── services/               # Backend services
β”‚       └── aiImageDetection.js # Sightengine integration
β”‚
β”œβ”€β”€ android/                    # πŸ“² Capacitor Android project
β”œβ”€β”€ *.sql                       # Database migration scripts
β”œβ”€β”€ capacitor.config.ts         # Mobile build config
└── package.json                # Root dependencies

πŸ› οΈ Scripts

Citizen App (Root)

npm run dev       # Start Vite dev server
npm run build     # Production build
npm run preview   # Preview production build
npm run lint      # Run ESLint

Backend

cd backend
npm run dev       # Start with auto-restart (--watch)
npm start         # Start production server

Admin Panel

cd admin
npm run dev       # Start Vite dev server
npm run build     # Production build

Worker App

cd worker-app
npm run dev       # Start Vite dev server
npm run build     # Production build

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Copy .env.example β†’ .env and configure your keys
  4. Make your changes
  5. Commit (git commit -m 'Add amazing feature')
  6. Push to your branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

πŸ“ License

This project is open-source. See the repository for license details.


Built with ❀️ by the CivicLens Team

About

The gap between "someone should fix this" and "it's fixed" is where CivicLens lives. AI-powered civic reporting that connects citizens directly to the people responsible for their city. Android.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors