How achemnomaer/legal-draft-ai works
LegalDraft AI is a legal-document copilot: an operator uploads a document, reviews extracted fields, generates a cited draft, and can submit edits that inform later drafts. The backend extracts text and structured data, indexes chunks for retrieval, then drafts and optionally verifies grounded output; learned preferences feed subsequent drafting. The graph includes the documented frontend capabilities and provider options. Some subsystem links rely on README descriptions or SOURCE INDEX references because their implementation excerpts were not provided.
Main entry points: drafter.py Grounded drafter · router.py Ingest and documents · main.py FastAPI application · factory.py LLM provider factory
Components 31
Review workspace
- Upload and review
frontend/app/page.tsx - Document view
frontend/app/documents/[id]/page.tsx - Draft workspace
frontend/components/DraftPanel.tsx - Citation renderer
frontend/components/DraftRenderer.tsx - Edit comparison
frontend/components/DiffEditor.tsx - Preference viewer
frontend/components/PreferenceList.tsx - HTTP client
frontend/lib/api.ts
Document ingestion
- Ingest and documents
backend/ingestion/router.py - PDF and OCR extraction
backend/ingestion/extractor.py - OCR processing
backend/ingestion/ocr.py - Structured fields
backend/ingestion/structured.py
Search and grounding
- Document chunking
backend/rag/chunker.py - Vector index
backend/rag/store.py - Hybrid retrieval
backend/rag/hybrid.py - Query endpoint
backend/rag/router.py
Draft generation
- Draft endpoint
backend/generation/router.py - Grounded drafter
backend/generation/drafter.py - Prompt builder
backend/generation/prompt_builder.py - Citation verifier
backend/generation/verifier.py
Edit learning
- Edit and preference API
backend/learning/router.py - Edit capture
backend/learning/capture.py - Preference extraction
backend/learning/pattern_extractor.py - Preference store
backend/learning/preference_store.py
Other components
- Legal operator
- FastAPI application
backend/main.py - SQLite records
backend/db.py - LLM provider factory
backend/llm/factory.py - Groq provider
backend/llm/providers/groq_llm.py - Gemini provider
backend/llm/providers/gemini_llm.py - Local embeddings
backend/llm/providers/local_embedder.py - Hosted LLM services
Connections 43
- Legal operator → Upload and review: uploads documents
- Upload and review → HTTP client: sends requests
- Document view → HTTP client: loads documents
- Draft workspace → HTTP client: requests drafts
- Draft workspace → Citation renderer: renders drafts
frontend/components/DraftPanel.tsx - Draft workspace → Edit comparison: compares edits
frontend/components/DraftPanel.tsx - Draft workspace → Preference viewer: shows preferences
frontend/components/DraftPanel.tsx - HTTP client → FastAPI application: calls over HTTP
- FastAPI application → Ingest and documents: registers routes
backend/main.py - FastAPI application → Query endpoint: registers routes
backend/main.py - FastAPI application → Draft endpoint: registers routes
backend/main.py - FastAPI application → Edit and preference API: registers routes
backend/main.py - FastAPI application → SQLite records: initializes schema
backend/main.py - Ingest and documents → PDF and OCR extraction: extracts text
backend/ingestion/router.py - PDF and OCR extraction → OCR processing: uses OCR
backend/ingestion/extractor.py - Ingest and documents → Structured fields: extracts fields
backend/ingestion/router.py - Ingest and documents → Document chunking: chunks pages
backend/ingestion/router.py - Ingest and documents → Vector index: indexes chunks
backend/ingestion/router.py - Ingest and documents → SQLite records: persists documents
backend/ingestion/router.py - Structured fields → LLM provider factory: uses LLM
backend/ingestion/structured.py - Query endpoint → Vector index: queries index
backend/rag/router.py - Grounded drafter → Hybrid retrieval: retrieves sources
backend/generation/drafter.py - Hybrid retrieval → Vector index: searches chunks
backend/rag/hybrid.py - Vector index → Local embeddings: embeds text
backend/rag/store.py - Draft endpoint → Grounded drafter: generates draft
backend/generation/router.py - Grounded drafter → Prompt builder: builds prompt
backend/generation/drafter.py - Grounded drafter → Citation verifier: checks grounding
backend/generation/drafter.py - Grounded drafter → Preference store: loads preferences
backend/generation/drafter.py - Grounded drafter → SQLite records: stores draft
backend/generation/drafter.py - Grounded drafter → LLM provider factory: generates with LLM
backend/generation/drafter.py - Citation verifier → LLM provider factory: checks with LLM
backend/generation/verifier.py - Edit and preference API → Edit capture: stores edit
backend/learning/router.py - Edit and preference API → Preference extraction: extracts patterns
backend/learning/router.py - Edit and preference API → Preference store: saves preferences
backend/learning/router.py - Edit capture → SQLite records: persists edits
backend/learning/capture.py - Preference extraction → LLM provider factory: analyzes edits
backend/learning/pattern_extractor.py - Preference store → SQLite records: reads and writes
backend/learning/preference_store.py - LLM provider factory → Groq provider: selects provider
backend/llm/factory.py - LLM provider factory → Gemini provider: selects provider
backend/llm/factory.py - Groq provider → Hosted LLM services: calls Groq
backend/llm/providers/groq_llm.py - Gemini provider → Hosted LLM services: calls Gemini
backend/llm/providers/gemini_llm.py - Groq provider → Local embeddings: delegates embeddings
backend/llm/providers/groq_llm.py - Gemini provider → Local embeddings: delegates embeddings
backend/llm/providers/gemini_llm.py