AI-powered legal contract analysis platform using MindsDB Knowledge Bases for intelligent document processing, risk assessment, and automated reporting.
https://github.com/user-attachments/assets/b4ffa79e-f270-41a7-9309-f956062c6e33
Try it now with one command - no setup required!
# Create .env file with your OpenAI or Gemini API key, then run:
curl -o docker-compose.yml https://raw.githubusercontent.com/ritwickrajmakhal/legal-contract-analyzer/main/docker-compose.prod.yml && docker-compose up -d
Access your AI contract analyzer at: http://localhost:3000
✅ Complete AI Contract Analysis Platform
✅ Pre-configured MindsDB Knowledge Base
✅ Multi-source Data Integration (PostgreSQL, SharePoint, Dropbox, etc.)
✅ Interactive Chat Interface with Natural Language Queries
✅ Risk Assessment & Compliance Monitoring
✅ Automated Email Notifications & Reporting
┌─────────────────────────────────────────────────────────────────────────────┐
│ Frontend Layer (Next.js - Port 3000) │
├─────────────────────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Chat Interface │ │ Analytics │ │ Integrations │ │
│ │ • ChatContainer│ │ • Risk Gauges │ │ • Data Sources │ │
│ │ • Composer │ │ • Timeline │ │ • KB Manager │ │
│ │ • Message │ │ • Charts │ │ • Sync Status │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│ HTTP/REST API
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Backend Layer (FastAPI - Port 8000) │
├─────────────────────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Agent Routes │ │ Integration API │ │ Upload API │ │
│ │ • Chat API │ │ • Data Sources │ │ • PDF Upload │ │
│ │ • Streaming │ │ • Connection │ │ • File Parsing │ │
│ │ • Analytics │ │ • Table Sync │ │ • Validation │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ │ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ KB Manager │ │ Email Actions │ │ Core Services │ │
│ │ • KB Operations │ │ • SMTP Service │ │ • MindsDB Mgr │ │
│ │ • Search API │ │ • Notifications │ │ • Query Gen │ │
│ │ • Sync Jobs │ │ • Reporting │ │ • Health Check │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│ MindsDB SDK
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ AI/Database Layer (MindsDB - Port 47334) │
├─────────────────────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Knowledge Base │ │ AI Models │ │ Integrations │ │
│ │ • Vector Store │ │ • OpenAI GPT-4 │ │ • PostgreSQL │ │
│ │ • Document KB │ │ • Google Gemini │ │ • SharePoint │ │
│ │ • Search Index │ │ • Embeddings │ │ • Dropbox │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ │ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Agents │ │ Projects │ │ Data Flows │ │
│ │ • Contract AI │ │ • Workspaces │ │ • ETL Pipeline │ │
│ │ • Risk Analysis │ │ • Permissions │ │ • Auto Sync │ │
│ │ • Q&A System │ │ • Configs │ │ • Notifications │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Data Sources Layer │
├─────────────────────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Databases │ │ Cloud Storage │ │ Enterprise │ │
│ │ • PostgreSQL │ │ • SharePoint │ │ • Salesforce │ │
│ │ • Snowflake │ │ • Dropbox │ │ • Elasticsearch │ │
│ │ • Files/PDF │ │ • GitHub │ │ • Apache Solr │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ │ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Communication │ │ Productivity │ │ Development │ │
│ │ • Email/SMTP │ │ • Notion │ │ • GitLab │ │
│ │ • Notifications │ │ • Workspaces │ │ • Repositories │ │
│ │ • Reporting │ │ • Knowledge │ │ • CI/CD │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
Data Flow & Security
┌─────────────────────────────────────────────────────────────────────────────┐
│ • PDF Upload → FastAPI → MindsDB Knowledge Base → Vector Embeddings │
│ • User Query → Chat API → AI Agent → Knowledge Base Search → LLM Response │
│ • Data Sync → Integration API → MindsDB → Automated Knowledge Base Update │
│ • Risk Analysis → Agent API → ML Models → Interactive Analytics Dashboard │
│ • Email Actions → SMTP Service → Automated Notifications & Reports │
└─────────────────────────────────────────────────────────────────────────────┘
Deploy instantly with one command:
.env file
# Required: AI Model API Key (choose one)
OPENAI_API_KEY=your-openai-api-key-here
# OR
GEMINI_API_KEY=your-gemini-api-key-here
# Optional: Email notifications
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-password
curl -o docker-compose.yml https://raw.githubusercontent.com/ritwickrajmakhal/legal-contract-analyzer/main/docker-compose.prod.yml && docker-compose up -d
git clone https://github.com/ritwickrajmakhal/legal-contract-analyzer.git
cd legal-contract-analyzer
cp .env.example .env
# Edit .env and add your API keys
docker-compose up -d
Upload PDF Files:
Example:
Upload a vendor agreement PDF, then ask: "Analyze the risk level of this contract"
Access Integrations:
Sync Data:
Natural Language Queries: Use the chat interface to ask questions in plain English:
"What are my highest-risk vendor contracts?"
"Show contracts expiring in the next 3 months"
"Compare liability clauses across all agreements"
"Find contracts with payment terms over 60 days"
Quick Actions:
Ctrl+K (or Cmd+K on Mac) to access quick promptsView Visual Insights:
Example Queries:
"Show me a risk distribution chart for all contracts"
"Display contract renewal timeline for Q1 2025"
"Provide portfolio metrics and KPIs"
Smart Email Suggestions: The AI automatically suggests email actions based on analysis results:
Execute Email Actions:
Access KB Manager:
Advanced Search:
Ctrl+K / Cmd+K: Open quick prompts menuEnter: Send messageShift+Enter: New line in messageEscape: Close modals or quick prompts"Identify contracts with high liability exposure"
"Show me agreements missing termination clauses"
"Find vendors with uncapped indemnification terms"
"Check GDPR compliance across data processing agreements"
"Verify all contracts have proper governing law clauses"
"Find agreements missing required insurance provisions"
"Calculate total contract value by vendor"
"Show payment terms distribution across portfolio"
"Identify contracts with penalty clauses over $50k"
"List all contracts expiring in Q1 2025"
"Show renewal deadlines requiring 60-day notice"
"Find overdue contract renewals"
legal-contract-analyzer/
├── app/ # Next.js pages (layout, globals, main page)
├── components/ # React UI components (chat, analytics, integrations)
├── lib/ # TypeScript utilities and hooks
├── python-services/ # FastAPI backend
│ ├── api/ # API routes (agent, integrations, uploads, kb)
│ ├── mindsdb_manager.py # MindsDB integration
│ ├── kb_manager.py # Knowledge base operations
│ └── requirements.txt # Python dependencies
├── mdb_data/ # MindsDB persistent storage
├── docker-compose.yml # Local development
├── docker-compose.prod.yml # Production deployment
└── package.json # Node.js dependencies
Frontend
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
npm run type-check # TypeScript type checking
Backend
npm run python:install # Install Python dependencies
npm run python:dev # Start FastAPI development server
Test the backend API:
curl http://localhost:8000/health
curl -X POST http://localhost:8000/api/agent/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello, analyze my contracts"}'
Using Docker Hub images (no building required):
# Download production configuration
curl -o docker-compose.yml https://raw.githubusercontent.com/ritwickrajmakhal/legal-contract-analyzer/main/docker-compose.prod.yml
# Start all services
docker-compose up -d
Using local build:
# Build and start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
The platform is published on Docker Hub with optimized production images:
ritwickrajmakhal/legal-contract-analyzer-frontend:latest - Next.js frontend (~100MB)ritwickrajmakhal/legal-contract-analyzer-backend:latest - FastAPI backend (~200MB)ritwickrajmakhal/legal-contract-analyzer-mindsdb:latest - MindsDB with integrations (~1.5GB)git checkout -b feature/amazing-feature
git commit -m 'Add amazing feature'
git push origin feature/amazing-feature
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ for legal professionals and contract managers