Skip to content

GritCheck/Droit-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DroitAI - CUAD Legal Contract Analysis System

DroitAI Logo

πŸ† Azure Innovation Challenge Entry - Enterprise-grade legal contract analysis platform powered by CUAD (Contract Understanding Atticus Dataset) strategy and Azure AI.

A production-ready RAG system specialized for legal contract analysis with enterprise security, built for Azure with Next.js frontend and FastAPI backend.

οΏ½ Innovation Focus

  • CUAD Integration: 41 legal clause types from Atticus dataset
  • Red Flag Detection: AI-powered risk identification in contracts
  • One-Click Deployment: Fully automated with data seeding
  • Enterprise Security: Managed Identity with RBAC
  • Legal Intelligence: Semantic search optimized for legal terminology

οΏ½πŸ—οΈ Architecture

DroitAI Architecture
DroitAI is a **full-stack legal AI system** with separate frontend and backend services:

Frontend (Next.js)

  • Framework: Next.js 15+ with App Router
  • Hosting: Azure App Service (Node.js 20 LTS)
  • Authentication: Entra ID SPA registration
  • Features: Contract upload, clause filtering, red flag dashboard

Backend (FastAPI)

  • Framework: FastAPI with async/await
  • Hosting: Azure App Service (Python 3.11)
  • Authentication: Entra ID Web API with OBO token flow
  • Features: CUAD processing, legal search, AI analysis

Azure Services

  • Authentication: Entra ID with On-Behalf-Of (OBO) flow + Managed Identity
  • Search: Azure AI Search with CUAD-optimized semantic ranking
  • AI: Azure OpenAI (GPT-4o) for legal analysis
  • Document Processing: Azure Document Intelligence (F0 tier)
  • Content Safety: Azure Content Safety (F0 tier)
  • Storage: Azure Storage with automated CUAD data seeding
  • Monitoring: Application Insights + Log Analytics
  • Deployment: Azure Developer CLI (azd) with Bicep

CUAD Legal Intelligence

  • 41 Clause Types: Governing Law, Change of Control, Indemnification, etc.
  • Red Flag Detection: Automated high-risk clause identification
  • Legal Analyzer: Microsoft analyzer optimized for legal terminology
  • Semantic Search: Legal context-aware search and ranking

πŸš€ Quick Start

Prerequisites

  • Azure CLI installed
  • Azure Developer CLI (azd) installed
  • Access to Azure subscription with Owner permissions

1. Clone Repository

git clone <repository>
cd droitai

2. Add Legal Contracts (Optional)

