A comprehensive AI-powered legal document search and analysis platform built with FastAPI, React, and advanced AI models. This system provides semantic search, legal reasoning, document analysis, and intelligent categorization for legal professionals.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React) β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Search β β Upload β β Analysis β β
β β Interface β β System β β Dashboard β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββ΄βββββββ
β β
ββββββββββββββββββββββΌββββββββββββββΌββββββββββββββββββββββββββββ
β Backend (FastAPI) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Document β β Vector β β AI β β
β β Processor β β Store β β Analyzer β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββΌβββββββββββ
β β β
ββββββββΌββββ ββββββΌββββ βββββΌβββββ
βPostgreSQLβ βChromaDBβ βOpenAI β
βDatabase β βVectors β βModels β
ββββββββββββ ββββββββββ ββββββββββ
git clone <repository-url>
cd law_ai
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp env.example .env
# Edit .env with your configuration
cd frontend
npm install
# For development (SQLite)
cd backend
python -m app.core.database
# For production (PostgreSQL)
# Ensure PostgreSQL is running and create database
createdb legal_ai
# Terminal 1: Backend
cd backend
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
# Terminal 2: Frontend
cd frontend
npm start
Visit http://localhost:3000
to access the application.
Create a .env
file in the root directory:
# OpenRouter AI Configuration
OPENROUTER_API_KEY=your_openrouter_api_key_here
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
# AI Model Configuration
DOCUMENT_ANALYSIS_MODEL=anthropic/claude-3-sonnet
LEGAL_REASONING_MODEL=anthropic/claude-3-opus
EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
# Database Configuration
DATABASE_URL=sqlite:///./legal_ai.db # Development
# DATABASE_URL=postgresql://user:password@localhost/legal_ai # Production
# Vector Database
CHROMA_HOST=localhost
CHROMA_PORT=8001
CHROMA_COLLECTION_NAME=legal_documents
# File Processing
MAX_FILE_SIZE_MB=50
SUPPORTED_FILE_TYPES=.pdf,.docx,.txt
CHUNK_SIZE=1000
CHUNK_OVERLAP=200
# Search Configuration
MAX_SEARCH_RESULTS=50
SIMILARITY_THRESHOLD=0.7
ENABLE_HYBRID_SEARCH=true
# Optional: Advanced Features
REDIS_URL=redis://localhost:6379 # For caching
ELASTICSEARCH_URL=http://localhost:9200 # For advanced search
The system supports various AI models through OpenRouter:
anthropic/claude-3-sonnet
(default)anthropic/claude-3-opus
(default)sentence-transformers/all-MiniLM-L6-v2
law_ai/
βββ backend/ # FastAPI backend
β βββ app/
β β βββ api/ # API endpoints
β β βββ core/ # Core configuration
β β βββ models/ # Database models
β β βββ schemas/ # Pydantic schemas
β β βββ services/ # Business logic
β βββ requirements.txt
βββ frontend/ # React frontend
β βββ src/
β β βββ components/ # React components
β β βββ pages/ # Page components
β β βββ styles/ # CSS/Tailwind
β βββ package.json
βββ pdf/ # Legal documents
βββ README.md
Semantic Search:
"What are the requirements for establishing breach of contract?"
Keyword Search:
contract AND breach AND damages
Citation Search:
cite:"42 U.S.C. Β§ 1983"
Currently using API key authentication. Include your API key in the header:
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/api/documents
POST /api/documents/upload
- Upload documentsGET /api/search/semantic
- Semantic searchGET /api/search/keyword
- Keyword searchPOST /api/analysis/analyze
- AI analysisGET /api/documents/{id}
- Get document detailsFull API documentation is available at http://localhost:8000/docs
when running the backend.
# Build and start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
# Backend
docker build -t legal-ai-backend ./backend
# Frontend
docker build -t legal-ai-frontend ./frontend
cd backend
pytest tests/ -v
cd frontend
npm test
# Run full test suite
npm run test:integration
git checkout -b feature/amazing-feature
)git commit -m 'Add amazing feature'
)git push origin feature/amazing-feature
)βModule not foundβ errors:
# Ensure virtual environment is activated
source venv/bin/activate
pip install -r requirements.txt
Database connection errors:
# Check database configuration in .env
# Ensure PostgreSQL is running (production)
Frontend build errors:
cd frontend
rm -rf node_modules package-lock.json
npm install
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please:
Built with β€οΈ for the legal community