Skip to content

Repository files navigation

BharatGov AI

India's AI-powered government-services assistant

Live Demo API Docs Next.js FastAPI Python TypeScript

BharatGov AI is a privacy-conscious assistant for Indian government services. Ask questions in plain language about schemes, documents and official procedures — it answers with citations drawn from a local knowledge base of official government sources, so you know exactly where the information came from. The app is multilingual-ready and works even when paid AI credits run out.

Try it live: https://bharatgov-ai-phi.vercel.app


Features

  • Ask about any government service — schemes, eligibility, required documents, application steps, helplines and more.
  • Source-aware answers with citations — every answer is grounded in a curated knowledge base of official government documents and returns clickable sources.
  • Multi-provider AI with automatic fallback — answers are generated by Gemini, then OpenAI, and finally a live web-search summary — the app never stops working.
  • Document and category browser — explore the underlying knowledge base by category (/categories, /documents).
  • Account dashboard with chat history — register, log in, and review your past conversations.
  • Privacy-conscious by design — chat history is stored per account and the assistant is engineered to avoid collecting unnecessary personal data.

Tech Stack

Layer Technology
Web app Next.js 15 (App Router), TypeScript, Tailwind CSS
API Python 3.12, FastAPI, SQLAlchemy, Pydantic
AI providers Google Gemini REST, OpenAI Responses API, DuckDuckGo web search (fallback)
Storage SQLite (local / single instance), PostgreSQL + Redis + Qdrant (Docker stack)
Auth Email/password (bcrypt + JWT), optional Google OAuth
Deployment Web on Vercel, API on Railway

Architecture

┌──────────────────────────┐          ┌─────────────────────────────┐
│  Next.js web app          │          │  FastAPI backend            │
│  apps/web                 │ ───────► │  services/api               │
│  - Login / Signup / Chat  │  /api/v1 │  - Auth (JWT)               │
│  - Dashboard              │          │  - /ask, /chat, /documents  │
│  - Vercel (vercel.app)    │          │  - /categories, /feedback   │
└──────────────────────────┘          │  - Railway (railway.app)    │
                                      └─────────────┬───────────────┘
                                                    │
                                     ┌──────────────┼──────────────┐
                                     ▼              ▼              ▼
                                Gemini 2.0     OpenAI GPT-4o-mini  DuckDuckGo
                               (primary LLM)   (fallback LLM)    (last-resort search)

API Overview

Base URL: https://bharatgov-ai-production.up.railway.app/api/v1 — interactive docs at /docs.

Endpoint Method Description
/auth/register POST Create an account
/auth/login POST Log in, returns a JWT
/auth/me GET Current user profile
/ask POST Ask the assistant (grounded in the knowledge base)
/chat GET / POST List / create conversations
/chat/{chat_id} GET Fetch a conversation's messages
/categories GET Knowledge-base categories
/documents GET Government source documents
/feedback POST Submit answer feedback

Getting Started (local, no Docker)

# 1. Environment
cp .env.example .env

# 2. API (port 8000)
cd services/api
python3 -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]'
python -m app.db.seed          # loads categories + 39 government source documents
uvicorn app.main:app --reload

# 3. Web (port 3000) — in a second terminal
cd apps/web
npm install
npm run dev

Open http://localhost:3000. API docs at http://localhost:8000/docs.

Docker

cp .env.example .env
docker compose up --build

The Docker stack uses PostgreSQL, Redis and Qdrant. Run the seed step once against the container DB (docker exec <api-container> python -m app.db.seed).

Environment Variables

Variable Used by Required
JWT_SECRET API Yes
OPENAI_API_KEY API (fallback LLM) No
GEMINI_API_KEY API (primary LLM) No
CORS_ORIGINS API Yes (deployed origins)
NEXT_PUBLIC_API_URL Web No (auto-resolved at runtime)
GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET API Optional
NEXT_PUBLIC_GOOGLE_CLIENT_ID Web Optional

Deployment

See docs/DEVELOPMENT.md and docs/DEPLOYMENT.md for details.

Project Structure

.
├── apps/
│   └── web/                 # Next.js frontend (login, chat, dashboard)
├── services/
│   └── api/                 # FastAPI backend
│       ├── app/api/routes/  # auth, chat, resources
│       ├── app/services/    # AI assistant (Gemini → OpenAI → web search)
│       ├── app/db/          # models + seed data
│       └── app/core/        # config, security, settings
├── docs/
├── docker-compose.yml
└── .env.example

License

MIT

About

AI-powered assistant for Indian government services. Ask about schemes, documents and procedures — answers with citations from official sources. Next.js + FastAPI + Gemini/OpenAI.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages