SSajidur Rahman Sajid
ACTIVE2026Backend / AI Engineer

CaseVault

AI legal intelligence platform — concept & MVP

FastAPISQLAlchemySQLiteNext.js 16React 19Tailwind CSS v4framer-motion

[ 01 ] — Context

Problem

  • Bangladeshi law firms work with thousands of handwritten and scanned documents, losing annotations and struggling to find relevant precedents.
  • Generic AI chatbots hallucinate citations — and firms cannot upload confidential client files to public AI tools without risking privacy.

[ 02 ] — Response

Solution

CaseVault Phase 1 is a working MVP: a FastAPI backend ingests markdown legal documents (front-matter metadata) into SQLite, with repositories that score document relevance per query and a full-text search API.

The Next.js frontend is a dark-theme research workspace — hero search, live stats, category cards, a document reader with AI tabs (summary / ask / citations / related), query highlighting, and an XSS-safe hand-rolled markdown renderer.

Phase 2 is fully designed (Project SynthGraph): Qdrant semantic search + Neo4j knowledge graph with Leiden community detection, Celery pipelines for OCR → chunking → embeddings, and sub-graph context injected into a reranker — targeting ~790ms to first token.

[ 03 ] — Structure

Architecture

  ┌───────────────────────── Phase 1 (shipped) ─────────────────────────┐
  │  Next.js 16 SPA  ──►  FastAPI  ──►  SQLAlchemy  ──►  SQLite          │
  │  / (search)  /reader  /admin  /dashboard  /library  /workspace      │
  │  DocumentService.sync_documents_from_disk() → 46 legal docs          │
  └──────────────────────────────────────────────────────────────────────┘
  ┌───────────────────────── Phase 2 (designed) ────────────────────────┐
  │  OCR → chunk → embed → Qdrant (vector) · Neo4j (KG, Leiden)         │
  │  Celery async pipelines · BGE reranker · ~790ms TTFT budget          │
  └──────────────────────────────────────────────────────────────────────┘

[ 04 ] — Trade-offs

Key engineering decisions

  1. 01

    XSS-safe markdown without a heavy renderer

    The reader renderer is hand-rolled and output-sanitized rather than pulling in a full markdown engine — small surface, safe by default for legal content.

  2. 02

    Relevance scoring at the repository layer

    Document relevance is computed in SQL against indexed columns and cached, keeping the search API fast without introducing a search server in Phase 1.

  3. 03

    Phase-2 placeholders designed up front

    Routes like /admin, /chat, and /workspace exist as intentional shells so the product structure survives the Phase 1 → Phase 2 migration.

[ 05 ] — Under the hood

Engineering highlights

Relevance-scored search
def search(self, q: str, limit: int = 20) -> list[Document]:
    like = f"%{escape_like(q)}%"
    rows = self.session.query(Document).filter(
        or_(Document.title.ilike(like),
            Document.content.ilike(like))
    ).order_by(relevance_rank(q)).limit(limit).all()
    return rows
Keyword relevance rank prioritizes title matches over body matches.

[ 06 ] — Outcomes

Results

46
legal docs ingested
6
product surfaces designed
790ms
Phase-2 TTFT budget
0
hallucinated citations (target)

[ 08 ] — Where it's going

Status & next steps

  • Phase 2 build: Qdrant + Neo4j + Celery pipelines per the SynthGraph design.
  • Admin review queue where firms approve AI-suggested citations before they reach research notes.