- Industry
- Indian legal-tech / public legal information
- Type
- Domain AI agent + CMS + optional offline LLMs
- Role
- Architecture + full-stack + model integration
- Models (this session)
- DeepSeek online · HF Llama 2 7B / Mistral 7B / GPT-2 offline
- Stack
- Flask · SQLite · Bootstrap 5 · Tailwind · PWA
- Proof
- Landing, agent chat, jurisdiction, admin CMS
The chrome is the product: jurisdiction, legal category, wizards and drafts sit next to the model agent chat. Public copy on the landing still says “legal advisor”; the in-app notice is the contract that matters — this software does not provide legal advice.
Product walkthrough
The same system on video — public landing through the BNS agent chat, model picker and admin. It is a walkthrough, not a court filing and not a licence to practise.
Open the dedicated demo page → · Watch on YouTube →
The problem
Most “AI for law” demos are a hosted chat box with a gavel icon. That fails the moment the work is Indian, local, and sensitive:
Constraints
Delivery stayed inside the client's stack, tenancy, compliance and media-ownership boundaries. Where a choice was forced (suite vs owned plane, BYOC vs CPaaS, local vs cloud models), the architecture section below records the trade-off rather than a marketing rewrite.
- IPC-era prompts still circulating after BNS, BNSS and BSA replaced the older codes
- No court level, state or district on the question — so the model answers as if India were one forum
- Every token leaving the building because the only model is a public API
- No operator path to curate questions, categories or keys without shipping a new frontend
- Drafts (FIR, consumer complaint, notice) living in Word templates beside the chatbot instead of in the same session
A generic LLM that “knows Indian law” is the wrong product. The hard parts are domain structure, jurisdiction as input, model residency, and a CMS so legal content is not hardcoded in HTML.
Business requirements
One path for a visitor: land, understand the six public domains, start chat, pick a model, set where the matter sits, use a wizard or a document draft, and read the disclaimer. One path for ops: pages, categories, questions and API keys without touching the agent UI. Local Hugging Face models where data should not leave; API models where latency and quality need a hosted endpoint.
This page does not publish invented accuracy scores, “cases won,” or a claim that the product is a law firm. The engineering claim is a complete surface map.
The solution
Flask owns routes, sessions and model loading. SQLite is the system of record and travels with the app — no separate database server for this build. Bootstrap 5 plus Tailwind render a public landing, the agent workspace and the admin panel. A service worker and web app manifest make the UI installable as a PWA.
Three audiences, one codebase:
- Visitors — landing, category grid, features, chat
- Researchers / clerks — jurisdiction, category, suggested questions, wizards, document drafts, model switch, session history
- Admins — pages, categories, questions, encrypted API-key store
The public shell is marketing that matches the product: “Your Guide to Indian Law,” Start Chatting, Learn More, Admin. Feature cards on the same site: instant answers, expert guidance, 24/7, coverage across the six domains, private & secure, PWA support.
How the system flows
Users pick jurisdiction and category; the agent retrieves Indian law context and drafts documents — chat and wizards share one backend.
flowchart TD User[User login or guest] --> J[Jurisdiction BNS category] J --> Chat[Chat or wizard] Chat --> RAG[RAG legal corpus] RAG --> LLM[LLM draft answer] LLM --> Doc[Document draft export]
Architecture
The model is a worker. Jurisdiction, category and curated Q&A are the product. Retrieval here is structured content plus prompts — this page does not claim a vector database.
flowchart TB UI[Web chat wizards] API[Backend auth sessions] VDB[(Vector or document store)] LLM[LLM provider] UI --> API API --> VDB API --> LLM
Key components
Backend
Flask application, SQLAlchemy models, session chat, model registry, jurisdiction and wizard payloads, document-draft templates, admin auth.
Frontend
Bootstrap 5 + Tailwind. Public landing, agent workspace, admin. PWA manifest and service worker for install and basic offline shell.
Models
Hugging Face conversational / text-generation models locally. DeepSeek as an online API in this session. OpenAI and Claude as configured providers — not claimed as live in the capture if they were offline.
CMS
Dynamic pages, six legal categories, curated questions with short and full answers, API-key rows encrypted at rest and never displayed in full.
What the agent actually covers
Jurisdiction and location
The left rail is the difference between a legal product and a prompt. Jurisdiction level, state and district are first-class. This session set Panchayat and Karnataka; the district list loaded Bangalore Urban, Mysore, Hubli, Mangalore, Belgaum, Gulbarga, Davanagere, Bellary, Bijapur, Raichur. Copy under the list: escalate to BDO if Panchayat cannot resolve. Important notes state that Panchayat handles local civil disputes, property matters and minor criminal cases. State information lists Karnataka High Court, the State Legal Services Authority, and the State Consumer Commission.
Legal category, wizards and drafts
Category in this capture: BNS — Bharatiya Nyaya Sanhita (Criminal), marked Beta. Guided wizards: Criminal, Civil, Consumer, Employment. Generate Documents: FIR Draft, Consumer Complaint, Legal Notice. Suggested questions change with category — the BNS view in another capture showed family-court prompts as well, because the suggestion list is category-driven, not a single hardcoded FAQ.
The chat pane is labelled Legal Assistance Chat / AI Model Agent Chat. History can be cleared. Export and share sit in the header. The public-resources strip repeats the disclaimer in the same viewport as the composer.
Model switching
Select Model is a first-class control, not a deploy-time flag. This session listed:
- DeepSeek — Online
- Llama 2 7B (Hugging Face) — Offline, gated, token set
- Mistral 7B (Hugging Face) — Offline, gated, token set
- OpenAI GPT-2 Large / GPT-2 XL (Hugging Face) — Offline
- Hugging Face GPT-2 — Offline
The workspace showed “Online — API models available” when DeepSeek was reachable. This page does not claim GPT-4, Claude-3, or any model that was marked Offline in the capture. OpenAI and Claude remain supported providers in admin when keys exist.
Admin CMS
Ops is not a second repo. The admin shell: Dashboard, Pages, Categories, Questions, API Keys, View Site.
- Dashboard — this session: 1 page, 6 categories, 0 questions in the counter yet, 1 published. Quick actions to create page, category or question. System info: AI Legal Assistant, version 1.0.0, Active
- Categories — BNS, BNSS, BSA, Family Court, Consumer Rights, Employment Rights with slug, icon, colour, Active, sort order 1–6
- New category / question — name, slug, description, icon, colour, sort; question fields include category, short answer for preview, full answer, keywords JSON, featured flag
- API keys — OpenAI, Claude (Anthropic), DeepSeek as supported providers. Keys encrypted at rest, never displayed in full, usage counted
The API-keys table in this run was empty (“No API keys configured”). DeepSeek still appeared Online in chat — provider wiring and a filled admin row are not the same screenshot. This page does not invent a live OpenAI or Claude session.
Data model (what matters)
Identity: admin users. Content: pages, page sections, categories, questions. Chat: sessions and messages with optional context summaries. Ops: model context rows and API-key records. Relationships are ordinary: a category owns questions; a session owns messages. SQLite file lives in the instance folder so backup is a file copy — credentials for local bring-up are not published here.
Engineering challenges
- Domain, not vibes — BNS/BNSS/BSA and four adjacent domains as CMS rows, not a single system prompt
- Place matters — Panchayat vs district vs higher courts changes the next step; the UI has to collect it
- Residency — local Hugging Face weights vs API models in the same picker
- Keys in the product — store OpenAI / Claude / DeepSeek without echoing secrets back to the grid
- Honesty — marketing “advisor” copy vs the in-app “does not provide legal advice” notice
How those were solved
Categories and questions are tables. Jurisdiction selectors feed the agent context. The model registry reports Online vs Offline (and gated/token state) so operators do not guess. Admin key screens mask on read. The disclaimer is in the chat rail, not only in a footer.
My role
Architecture + full-stack + model integration. Flask app and schema, public PWA, agent workspace, jurisdiction and wizard flows, document drafts, Hugging Face and API model switching, admin CMS. Live client matters stay off this page.
Technology stack
These technologies are the documented stack. This page does not add vector databases, GPT-4, or court integrations that were not part of the captured build.
Production considerations
- RAG corpus versioning for Indian law updates — not legal advice disclaimers only.
- Prompt and retrieval logs for audit without leaking client uploads.
- Rate limits on document ingestion endpoints.
Engineering outcomes
No invented “legal accuracy %” or user counts. What this system actually established:
- A public path from landing → six Indian-law categories → installable PWA chat
- An agent shell where jurisdiction, category, wizards and document drafts are visible before the first token
- A model picker that reports DeepSeek online and Hugging Face models offline in the same session
- An admin path for pages, categories, questions and masked API keys
- SQLite as an offline-capable store — no remote database server required for this build
- A product disclaimer in the same viewport as the composer
Screenshots
Architecture on this page is the HTML diagram above. The walkthrough is also on the AI Legal Assistant demo page and in Next-gen AI legal chatbot for India.
Architectural insight
A legal assistant is a jurisdiction, a domain catalogue and a model that you can keep local. If the LLM owns the forum and the statute, you do not have a product you can defend. If SQLite owns categories and questions, the UI owns place, and the model only answers inside that frame, you do.
Disclaimer: this software is for information, research and drafting workflows. It is not a law firm, not an advocate, and not legal advice. Nothing here is a filing, opinion or representation before any court or authority. Vendor names (Hugging Face, DeepSeek, OpenAI, Anthropic) are described as advertised integrations in this build.
FAQ — buyer & architecture questions
Ten common questions about this case study, fit, and engagement.
Building a domain AI assistant — legal or otherwise?
Share the statutes or playbooks, whether inference must stay on-prem, and whether operators need a CMS. The first reply is whether the gap is jurisdiction UX, local models, document drafts or admin.
Discuss Your Project