Skip to content

ENTRYDOWN99/solution-challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Community Aid Platform

A full-stack volunteer-need matching system for NGOs, powered by Google Gemini AI. This platform connects community needs with available volunteers using intelligent matching algorithms, NLP-powered data extraction, a Gemini-driven chatbot, and real-time notifications.

React Node.js Python SQLite Gemini

๐Ÿ”— Repository: https://github.com/ENTRYDOWN99/solution-challenge

git clone https://github.com/ENTRYDOWN99/solution-challenge.git
cd solution-challenge

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   React     โ”‚โ”€โ”€โ”€โ–ถโ”‚  Node.js     โ”‚โ”€โ”€โ”€โ–ถโ”‚   SQLite     โ”‚
โ”‚   Frontend  โ”‚    โ”‚  Express API โ”‚    โ”‚   Database   โ”‚
โ”‚   (Vite)    โ”‚    โ”‚              โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚              โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                   โ”‚              โ”‚โ”€โ”€โ”€โ–ถโ”‚  In-Memory   โ”‚
                   โ”‚              โ”‚    โ”‚  Cache       โ”‚
                   โ”‚              โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚              โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                   โ”‚              โ”‚โ”€โ”€โ”€โ–ถโ”‚  Python NLP Service  โ”‚
                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚  Flask + Gemini AI   โ”‚
                                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โœจ Features

  • ๐Ÿค– Gemini AI Integration โ€” Enhanced NLP extraction, human-readable match explanations, and a volunteer-facing chatbot powered by gemini-1.5-flash
  • ๐Ÿง  Intelligent Matching Engine โ€” Matches volunteers to needs using skill overlap, distance, availability, and trust score
  • ๐Ÿ“ NLP Text Extraction โ€” Extract structured data from paper surveys using OCR + spaCy NLP, enriched by Gemini
  • ๐Ÿ’ฌ Volunteer Chatbot โ€” Multi-turn AI assistant with persistent sessions, aware of live platform context (open needs count, user role)
  • ๐Ÿ“Š Real-time Dashboard โ€” Analytics, trends, heatmaps, and coverage gap analysis
  • ๐Ÿšจ Urgency Scoring โ€” Automatic urgency calculation: severityร—0.4 + peopleร—0.3 + time_sensitiveร—0.2 + vulnerabilityร—0.1
  • ๐Ÿ“ธ OCR Pipeline โ€” Upload survey images โ†’ Tesseract OCR โ†’ Gemini-enhanced NLP extraction โ†’ auto-create needs
  • ๐Ÿ” Role-based Access โ€” Separate views for NGO admins, volunteers, and super admins
  • ๐Ÿ”” Notifications โ€” SMS (Twilio) and email (Nodemailer) for task assignments
  • ๐Ÿ—บ๏ธ Heatmap Visualization โ€” Leaflet.js map with color-coded urgency markers
  • ๐Ÿ“ DBSCAN Clustering โ€” Group nearby needs (within 200m) for efficient resource allocation
  • ๐Ÿ”— API Webhooks โ€” Accept external need data from partner NGO systems

๐Ÿ“ Project Structure

