How kartavyaverma/ai-legal-analyzer works
AI Legal Contract Analyzer is a multi-user web application for uploading contracts, reviewing clause extraction and explainable risk scores, and asking cited questions. The main workflow runs asynchronously: the API accepts an upload and queues analysis; a worker parses and indexes the document, quarantines suspicious passages, extracts and verifies clause evidence, scores risk, and saves a report. Users can then inspect the report or chat over the contract. The README documents these stages; several service implementations were not excerpted, so their internal links are based on that documentation.
Main entry points: pipeline.py Analysis orchestrator · rag.py Index and retrieval · extractor.py Clause extraction · main.py FastAPI application
Components 29
Web client
- React application
frontend/src/App.jsx - Auth state
frontend/src/context/AuthContext.jsx - API client
frontend/src/utils/api.js - Contract dashboard
frontend/src/pages/Dashboard.jsx - Analysis view
frontend/src/pages/Analysis.jsx - Cited chat
frontend/src/components/ChatInterface.jsx
API and jobs
- FastAPI application
backend/app/main.py - Authentication routes
backend/app/api/auth.py - Contract routes
backend/app/api/contracts.py - Chat routes
backend/app/api/chat.py - Job dispatch
backend/app/core/jobs.py - Analysis worker
backend/app/worker.py
Contract analysis
- Analysis orchestrator
backend/app/services/pipeline.py - Document parsing
backend/app/services/parser.py - Injection screening
backend/app/services/guard.py - Index and retrieval
backend/app/services/rag.py - Clause extraction
backend/app/services/extractor.py - Quote verification
backend/app/services/verify.py - Risk scoring
backend/app/services/risk_scorer.py - Report generation
backend/app/services/report.py
Storage and models
- Clause schemas
backend/app/models/clauses.py - User and report store
backend/app/services/store.py
External services
- Local embeddings
backend/app/core/embeddings.py - Vector index
backend/app/core/qdrant.py - LLM client
backend/app/core/llm.py - SQL database
backend/app/db.py - Redis queue
- Groq API
Other components
- Contract user
Connections 41
- Contract user → React application: uses
- React application → Auth state: provides auth
frontend/src/App.jsx - Auth state → API client: calls
frontend/src/context/AuthContext.jsx - React application → Contract dashboard: routes to
frontend/src/App.jsx - React application → Analysis view: routes to
frontend/src/App.jsx - Contract dashboard → API client: loads contracts
frontend/src/pages/Dashboard.jsx - Analysis view → API client: loads report
frontend/src/pages/Analysis.jsx - Analysis view → Cited chat: renders
frontend/src/pages/Analysis.jsx - Cited chat → API client: streams questions
frontend/src/components/ChatInterface.jsx - API client → FastAPI application: HTTP requests
- FastAPI application → Authentication routes: mounts
backend/app/main.py - FastAPI application → Contract routes: mounts
backend/app/main.py - FastAPI application → Chat routes: mounts
backend/app/main.py - Authentication routes → User and report store: accesses users
backend/app/api/auth.py - Authentication routes → FastAPI application: uses security
backend/app/api/auth.py - Contract routes → User and report store: manages contracts
backend/app/api/contracts.py - Contract routes → Job dispatch: queues analysis
backend/app/api/contracts.py - Job dispatch → Redis queue: enqueues jobs
- Analysis worker → Analysis orchestrator: runs
backend/app/worker.py - Analysis worker → Job dispatch: consumes jobs
backend/app/worker.py - Analysis orchestrator → Document parsing: parses document
backend/app/services/pipeline.py - Analysis orchestrator → Index and retrieval: indexes and quarantines
backend/app/services/pipeline.py - Analysis orchestrator → Injection screening: screens chunks
backend/app/services/pipeline.py - Analysis orchestrator → Clause extraction: extracts clauses
backend/app/services/pipeline.py - Analysis orchestrator → Risk scoring: scores risk
backend/app/services/pipeline.py - Analysis orchestrator → Report generation: builds report
backend/app/services/pipeline.py - Analysis orchestrator → User and report store: saves status and report
backend/app/services/pipeline.py - Clause extraction → Index and retrieval: retrieves passages
backend/app/services/extractor.py - Clause extraction → LLM client: requests extraction
backend/app/services/extractor.py - Clause extraction → Quote verification: verifies quotes
backend/app/services/extractor.py - Clause extraction → Clause schemas: validates output
backend/app/services/extractor.py - Risk scoring → Clause schemas: uses risk models
backend/app/services/risk_scorer.py - Index and retrieval → Local embeddings: embeds and reranks
backend/app/services/rag.py - Index and retrieval → Vector index: queries and writes
backend/app/services/rag.py - Index and retrieval → Document parsing: uses parsed chunks
backend/app/services/rag.py - LLM client → Groq API: calls
- User and report store → SQL database: reads and writes
backend/app/services/store.py - Chat routes → User and report store: loads contract
backend/app/api/chat.py - Chat routes → Index and retrieval: retrieves and answers
backend/app/api/chat.py - Chat routes → LLM client: streams response
- Index and retrieval → LLM client: rewrites and answers
backend/app/services/rag.py