A sophisticated legal AI system for Indian law, combining PDF document analysis with knowledge graph-based query resolution.
- Multi-format Support: Analyze court judgments, contracts, statutes, legal notices, and petitions
- Intelligent Segmentation: AI-powered document-type-specific parsing
- Citation Extraction: Automated extraction of case law, statutes, and legal principles
- Plain-Language Summaries: Convert complex legal text into accessible explanations
- PDF Report Generation: Comprehensive analysis reports in PDF format
- Knowledge Graph Architecture: Pre-built graph of Indian legal scenarios, principles, and articles
- Hybrid Approach: Graph matching with LLM fallback for comprehensive coverage
- Semantic Search: InLegalBERT embeddings + FAISS for fast similarity matching
- Dynamic Learning: Automatically updates knowledge graph with new scenarios
- Context-Aware Answers: Expands legal context through graph traversal
- Modern React UI: Responsive, accessible interface with TypeScript
- Real-time Processing: Live progress updates and streaming responses
- Dual-Mode Interface: PDF upload and text query interfaces
- Professional Design: Tailwind CSS with legal industry aesthetics
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React + TypeScript) β
β PDFAnalyzer β LegalQuery β Home β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β REST API
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β Backend (FastAPI) β
β /upload-pdf β /legal-query β /download/{id} β
ββββββββββββ¬βββββββββββββββββββββββββββββββββββ¬ββββββββββββββββ
β β
ββββββββΌβββββββ ββββββββΌβββββββ
β Tool 1 β β Tool 2 β
β PDF Analyzer β β Graph Query β
β β β Resolver β
β β’ Parser β β β’ Matcher β
β β’ Segmenter β β β’ Traversal β
β β’ Summarizer β β β’ AutoLinker β
β β’ Citations β β β’ Simplifier β
ββββββββββββββββ ββββββββββββββββ
- Python 3.8+ with pip
- Node.js 16+ with npm
- Git
git clone https://github.com/Boombaybay12334/LAWREADER.git
cd LAWREADERCreate Environment Files:
backend/.env:
# Not required for backend itself, but tools need their own .envtool1/.env:
OPENROUTER_API_KEY=your_openrouter_api_key_here
MISTRAL_MODEL=mistralai/mistral-7b-instructtool2/.env:
LLM_API_KEY=your_llm_api_key_here
GRAPH_PATH=law_graphTest.gpickleInstall Backend Dependencies:
cd backend
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Mac
pip install -r requirements.txt
mkdir uploads processedSetup Tool 1:
cd ../tool1
python -m venv venv
venv\Scripts\activate # Windows
pip install -r requirements.txtSetup Tool 2:
cd ../tool2
python -m venv venv
venv\Scripts\activate # Windows
pip install -r requirements.txtcd .. # Back to root
npm installTerminal 1 - Backend:
cd backend
venv\Scripts\activate
python main.pyAPI available at: http://localhost:8000
Terminal 2 - Frontend:
npm run devApp available at: http://localhost:5173
- Navigate to "PDF Analyzer" page
- Upload a legal PDF document
- Wait for processing (typically 1-2 minutes)
- Download the analyzed report
- Navigate to "Legal Query" page
- Enter your legal question in plain English
- Receive contextual answer with:
- Relevant legal principles
- Constitutional articles
- Plain-language explanation
- "Can police arrest me without a warrant during a protest?"
- "What are my rights if my employer fires me without notice?"
- "Is blocking internet during protests a violation of fundamental rights?"
| Tech | Purpose |
|---|---|
| React 18 | UI Framework |
| TypeScript | Type Safety |
| Tailwind CSS | Styling |
| Vite | Build Tool |
| Axios | API Client |
| Tech | Purpose |
|---|---|
| FastAPI | Web Framework |
| Python 3.8+ | Runtime |
| Uvicorn | ASGI Server |
| Tech | Purpose |
|---|---|
| Mistral 7B | LLM (via OpenRouter) |
| InLegalBERT | Legal Embeddings |
| BART-large-MNLI | Document Classification |
| FAISS | Vector Similarity Search |
| NetworkX | Graph Operations |
| pdfplumber | PDF Parsing |
LAWREADER/
βββ frontend/ # React application
β βββ src/
β βββ components/ # Reusable UI components
β βββ pages/ # Route pages
β βββ services/ # API client
β βββ types/ # TypeScript definitions
β
βββ backend/ # FastAPI server
β βββ main.py # Application entry
β βββ requirements.txt
β
βββ tool1/ # PDF Analyzer
β βββ pipeline/
β βββ main.py
β βββ parser.py
β βββ segmenter.py
β βββ summarizer.py
β βββ citation_extractor.py
β
βββ tool2/ # Query Resolver
β βββ lawreader_main.py
β βββ semantic_matcher.py
β βββ traversal.py
β βββ auto_linker.py
β βββ answer_simplifier.py
β
βββ data/ # Knowledge graphs & indices
βββ law_graphTest.gpickle
- Codebase Analysis Report - Comprehensive workflow analysis and recommendations
- Tool 1 README - PDF Analyzer documentation
- API Documentation - Available at
http://localhost:8000/docswhen backend is running
# Backend tests
cd backend
pytest
# Tool 1 tests
cd tool1
pytest tests/
# Tool 2 tests
cd tool2
pytest# Format code
black backend/ tool1/ tool2/
# Lint
flake8 backend/ tool1/ tool2/- Hardcoded Font Path in
tool1/pipeline/main.py- Needs relative path - Subprocess Architecture - Backend launches tools as subprocesses (inefficient)
- Single-threaded Processing - No concurrent request handling
- No Authentication - Open API (not production-ready)
- Limited Error Recovery - Failures require manual intervention
See CODEBASE_ANALYSIS_REPORT.md for detailed recommendations.
- Refactor to monolithic FastAPI app (remove subprocess calls)
- Implement caching layer (Redis)
- Add user authentication (JWT)
- Background task processing (Celery)
- Real-time progress updates (WebSockets)
- Multi-language support
- Mobile application
- Deployment guides (Docker, Kubernetes)
Contributions welcome! Please read CONTRIBUTING.md first.
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is licensed under the MIT License - see LICENSE file for details.
- Abhin - Initial work
- InLegalBERT for legal domain embeddings
- OpenRouter for LLM API access
- Indian legal community for domain knowledge
For issues and questions:
- Open an Issue
- Email: [your-email@example.com]
Made with β€οΈ for the Indian legal community
GET /health- Server health status
POST /upload-pdf- Upload and analyze PDF documentsGET /download/{file_id}- Download processed documents
POST /legal-query- Process legal questions
legal-document-analyzer/
βββ backend/
β βββ main.py # FastAPI application
β βββ requirements.txt # Python dependencies
β βββ .env # Environment variables
β βββ uploads/ # Temporary upload directory
β βββ processed/ # Processed files directory
βββ src/
β βββ components/ # React components
β β βββ Layout.tsx
β β βββ LoadingSpinner.tsx
β β βββ ErrorMessage.tsx
β β βββ SuccessMessage.tsx
β βββ pages/ # Page components
β β βββ Home.tsx
β β βββ PDFAnalyzer.tsx
β β βββ LegalQuery.tsx
β βββ services/ # API services
β β βββ api.ts
β βββ types/ # TypeScript types
β β βββ index.ts
β βββ App.tsx # Main application component
βββ package.json
βββ README.md
Create a .env file in the backend directory:
API_HOST=0.0.0.0
API_PORT=8000
DEBUG=True
LOG_LEVEL=INFO
MAX_FILE_SIZE=10485760
UPLOAD_DIR=uploads
PROCESSED_DIR=processed- File type validation (PDF only)
- File size limits (10MB maximum)
- Automatic file cleanup (files older than 1 hour)
- CORS configuration for frontend integration
- Input sanitization and validation
Replace the simulation code in main.py with actual tool execution:
# Replace the simulation with:
result = subprocess.run([
"python", "-m", "pipeline.main", "--file", str(input_path)
], capture_output=True, text=True, timeout=300)Replace the simulation code in main.py with actual tool execution:
# Replace the simulation with:
result = subprocess.run([
"python", "lawreader_main.py", "-q", query.question
], capture_output=True, text=True, timeout=120)# Backend tests (if implemented)
cd backend
python -m pytest
# Frontend tests
npm test# Build frontend
npm run build
# Start production server
npm run preview# Using uvicorn directly
uvicorn main:app --host 0.0.0.0 --port 8000
# Using gunicorn for production
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000npm run build
# Deploy the dist/ directory to your hosting service