Govly is an AI-powered assistant that helps residents navigate government services. It routes queries intelligently, retrieves relevant policy documents and forms via RAG, and tracks application progress through a modern chat UI.
Built with Next.js (frontend) and FastAPI (backend), vector search on Supabase pgvector, and the SEA-LION LLM.
- Smart chat routing: Classifies intent and routes to document search, form discovery, agency selection, or general advice
- RAG document and form search: Uses BAAI/bge-m3 embeddings (1024-d) over Supabase pgvector
- PDF form understanding: OCR + extraction to generate dynamic fillable schemas
- Browse database documents + AI explanations: Inspect retrieved items with contextual explanations
- Upload forms for field extraction: Turn PDFs into structured, fillable forms
- Multi-country, multi-language: Context-aware responses for Southeast Asia
- Application tracking: Local progress timeline (Applied β Under Review β Confirmed)
govly-web/
βββ backend/ # FastAPI server & RAG
β βββ main.py # API endpoints
β βββ rag/ # Embedding, matching, preprocessing
βββ frontend/ # Next.js 14 app
βββ pages/ # Chat, status pages
βββ components/ # ChatMessage, DynamicForm, Sidebar
Prereqs: Docker Desktop, Git
git clone <your-repo-url>
cd Govly
cp env.example .env
docker-compose up -dServices:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
# Stop
docker-compose downPrereqs: Node.js 18+, Python 3.11+, Git, Supabase project (pgvector), SEA-LION API key
- Backend
cd govly-web/backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtCreate .env in govly-web/backend:
SEA_LION_API_KEY=your_api_key
SUPABASE_URL=your_supabase_project_url
SUPABASE_KEY=your_supabase_anon_keyRun backend:
python main.py
# API: http://localhost:8000, Docs: http://localhost:8000/docs- Frontend
cd govly-web/frontend
npm install
npm run dev
# App: http://localhost:3000POST /api/smartChatβ Intent detection and routingPOST /api/ragLinkβ Policy/regulation document searchPOST /api/ragFormβ Government form searchPOST /api/explainβ Explain relevance of retrieved itemsPOST /api/extractFormβ PDF form field extractionPOST /api/fillFormβ AI-assisted form filling using chat contextPOST /api/documentChatβ Ask questions about a specific document (document-aware chat)
Additional endpoints for documents and forms:
GET /api/pdf/{filename}β Serve local PDF from backend/forms for previewPOST /api/uploadβ Upload PDF/JPG/PNG (β€10MB) to backend/formsPOST /api/extractFormPreprocessedβ Use preprocessed DB fields by filenamePOST /api/extractFormByIdβ Use preprocessed DB fields by numeric IDPOST /api/extractFormDirectβ Force OCR-based extraction (skip DB)POST /api/formsβ Alias to RAG form search (frontend compatibility)
Document management API (Supabase storage-backed):
GET /api/documentsβ List documents with public URLsGET /api/documents/{document_id}β Get document metadataPOST /api/documentsβ Create document recordDELETE /api/documents/{document_id}β Delete document and storage fileGET /api/documents/search?query=...β Search documents by title
Form data retrieval:
GET /api/formData/{form_id}β Full stored form dataGET /api/formSchema/{form_id}β Schema formatted for fillingGET /api/formsByCategory/{category}β Forms by categoryGET /api/formCategoriesβ List categoriesGET /api/formsSummaryβ Summary of available formsGET /api/formByFilename/{filename}β Form data by filename
Use the RAG endpoints to browse documents stored in the vector database, then call explain for AI-generated context.
Example flow:
- Search documents
curl -X POST http://localhost:8000/api/ragLink \
-H "Content-Type: application/json" \
-d '{
"query":"housing assistance policies",
"country":"Vietnam",
"language":"Vietnamese"
}'- Ask AI to explain how results relate to your query
curl -X POST http://localhost:8000/api/explain \
-H "Content-Type: application/json" \
-d '{
"user_query":"I need housing assistance",
"documents":[{"title":"...","content":"...","url":"..."}],
"document_type":"ragLink",
"country":"Vietnam",
"language":"Vietnamese"
}'The frontend surfaces this as a browsable list with contextual explanations.
Upload a government PDF form and extract a structured schema, then let AI prefill it with your chat context.
- Extract fields from a PDF
curl -X POST http://localhost:8000/api/extractForm \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/form.pdf"}'- AI-assisted fill from chat history
curl -X POST http://localhost:8000/api/fillForm \
-H "Content-Type: application/json" \
-d '{
"form_schema": {"fields": [{"name":"full_name","type":"text"}]},
"chat_history": [{"role":"user","content":"My name is Jane Doe"}]
}'In the UI, you can upload a PDF, review detected fields, edit if needed, and export the filled result.
- Embeddings:
BAAI/bge-m3(1024-d) - Database: Supabase with pgvector
- Chunking: ~1200 words with ~150 overlap
- Similarity: cosine distance via
<=>, reported as1 - distance
Supabase SQL (create tables and RPC helpers): see govly-web/README.md for full snippets.
-
Tesseract OCR: Default on-demand OCR for PDFs and images via
tesseract_extractor- Used by:
POST /api/extractForm,POST /api/extractFormDirect, and OCR fallback paths - Supports Vietnamese and English extraction, with cleaning and field inference
- Used by:
-
AWS Textract (preprocessing pipeline): Optional batch/preload flow
- Script:
govly-web/backend/preprocess_forms.py - Uploads PDFs to S3, runs Textract, parses key-values/tables, stores normalized fields to DB
- At runtime, APIs can use preprocessed schemas via
extractFormPreprocessed/extractFormById
- Script:
AWS setup (optional):
- Configure AWS credentials with Textract and S3 permissions
- Set environment variables for bucket/region/keys
- Run the preprocessing script to seed the database
See inline comments in preprocess_forms.py for parameters and execution flow.
- SEA-LION API key is required for LLM responses
- Supabase URL and anon key for RAG queries
- Optional: pre-seeded Supabase instance and keys are available on request
- Optional (AWS Textract): AWS credentials with Textract + S3 access, target S3 bucket
Frontend
cd govly-web/frontend
npm run dev
npm run build
npm run start
npm run lintBackend
cd govly-web/backend
python main.py- Ports 3000/8000 busy β stop conflicting services
- Backend fails β check venv,
.env, Python >= 3.8/3.11 - Frontend fails β ensure Node 18+, rerun
npm install - RAG empty results β verify Supabase, pgvector, and RPC SQL installed
- OCR issues β verify Tesseract installed and language packs; for Textract, check IAM and job status
MIT
pages/dashboard.tsx: Entry dashboard aggregating chat, quick actions, and navigationpages/documents.tsx: Document browser backed byGET /api/documentsand searchpages/documents/[id].tsx: Document detail with preview and AI Q&A viaPOST /api/documentChatpages/scan.tsx: Upload PDFs/images (POST /api/upload) and extract fields viaextractForm*APIspages/status.tsx: Application progress tracking (Applied β Under Review β Confirmed)pages/edit-application/[id].tsx: Review and edit captured application data- Components:
PDFViewer.tsx,WebsiteViewer.tsx,DynamicForm.tsx,AgencyDetection.tsx,Sidebar.tsx,DashboardHeader.tsx
Usage highlights:
- Browse documents, open details, and ask AI targeted questions about the current document
- Upload a PDF form, extract fields (preprocessed or OCR), review schema, and AI-prefill using chat context
- Track applications and view progress with timestamps; edit or continue later
Built by Shao Zhi, Yi Ting, Yong Sheng (NUS). Demo links and extended docs are in govly-web/README.md.