/project-root
โ”œโ”€โ”€ frontend/                 # React 18 + Vite SPA
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/       # Reusable UI components
โ”‚   โ”‚   โ”œโ”€โ”€ pages/            # Route pages
โ”‚   โ”‚   โ”œโ”€โ”€ context/          # React Context providers
โ”‚   โ”‚   โ””โ”€โ”€ services/         # API service layer
โ”‚   โ””โ”€โ”€ index.html
โ”œโ”€โ”€ backend/                  # Node.js + Express REST API
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ config/           # DB, cache, app config
โ”‚   โ”‚   โ”œโ”€โ”€ controllers/      # Route handlers
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ chatController.js   # Gemini chat proxy
โ”‚   โ”‚   โ”œโ”€โ”€ middleware/       # Auth, upload, error handling
โ”‚   โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ chat.js       # POST /api/chat
โ”‚   โ”‚   โ”œโ”€โ”€ services/         # Email, SMS services
โ”‚   โ”‚   โ”œโ”€โ”€ utils/            # Helpers (haversine, scoring)
โ”‚   โ”‚   โ””โ”€โ”€ server.js         # Entry point
โ”‚   โ””โ”€โ”€ uploads/              # File upload storage
โ”œโ”€โ”€ nlp-service/              # Python Flask + Gemini microservice
โ”‚   โ”œโ”€โ”€ app.py                # NLP + Gemini endpoints
โ”‚   โ”œโ”€โ”€ requirements.txt      # includes google-generativeai
โ”‚   โ””โ”€โ”€ .env                  # GEMINI_API_KEY (local only, not committed)
โ”œโ”€โ”€ db/                       # Database files
โ”‚   โ”œโ”€โ”€ 001_init.sql          # Schema definition
โ”‚   โ””โ”€โ”€ seed.js               # Seed data script
โ”œโ”€โ”€ docker-compose.yml
โ””โ”€โ”€ README.md

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • Python 3.11+ (optional โ€” for NLP service)
  • Docker & Docker Compose (optional)
  • Google Gemini API key (optional โ€” platform degrades gracefully without it)

Option 1: Docker

# Copy and configure the root .env (add your Gemini key here)
echo "GEMINI_API_KEY=your_key_here" > .env

# Start all services
docker-compose up --build

# Seed the database (first time only)
docker exec cap_backend npm run seed

Services:


Option 2: Manual Setup

1. Backend

cd backend
npm install
cp .env.example .env    # Configure environment variables
npm run seed            # Seed initial data (first time only)
npm run dev             # Starts on port 5000

2. NLP Service (optional but recommended)

cd nlp-service
pip install -r requirements.txt
python -m spacy download en_core_web_sm

# Add your Gemini API key (get one free at https://aistudio.google.com/app/apikey)
echo "GEMINI_API_KEY=your_key_here" > .env

python app.py           # Starts on port 5001

If the NLP service is not running, the backend automatically falls back to local regex-based extraction.
If GEMINI_API_KEY is not set, all endpoints still work โ€” Gemini features are silently disabled.

3. Frontend

cd frontend
npm install
npm run dev             # Starts on port 3000

๐Ÿ“ก API Reference

Authentication

Method Endpoint Description Auth
POST /api/auth/register Register new user No
POST /api/auth/login Login, returns JWT No
POST /api/auth/refresh Refresh access token No
GET /api/auth/me Get current user Yes

Needs

Method Endpoint Description Auth
POST /api/needs Create need (auto urgency scoring) Yes
GET /api/needs List needs (filterable, paginated) Yes
GET /api/needs/:id Get need with assignments Yes
PUT /api/needs/:id Update need Admin
DELETE /api/needs/:id Soft delete need Admin
POST /api/needs/bulk-upload OCR upload paper survey Yes
GET /api/needs/heatmap Heatmap data (lat/lng + urgency) Yes

Volunteers

Method Endpoint Description Auth
POST /api/volunteers/profile Create/update profile Yes
GET /api/volunteers List volunteers (filterable) Yes
GET /api/volunteers/:id Get full profile Yes
PUT /api/volunteers/:id/availability Update schedule Yes
GET /api/volunteers/:id/tasks Task history Yes

Matching

Method Endpoint Description Auth
POST /api/matching/run Trigger matching engine Admin
GET /api/matching/suggestions/:need_id Top 5 matches Yes
POST /api/matching/assign Assign volunteer Admin
POST /api/matching/accept/:task_id Accept task Yes
POST /api/matching/complete/:task_id Complete task Yes

Analytics

Method Endpoint Description Auth
GET /api/analytics/summary Dashboard statistics Yes
GET /api/analytics/trends 30-day trends Yes
GET /api/analytics/coverage-gaps Low coverage areas Yes
GET /api/analytics/top-needs Top 5 urgent needs Yes

