How adityaa2404/legal-assist works
Legal Assist AI turns uploaded contracts and case files into privacy-preserving analyses, clause breakdowns, grounded chat, and reports. The main workflow runs from the user’s upload through extraction/OCR, PII anonymization, session storage and background retrieval-index construction, then analysis or chat and results in the UI. Separate branches support authentication, document comparison, clause-library browsing, and permanent history. The README documents these capabilities and the worker pipeline; sampled source confirms API routing, session persistence, report tasks, and frontend streaming, but not every endpoint-to-service call.
Main entry points: tasks.py Background tasks · router.py API routes · App.tsx React app and routes · analysis.py Analysis endpoints
Components 30
User interface
- React app and routes
frontend/src/App.tsx - Upload and capture
frontend/src/components/UploadView.tsx - Analysis and document views
frontend/src/components/AnalysisDashboard.tsx - Chat interface
frontend/src/hooks/useChat.ts - History and clauses
frontend/src/components/HistoryPage.tsx - API client
frontend/src/api/axiosClient.ts
HTTP API
- FastAPI application
backend/app/main.py - API routes
backend/app/api/v1/router.py - Document endpoints
backend/app/api/v1/documents.py - Analysis endpoints
backend/app/api/v1/analysis.py - Chat endpoints
backend/app/api/v1/chat.py - History endpoints
backend/app/api/v1/history.py - Comparison endpoints
backend/app/api/v1/comparison.py - Clause library endpoints
backend/app/api/v1/clause_library.py - Authentication endpoints
backend/app/api/v1/auth.py
Document processing
- Background tasks
backend/app/worker/tasks.py - Document extraction and OCR
backend/app/services/document_parser.py - PII anonymization
backend/app/services/pii_anonymizer.py - HTOC construction
backend/app/services/htoc_builder.py - BM25 retrieval
backend/app/services/bm25_search.py - Tree retrieval
backend/app/services/tree_search.py - LLM provider client
backend/app/services/gemini_client.py
Persistence and queue
- Session service
backend/app/services/session_service.py - MongoDB
backend/app/core/database.py - Redis task broker
backend/app/core/redis.py
Analysis features
- Authentication service
backend/app/services/auth_service.py - PDF report generation
backend/app/services/report_generator.py - Clause library service
backend/app/services/clause_library_service.py - History service
backend/app/services/history_service.py
Other components
- User
Connections 46
- User → React app and routes: uses
- React app and routes → Upload and capture: routes to
- React app and routes → Analysis and document views: routes to
- React app and routes → Chat interface: routes to
- React app and routes → History and clauses: routes to
- Upload and capture → API client: uploads via
- Analysis and document views → API client: requests via
- Chat interface → API client: streams via
- History and clauses → API client: requests via
- API client → FastAPI application: HTTP requests
- FastAPI application → API routes: mounts routes
- API routes → Document endpoints: dispatches
- API routes → Analysis endpoints: dispatches
- API routes → Chat endpoints: dispatches
- API routes → History endpoints: dispatches
- API routes → Comparison endpoints: dispatches
- API routes → Clause library endpoints: dispatches
- API routes → Authentication endpoints: dispatches
- Document endpoints → Background tasks: queues processing
- Background tasks → Redis task broker: consumes jobs
- Background tasks → Document extraction and OCR: extracts text
- Background tasks → PII anonymization: anonymizes text
- Background tasks → HTOC construction: builds structure
- Background tasks → BM25 retrieval: builds index
- Background tasks → Session service: updates session
- Analysis endpoints → PII anonymization: deanonymizes results
- Analysis endpoints → LLM provider client: requests analysis
- Analysis endpoints → Tree retrieval: retrieves context
- Chat endpoints → BM25 retrieval: searches index
- Chat endpoints → Tree retrieval: retrieves context
- Chat endpoints → LLM provider client: generates answers
- Chat endpoints → PII anonymization: deanonymizes answers
- Tree retrieval → HTOC construction: navigates tree
- Tree retrieval → LLM provider client: selects sections
- Analysis endpoints → Background tasks: queues reports
- Background tasks → PDF report generation: renders PDF
- Background tasks → Session service: caches report
- History endpoints → History service: serves history
- History service → MongoDB: reads history
- Session service → MongoDB: reads and writes
- Authentication endpoints → Authentication service: authenticates
- Authentication service → MongoDB: reads and writes users
- Clause library endpoints → Clause library service: serves library
- Clause library service → MongoDB: reads and writes
- Comparison endpoints → LLM provider client: compares documents
- LLM provider client → User