# Place your legal documents here for automated seeding
mkdir -p data/cuad-contracts
# Add your PDF/TXT contract files
cp your-contracts/*.pdf data/cuad-contracts/

3. One-Click Deployment

# Deploys infrastructure, uploads contracts, and starts applications
azd up

That's it! πŸŽ‰ Your legal contract analysis platform is ready with:

  • βœ… Infrastructure provisioned
  • βœ… CUAD contracts uploaded automatically
  • βœ… Search index created and populated
  • βœ… Applications running and secured

4. Access Your Platform

azd env get-values  # Get URLs and credentials

Frontend: Legal contract analysis interface
Backend API: https://<backend-app-name>.azurewebsites.net/docs

πŸ”§ Local Development

Setup Environment

# Get Azure credentials
azd env get-values > .env.local

# Frontend
cd frontend
npm install
npm run dev

# Backend
cd backend
pip install -r requirements.txt
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

πŸ“ Project Structure

/droitai
β”œβ”€β”€ /frontend (Next.js 15+ App Router)
β”‚   β”œβ”€β”€ /app
β”‚   β”‚   β”œβ”€β”€ /api/auth          # Entra ID authentication
β”‚   β”‚   β”œβ”€β”€ /chat              # Legal chat interface
β”‚   β”‚   └── layout.tsx         # Context providers
β”‚   β”œβ”€β”€ /components
β”‚   β”‚   β”œβ”€β”€ /chat              # Legal message components
β”‚   β”‚   └── /legal              # CUAD clause filters
β”‚   β”œβ”€β”€ /hooks                 # useChat, useOboToken
β”‚   └── /lib                   # Client utilities

β”œβ”€β”€ /backend (FastAPI)
β”‚   β”œβ”€β”€ /app
β”‚   β”‚   β”œβ”€β”€ /api               # API routes (v1/chat, v1/ingest)
β”‚   β”‚   β”œβ”€β”€ /core              # Security, Config
β”‚   β”‚   β”œβ”€β”€ /services          # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ search_service.py    # CUAD-optimized search
β”‚   β”‚   β”‚   β”œβ”€β”€ openai_service.py    # Legal analysis AI
β”‚   β”‚   β”‚   β”œβ”€β”€ docintel_service.py  # Document Intelligence
β”‚   β”‚   β”‚   └── safety_service.py    # Content Safety
β”‚   β”‚   └── main.py
β”‚   β”œβ”€β”€ /evaluators            # Responsible AI metrics
β”‚   └── /models                # Pydantic schemas

β”œβ”€β”€ /infra (Infrastructure as Code)
β”‚   β”œβ”€β”€ main.bicep            # Azure resources orchestration
β”‚   β”œβ”€β”€ /modules
β”‚   β”‚   β”œβ”€β”€ search.bicep       # CUAD-optimized search index
β”‚   β”‚   β”œβ”€β”€ storage.bicep      # Azure Storage
β”‚   β”‚   β”œβ”€β”€ ai-services.bicep  # OpenAI, Document Intelligence
β”‚   β”‚   └── monitoring.bicep   # App Insights, Log Analytics
β”‚   └── azure.yaml            # AZD service configuration

β”œβ”€β”€ /data/cuad-contracts/      # Legal documents for seeding
β”œβ”€β”€ /scripts
β”‚   β”œβ”€β”€ sync-data.ps1         # Windows data upload script
β”‚   β”œβ”€β”€ sync-data.sh          # Linux/Mac data upload script
β”‚   └── test-env.ps1          # Environment verification

└── README.md                  # This file

πŸ” Security Features

Enterprise Security

  • Managed Identity: Zero secrets, Azure AD RBAC only
  • Separate Identities: Frontend and backend with dedicated Entra ID apps
  • OBO Token Flow: Secure token exchange between services
  • Least Privilege Access: Granular role assignments
  • Network Security: Storage with deny-by-default, HTTPS only
  • Content Safety: Built-in legal content filtering

Compliance

  • Data Encryption: All contracts encrypted at rest and in transit

  • Audit Logging: Complete legal document access trail

  • CORS Configuration: Secure cross-origin resource sharing

  • Token Validation: Both frontend and backend validate tokens

🌟 Key Features

Legal Intelligence

  • CUAD Analysis: 41 clause types automatically identified
  • Red Flag Detection: AI-powered risk assessment
  • Legal Semantic Search: Context-aware contract search
  • Faceted Filtering: Filter by clause types, risk level, document
  • Document Intelligence: PDF, Word, and image processing

Enterprise Features

  • One-Click Deployment: Automated infrastructure and data seeding
  • Managed Identity: Production-ready security without API keys
  • Scalable Architecture: Microservices with container support
  • Responsible AI: Legal evaluation metrics and governance
  • Developer Experience: Full local development with Docker

CUAD Clause Types (41 Categories)

  • Governing Law, Change of Control, Indemnification
  • Limitation of Liability, Warranty Duration, Confidentiality
  • Non-Compete, Assignment, Termination for Convenience
  • And 32 more specialized legal clause types

οΏ½ Cost Optimization

  • Free Tiers: Search (Free), Document Intelligence (F0), Content Safety (F0)
  • Basic Tiers: App Service (B1), Storage (Standard_LRS)
  • Pay-as-you-go: OpenAI (S0) with usage-based billing
  • Monitoring: Free tier for Application Insights and Log Analytics

οΏ½πŸ› οΈ Development Workflows

Infrastructure Changes

# Preview infrastructure changes
azd provision --preview

# Deploy infrastructure only
azd provision

# Deploy application only
azd deploy

Data Management

# Add new contracts
cp new-contracts/*.pdf data/cuad-contracts/
azd up  # Re-deploys with new data

# Clear and reseed data
rm -rf data/cuad-contracts/*
azd up

πŸ“Š Monitoring & Observability

  • Application Insights: Legal document processing tracking
  • Log Analytics: Centralized legal audit logging
  • Health Checks: Application and legal service monitoring
  • Error Tracking: Comprehensive legal AI error reporting

οΏ½ Innovation Challenge Highlights

Automation Excellence

  • Zero Manual Steps: Contracts uploaded during deployment
  • Idempotent Operations: Safe re-deployment with data preservation
  • Cross-Platform: Works on Windows, Linux, and Mac

Security Innovation

  • Keyless Architecture: No API keys or secrets in code
  • RBAC-First: Role-based access control throughout
  • Identity-Based: Uses Azure AD identities exclusively

Legal AI Innovation

  • CUAD Integration: Industry-standard legal clause dataset
  • Semantic Legal Search: Optimized for legal terminology
  • Risk Intelligence: Automated red flag identification

πŸ“š Documentation

πŸ“š Architecture Documentation

Security & Authentication

Infrastructure & Deployment

Application Architecture

Development & Operations

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Test with azd up
  4. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file for details


πŸ† Built for Azure Innovation Challenge 2026
πŸ”’ Enterprise-Grade Legal AI with CUAD Integration
πŸš€ One-Click Deployment with Automated Data Seeding

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages