All projectsLegal RAG Application

Qanoon

Ask Pakistan's Federal Statutes a Question

Qanoon answers questions about Pakistan's federal statutes in plain language, grounded strictly in statute text, with citations that open the exact page of the exact source PDF. 525 federal laws — 6,487 pages across 21 categories — are chunked, embedded, and searchable through hybrid retrieval that fuses vector similarity with full-text search, so a specific section or act name is never missed. Every answer streams live and cites its source; every act also has a precomputed plain-language summary, key topics, and suggested questions ready with zero runtime cost.

Category
Legal RAG Application
Role
Solo design & engineering
AI engine
OpenAI (gpt-5.6-luna)
Status
Live · Open source
Built with

Next.jsReactTypeScriptTailwind CSSShadcn/UIVercel AI SDKOpenAI LLMPostgreSQLpgvectorBetter AuthResendUpstash RedisMinIO

Qanoon landing page — ask Pakistan's federal statutes a question
The landing page — ask a question, browse the corpus, or see how retrieval works.
What it does

Grounded answers, page-exact citations.

Hybrid retrieval

pgvector cosine search fused with Postgres full-text search via Reciprocal Rank Fusion — statute questions hinge on exact section and act names that pure vector search drifts on.

Cited, streamed answers

Citations render as numbered pills that open a reference panel with the exact PDF page — nothing is asserted without a source.

Category & act browsing

525 statutes across 21 categories, each with a precomputed plain-language summary, key topics, and suggested questions — a DB read, not a runtime LLM call.

Accounts & admin

Better Auth email/password and Google sign-in, a per-user dashboard and credit balance, and an admin dashboard for platform totals, user management, and in-app PDF ingestion.

The flow

From question to cited page.

  1. 1Ask a question — scoped to all laws, a category, or a single act.
  2. 2Hybrid retrieval fuses vector and full-text search results with Reciprocal Rank Fusion.
  3. 3The answer streams in, grounded strictly in the retrieved statute text.
  4. 4Citation pills open a reference panel showing the exact page of the source PDF.
Architecture

Route handlers, no orchestration layer.

Direct to Postgres + OpenAI

Next.js App Router route handlers talk directly to Postgres and OpenAI — no separate orchestration layer in between.

Better Auth

Email/password and Google OAuth, email OTP verification, password reset, and an admin plugin for roles and bans.

Cost ledger

Every OpenAI call — embeddings, chat completions, offline summarization — is logged to a usage_events table, priced from a model_pricing table.

Gallery

A closer look.

Qanoon landing page with how-it-works and corpus stats
The landing page — hero, how it works, and the 525-law, 21-category corpus.
Qanoon browse the corpus page
Browse the corpus — 21 categories of federal statutes with plain-language descriptions.
Qanoon act detail page with summary and source PDF
An act's detail page — precomputed summary, key topics, and suggested questions, with the source PDF side-by-side.
Qanoon user dashboard
The user dashboard — conversation stats, credit balance, and bookmarked answers.
Qanoon account settings page
Account settings — profile, avatar, password, and account deletion.
Qanoon ask flow with a streamed, cited answer
Ask flow — a streamed, cited answer with a reference panel that opens the exact source PDF page.