AI Copilot for Government Benefits
BenefitBridge helps citizens discover, understand, and apply for Indian government welfare schemes through a deterministic eligibility engine and an AI assistant grounded in real scheme data.
- Architecture
- RAG pipeline
- Rule engine
- Folder structure
- Installation
- Running locally
- Environment variables
- Known limitations / future improvements
- License
Eligibility is never decided by the LLM. It is always decided by a deterministic rule engine; the AI only explains, summarizes, and answers follow-up questions using the engine's output plus retrieved scheme data.
User
│
▼
Questionnaire (React)
│
▼
Rule Engine ──────────────► Eligible / Almost Eligible / Not Eligible
│ (with score + reasons)
▼
RAG Context Builder (retrieves relevant schemes + FAQs for the question)
│
▼
OpenAI (gpt-4o-mini) — explanation only, never eligibility
│
▼
Frontend (results page + chat panel)
If OpenAI is unavailable or the request fails, the app falls back to a
rule-engine-only response instead of crashing or hanging — see
server/src/controllers/chatController.js.
A lightweight, dependency-free retrieval layer — no vector DB required for the MVP, but the interface is narrow enough to swap in Pinecone/Chroma later without touching any caller.
User question
│
▼
Tokenize + strip stopwords
│
▼
Score every scheme's (name + category + description + tags) against the query
│
▼
Top-N schemes ──┬──► also pull matching FAQ entries
│
▼
Build context object { schemes, faqs }
│
▼
Sent to OpenAI as the ONLY source of truth for its answer
See server/src/services/ragService.js. retrieveSchemes() and
retrieveFaqs() are the two functions you'd replace with real vector search.
server/src/services/ruleEngine.js evaluates a citizen profile against every
scheme's eligibility object and returns, per scheme:
status:eligible/almost_eligible(exactly one criterion missing) /not_eligibleeligibilityScore: 0–100 (% of criteria met)reasonsMet/reasonsMissing: human-readable explanations
Supported criteria: occupation, income_max, income_min, age_min,
age_max, gender, land_ownership, student, farmer, disability,
bpl, aadhaar, bank_account, education.
genderis only enforced if the profile supplies one — the current questionnaire doesn't ask for it, so it's treated as "not specified" rather than silently failing everyone.
BenefitBridge/
├── client/ Vite + React 19 + TypeScript SPA
│ ├── src/
│ │ ├── components/ Reusable UI (chat panel, theme toggle, etc.)
│ │ ├── routes/ File-based routes (landing, questionnaire, processing, results, admin)
│ │ ├── lib/ API clients, types, theme, utils
│ │ └── styles.css
│ └── public/
├── server/ Express API
│ ├── src/
│ │ ├── controllers/ Request handlers
│ │ ├── routes/ Express routers
│ │ ├── services/ Rule engine, RAG, OpenAI, knowledge-base composition
│ │ │ └── __tests__/ Unit tests (node --test)
│ │ ├── middleware/ helmet/cors/rate-limit/morgan/validation/error handling
│ │ ├── prompts/ System prompt + context builder
│ │ └── utils/ Generic JSON CRUD, logger, zod schemas
│ ├── db/ JSON "database" — see below
│ └── logs/ app.log (gitignored)
├── README.md
├── LICENSE
└── .env.example
Split by concern rather than one big blob, and joined back together by
server/src/services/knowledgeBase.js — the single place that knows how to
compose a "full scheme" for the rule engine/RAG/frontend, and the single
place that splits a write back out across files:
| File | Contents |
|---|---|
schemes.json |
Core metadata: id, name, category, description, benefits, tags |
eligibility_rules.json |
{ [schemeId]: eligibility criteria } |
documents.json |
{ [schemeId]: string[] } |
application_steps.json |
{ [schemeId]: string[] } |
government_links.json |
{ [schemeId]: { website, name } } |
faqs.json |
[{ schemeId, schemeName, q, a }] |
states.json / categories.json |
Static lookup lists for the questionnaire/filters |
sessions.json |
Chat history per session |
feedback.json |
Thumbs up/down feedback |
analytics.json |
Usage counters |
users.json |
Present but currently unused — see Roadmap |
Requires Node.js 18+.
npm run install:all
cp server/.env.example server/.env
cp client/.env.example client/.envEdit server/.env and set your OpenAI key:
OPENAI_API_KEY=sk-...
The eligibility checker and admin panel work without a key; only /api/chat
needs it (and gracefully degrades to a rule-engine-only reply without one).
npm run devOr separately:
npm run dev:server # http://localhost:5000
npm run dev:client # http://localhost:5173Open http://localhost:5173. Visit /admin for the scheme/analytics admin
panel.
server/.env
| Variable | Description | Default |
|---|---|---|
OPENAI_API_KEY |
OpenAI API key used by /api/chat |
(required for AI chat) |
OPENAI_MODEL |
Chat completion model | gpt-4o-mini |
PORT |
Port the Express server listens on | 5000 |
NODE_ENV |
development (logs to console + file) or production (file only) |
development |
CORS_ORIGIN |
Comma-separated list of allowed frontend origins | http://localhost:5173 |
client/.env
| Variable | Description | Default |
|---|---|---|
VITE_API_URL |
Base URL of the Express API | http://localhost:5000 |
Being upfront about what's intentionally out of scope for this pass, rather than shipping a shallow, half-working version of everything:
Implemented and verified:
- Deterministic rule engine with scoring + explainable reasons (unit tested)
- Lightweight RAG retrieval, source-of-truth-only chat, graceful AI fallback
- Knowledge base split across 6+ JSON files, composed/decomposed by one module
- Full REST API incl. spec-named admin aliases,
/api/states,/api/categories - helmet, cors, rate limiting, morgan request logging, zod validation everywhere
- Admin panel (add/delete schemes + live analytics), dark mode, chat panel
Not implemented — real gaps, not hidden ones:
- Admin panel has no auth, and no inline edit / FAQ management UI — only
add/delete. Edit
server/db/*.jsondirectly for anything else. users.jsonexists but nothing writes to it — there's no auth/account system yet.- Retrieval is keyword/tag-based, not embeddings-based.
ragService.jsand the newknowledgeBase.jscomposition layer are written so a real vector store is a drop-in replacement without touching the rule engine or controllers. - JSON-file storage is fine for a single-process MVP; not safe for multi-instance/concurrent-writer deployments.
MIT — see LICENSE.