Organizations

Method Endpoint Description Auth
POST /api/orgs Create organization Admin
GET /api/orgs List organizations Yes
GET /api/orgs/:id/needs Org's needs Yes
POST /api/orgs/webhook External webhook (API key) API Key

๐Ÿค– Gemini Chat (New)

Method Endpoint Description Auth
POST /api/chat Send message to Gemini volunteer assistant Yes

Request body:

{ "message": "What open needs are near me?" }

Response:

{ "reply": "There are currently 12 open needs on the platform..." }

NLP Service (Internal)

Method Endpoint Description
POST /extract Extract fields from text (Gemini-enhanced)
POST /match-score Compute match score + Gemini explanation
POST /cluster-needs DBSCAN clustering
POST /chat Gemini chatbot (called via backend proxy)
GET /health Health check (gemini_available field)

๐Ÿ”ง Environment Variables

Backend (backend/.env)

Variable Description Default
JWT_SECRET JWT signing secret Required
JWT_REFRESH_SECRET Refresh token secret Required
PORT Server port 5000
NODE_ENV Environment development
NLP_SERVICE_URL Python service URL http://localhost:5001
FRONTEND_URL Frontend URL for CORS http://localhost:3000
REDIS_URL Redis connection string (optional) In-memory fallback used
TWILIO_SID Twilio account SID Optional
TWILIO_AUTH_TOKEN Twilio auth token Optional
TWILIO_PHONE Twilio phone number Optional
SMTP_HOST SMTP server host Optional
SMTP_USER SMTP username Optional
SMTP_PASS SMTP password Optional

NLP Service (nlp-service/.env)

Variable Description Default
GEMINI_API_KEY Google Gemini API key โ€” get yours free Optional
PORT Flask service port 5001

Graceful degradation: If GEMINI_API_KEY is absent or the Gemini call fails, all endpoints continue to work using spaCy/regex logic. No crashes.

Frontend (frontend/.env)

Variable Description Default
VITE_API_URL Backend API URL http://localhost:5000/api

๐Ÿค– Gemini AI Features

1. Enhanced Data Extraction (POST /extract)

Gemini reads the raw field-report text and returns a structured JSON object that overrides and enriches the base spaCy/regex result โ€” providing more accurate location, category, severity, and a human-readable description.

2. Match Explanation (POST /match-score)

After the numeric score is computed, Gemini generates a one-sentence natural-language explanation:

{
  "match_score": 0.82,
  "explanation": "Raj is an 82% match โ€” his medical skills are exactly what's needed and he lives just 3 km away with a strong trust record.",
  "distance_km": 3.1,
  "breakdown": { "skill": 1.0, "distance": 0.88, "availability": 0.5, "trust": 0.75 }
}

3. Volunteer Chatbot (POST /api/chat)

Multi-turn conversational assistant with:

  • Persistent in-memory session per user
  • Live platform context (open needs count, user role)
  • Graceful 503 response if Gemini is unconfigured

๐Ÿงฎ Matching Algorithm

match_score = skill_match ร— 0.4 + distance_score ร— 0.3 + availability ร— 0.2 + trust ร— 0.1
  • Skill Match (40%): 1.0 if volunteer has the need's category as a skill
  • Distance Score (30%): max(0, 1 - distance / max_radius_km)
  • Availability (20%): 1.0 if volunteer is available during need's time
  • Trust Score (10%): trust_score / 100
  • Hard Filters: Score = 0 if no skill match OR distance > max radius

Needs with urgency_score > 0.85 trigger real-time matching immediately on creation.


๐Ÿ“Š Urgency Scoring

urgency = severity_norm ร— 0.4 + people_norm ร— 0.3 + time_sensitive ร— 0.2 + vulnerability_norm ร— 0.1

๐Ÿ”„ Cron Jobs

Job Schedule Description
Batch Matching Every 15 minutes Runs matching engine for all open needs
Token Cleanup Daily at 2 AM Removes expired refresh tokens

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors