How m-tanay/criminal-law-chatbot works
This is a citation-grounded Australian criminal-law RAG assistant for Commonwealth and NSW legislation. A user asks in the React app; the app calls its chat API, the server proxy forwards to n8n, and the workflow retrieves statutory text, gates weak matches, drafts and checks a grounded answer, then returns sources with the response. Separate ingestion scripts build the shared Qdrant corpus. The README also describes a Control Hub for operations. Workflow internals are represented from README documentation; unsampled implementation details are not inferred.
Main entry points: App.tsx Chat application · common.py Chunk, embed, store · components Chat components · api.ts Chat API client
Components 25
Chat experience
- Chat application
ui/app/src/App.tsx - Chat components
ui/app/src/components - Citation extraction
ui/app/src/lib/citations.ts - Source register links
ui/app/src/lib/legislation.ts - Chat API client
ui/app/src/lib/api.ts - HTTP chat proxy
ui/app/server/chatProxy.mjs
Answer workflow
- n8n chat workflow
n8n/virtual-lawyer-clean-v1.workflow.json - Input guard
n8n/virtual-lawyer-clean-v1.workflow.json - Query embedding
n8n/virtual-lawyer-clean-v1.workflow.json - Vector retrieval
n8n/virtual-lawyer-clean-v1.workflow.json - Match score gate
n8n/virtual-lawyer-clean-v1.workflow.json - Grounded answer draft
n8n/virtual-lawyer-clean-v1.workflow.json - Groundedness guard
n8n/virtual-lawyer-clean-v1.workflow.json - Audit and response
n8n/virtual-lawyer-clean-v1.workflow.json
Legislation corpus
- Qdrant collection
- Commonwealth ingestion
rag/ingest/ingest_cth.py - NSW ingestion
rag/ingest/ingest_nsw.py - NSW corpus scan
rag/ingest/scan_oalc_nsw.py - Chunk, embed, store
rag/lib/common.py
Operations
- Control Hub
control-hub/hub.py
Other components
- Legal questioner
- Ollama embeddings
- OpenRouter model
- Federal legislation source
- Open Australian Legal Corpus
Connections 30
- Legal questioner → Chat application: asks
README.md - Chat application → Chat components: renders
ui/app/src/App.tsx - Chat application → Chat API client: sends query
ui/app/src/App.tsx - Chat API client → HTTP chat proxy: posts chat
README.md - HTTP chat proxy → n8n chat workflow: forwards request
ui/app/server/chatProxy.mjs - n8n chat workflow → Input guard: sanitizes input
README.md - Input guard → Query embedding: passes input
README.md - Query embedding → Ollama embeddings: embeds query
README.md - Query embedding → Vector retrieval: provides vector
README.md - Vector retrieval → Qdrant collection: searches top 8
README.md - Vector retrieval → Match score gate: returns matches
README.md - Match score gate → Grounded answer draft: passes strong match
README.md - Match score gate → Audit and response: refuses weak match
README.md - Grounded answer draft → OpenRouter model: requests draft
README.md - Grounded answer draft → Groundedness guard: checks citations
README.md - Groundedness guard → Audit and response: passes grounded answer
README.md - Audit and response → HTTP chat proxy: returns answer and sources
README.md - Chat API client → Chat application: returns response
ui/app/src/App.tsx - Chat application → Citation extraction: extracts citations
ui/app/src/App.tsx - Chat components → Citation extraction: renders citations
ui/app/src/components/MarkdownWithCitations.tsx - Chat components → Source register links: links registers
ui/app/src/components/SourcesPanel.tsx - Federal legislation source → Commonwealth ingestion: supplies legislation
rag/ingest/ingest_cth.py - Open Australian Legal Corpus → NSW corpus scan: supplies corpus slice
README.md - NSW corpus scan → NSW ingestion: prepares input
rag/ingest/ingest_nsw.py - Commonwealth ingestion → Chunk, embed, store: uses helpers
rag/ingest/ingest_cth.py - NSW ingestion → Chunk, embed, store: uses helpers
rag/ingest/ingest_nsw.py - Chunk, embed, store → Ollama embeddings: embeds chunks
rag/lib/common.py - Chunk, embed, store → Qdrant collection: upserts chunks
rag/lib/common.py - Control Hub → Qdrant collection: browses law database
README.md - Control Hub → n8n chat workflow: inspects runs and health
README.md