CyberKanoon — Pakistani Cybercrime Law Assistant
Grounded legal answers over Pakistan's cybercrime statutes.

Problem
People in Pakistan struggled to find reliable, easy‑to‑understand information about cybercrime and online‑harassment law. The official statutes were available only as dense PDFs and legal commentaries, making it hard for non‑lawyers to identify the relevant sections. Existing AI chatbots answered generically and often guessed when the law was unclear. There was no tool that could retrieve the exact legal text and cite it in real time.
Stack
- Next.js 15
- LangGraph.js
- Groq
- Supabase
- pgvector
- Drizzle
- Gemini embeddings
- TypeScript
What I built
I built CyberKanoon as a retrieval‑augmented generation (RAG) system using Next.js 15 for the front‑end and TypeScript throughout for type safety. The legal corpus – the full Prevention of Electronic Crimes Act 2016, relevant Pakistan Penal Code sections, and constitutional excerpts – is stored in Supabase Postgres and indexed with pgvector. I generated Gemini embeddings for each paragraph and stored them alongside the raw text. At query time, LangGraph.js orchestrates the workflow: it sends the user’s plain‑language description to Groq, which runs a Gemini model to produce a concise request for relevant passages. The system then performs a vector similarity search against pgvector, retrieves the top matches, and injects the exact citations into the prompt before the model generates the final answer. Drizzle provides a typed query layer, ensuring consistent data access. The main trade‑off was latency versus depth of retrieval; I limited the similarity search to the top five passages to keep response times low while still covering the most pertinent law. Using Gemini embeddings improved relevance but increased inference cost, which I balanced by caching frequent queries.
CyberKanoon started as a response to the gap between complex legal documents and everyday users who need clear guidance on cyber offences. I collected the official text of the Prevention of Electronic Crimes Act 2016, the relevant portions of the Pakistan Penal Code, and excerpts from the Constitution directly from the Pakistan Code and National Assembly gazette. These documents were cleaned, split into logical paragraphs, and each paragraph was embedded using Gemini embeddings. The embeddings and raw text were stored in Supabase Postgres, with a pgvector column enabling fast similarity searches.
The front‑end, built with Next.js 15, presents a simple chat interface where users describe their situation in natural language. When a query arrives, LangGraph.js triggers a multi‑step graph: first, the user’s description is sent to Groq, which runs a Gemini model to formulate a retrieval request. The system then queries pgvector for the most similar paragraphs, retrieves them via Drizzle, and assembles a prompt that includes the retrieved excerpts and a request for a concise legal answer. The model generates a response that lists the exact law, section number, prescribed punishment, and steps to report the incident to the NCCIA. Every answer ends with a citation linking back to the source paragraph.
I chose this architecture to keep the system modular and observable. LangGraph.js makes the workflow explicit and debuggable, while Supabase provides managed storage and vector search without additional infrastructure. The decision to limit retrieval to five passages balances response speed with legal coverage. The result is a trustworthy, citation‑backed chatbot that helps users navigate Pakistani cyber law without needing legal expertise.
Outcome
The assistant now returns answers that include the precise legal section, the applicable punishment, and reporting instructions, with a citation for every claim. When the corpus contains no matching provision, the bot explicitly states that no law applies instead of fabricating an answer. This behaviour reduces misinformation and gives users confidence that the guidance is grounded in official legislation.