Skip to content
roocket_
[ ≡ ]
LEGAL · AI + WEB + MOBILE

Legal system for law firms

An AI assistant for preparing case files: it answers with verifiable citations to document, page, statute article or judgment, or says "not on file". Hybrid RAG, legislation, case law and a mobile app.

Legal system for law firms

Context

A law firm that prepares case files with hundreds of documents per matter: contracts, deeds, pleadings, rulings, emails, spreadsheets and many scans. Lawyers need to ask the case file questions and get answers with sources, not a chatbot answering from memory. We built a complete legal system: web back-office, mobile app and the whole AI layer, with Spanish legislation and case law built in.

Challenge

  • Accuracy and traceability: every claim must lead to its document and page, its statute article or its judgment. An invented citation is unacceptable.
  • Hard documents: scans, tables, annexes and legal structure (clauses, grounds, articles).
  • Legal language: article numbers, case numbers, amounts and party names that semantic search alone misses.
  • Statutes in force: cite the current consolidated text, not the original publication.
  • Confidentiality: several firms on one platform, with no data crossing between them.
  • On the move: check the case file and sources from a phone.

Solution

Back-office: chat with citations over a case file The assistant’s answer: every fact carries its citation (1), what has no basis is stated as “not on file” (2) and the answer can become a draft document (3). Fictional names.

Document ingestion

Every document goes through an asynchronous pipeline of idempotent, retryable jobs: upload of the original to S3-compatible storage, text extraction (the text layer when there is one; otherwise OCR with Amazon Textract and Claude vision as a fallback, with illegible parts marked instead of filled in), an AI-proposed classification the lawyer can confirm, structural chunking and embeddings in PostgreSQL with pgvector.

Chunking follows the legal structure: clauses, numbered grounds, articles and sections; tables stay whole and every fragment carries a context header (“Contract · Clause 5: Term”) that improves both retrieval and citation.

Document ingestion flow

Case file with its input documents classified and indexed Case file: indexed fragments, input documents with their proposed category and status. Fictional data. Interface in Spanish.

Hybrid search and reranking

Retrieval combines vector search with Spanish full-text search (for article numbers, case numbers or amounts that need an exact match), fused with Reciprocal Rank Fusion. Within a case file the search is exact, with no approximation, so nothing is missed; for the large, shared statute corpus an HNSW index is used. A cross-encoder then reranks the candidates and MMR avoids near-duplicate fragments.

Verifiable citations or “not on file”

Claude answers in structured JSON and cites by fragment ID: it never reproduces the source text. The system checks that every citation exists in the context it sent and resolves it against the database to its document and page, statute article or judgment; invented citations are dropped. If no fragment clears the relevance threshold, the answer is “not on file”: no sources, no analysis. Every answer keeps its audit trail (candidates used and dropped, with their scores).

Flow from question to cited answer

Legislation and case law

  • Legislation: consolidated Spanish statutes (BOE), cached on demand, with version date and last-checked date; the article is the unit of search and citation.
  • Case law: judgments with filters by year, court and subject, search, and a detail view with PDF, text and fragments; cited like any other source. They are added by a platform admin or a licensed provider.

Statutes and case law in the back-office Global sources: consolidated legislation and case law.

Drafts

An answer can be turned into a draft: an output document with versions, refined with instructions and exported to DOCX or PDF. Generated documents are never re-indexed as case evidence.

Isolation between firms

Every query is filtered by firm with an Eloquent global scope and, as a safety net in the database, PostgreSQL Row-Level Security; within the firm, also by case file. Legislation and case law are shared global layers. Isolation tests are mandatory, including for queued jobs.

Data layers and isolation

Swappable providers and GDPR

The language model, embeddings, reranker and OCR sit behind contracts: changing provider is a new implementation, not a domain change. With the direct API only fictional or anonymised data is used; for real client data the planned path is Bedrock in the EU with a DPA and an impact assessment.

Mobile app

An iOS and Android app with case files, documents (PDF and image viewer, extracted text and fragments), chat with citations that open the document, drafts and sources (legislation and case law). With 2FA and biometric unlock.

Mobile app: case files, case file, chat with citations, statutes and case law Mobile app (interface in Spanish). Fictional names.

Evaluation from day one

A set of golden questions over a fictional case file, including questions whose correct answer is “not on file”, measures citation accuracy and retrieval, calibrates the reranker threshold and acts as a regression net whenever chunking, search or prompts change.

Results

  • Answers with a verifiable source down to document and page, statute article or judgment, or an explicit “not on file”.
  • Case file, statutes and case law in one tool, on web and mobile.
  • Scanned documents and legal structure handled without losing traceability.
  • Each firm’s data isolated by design and in the database itself.

Stack

  • Backend: Laravel 13 as a modular monolith by domain, PostgreSQL 16 with pgvector, Redis for queues, S3-compatible storage for originals.
  • AI: Claude for answers, classification and fallback OCR; Amazon Textract for OCR; OpenAI embeddings; Cohere reranking; all behind contracts.
  • Web: React with Inertia.
  • App: Ionic + Angular + Capacitor, with 2FA and biometrics.
  • Deployment: Laravel Forge.
Stack
Laravel React Angular Ionic PostgreSQL Redis Anthropic AWS

Ready to ship the next thing?

Bring the roadmap, the stuck build, or the rough idea. We turn it into a clear plan.