Repository navigation
1 Architecture
Bosaj edited this page Nov 5, 2026
·
4 revisions
Ministry of Justice portal (official PDFs)
│ tools/crawl_adala.py, download_core.py
▼
tools/build_corpus.py ── src/pdf_articles.py (rebuild Arabic from glyph positions)
│
▼
data/corpus.sqlite: laws, articles, FTS5 indexes, document catalogue
│
▼
src/corpus.py: named articles, legal index, Darija word map, BM25
│
▼
src/legal_rag.py: citations with source links, exact-match check, short note
│
▼
server.py (local) or api/index.py (Vercel) ── web/ (React interface)
- Nothing is generated. Every quote is a row cut from an official PDF and is compared with the corpus before it is shown.
- Declining beats guessing. A question that matches too little gets no articles and a pointer to the document search.
- Questions are private. Only language, field of law and result counts are stored.
-
The server needs no packages. It runs on the Python standard library and SQLite FTS5.
pymupdfis only needed to rebuild the corpus.
-
src/bo_diff_engine.py: Bulletin Officiel index and text comparison. Its comparisons are hand-written illustrations and are labelled as such in the interface. -
src/contract_auditor.py: pattern checks for a few clauses the law forbids. Tests confirm the articles it cites exist.
Requests run on several threads at once, so each thread has its own read-only SQLite connection (Corpus.db). Usage counters can never fail a request, and they are off on serverless hosts, where each instance has its own disk. Law text routes may be cached at the edge for a day. Answers are never cached.
Measured on production on 2026-11-05: 120 of 120 questions answered at 20 at a time, p95 about 1.9 seconds. Before this work, 15 of 120 returned 500.
Moroccan Law AI Legal Q&A Assistant Documentation — Maintained by @Bosaj