Skip to content

Latest commit

 

History

87 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AIX Contract Lifecycle Management (CLM) System

A comprehensive AI-powered contract management platform that automates contract analysis, risk assessment, and lifecycle management using advanced machine learning and natural language processing technologies.

Overview

The AIX-CLM system is a full-stack application designed to revolutionize contract management by providing intelligent document analysis, automated risk detection, and comprehensive contract lifecycle tracking. Built with modern web technologies and powered by OpenAI's GPT models, it offers both web-based and API-based contract processing capabilities.

Key Features

AI-Powered Contract Analysis

  • Automated Document Processing: Extract key information from PDF and DOCX contracts
  • Intelligent Risk Detection: Identify potential risks with severity classification (High/Medium/Low)
  • Missing Clause Detection: Automatically identify standard clauses that may be missing
  • Financial Terms Extraction: Parse payment schedules, amounts, and penalties
  • Contract Summarization: Generate concise summaries of contract purpose and scope

Comprehensive Dashboard

  • Real-time Analytics: Track contract statistics and analysis metrics
  • Visual Risk Assessment: Interactive charts and graphs for risk visualization
  • AI Insights Panel: Latest findings and recommendations from contract analysis
  • Recent Activity Tracking: Monitor recent uploads and analysis progress

Advanced Search & Discovery

  • Semantic Contract Search: Find contracts using natural language queries
  • Vector-based Similarity: Leverage OpenAI embeddings for intelligent contract matching
  • Multi-language Support: Process contracts in multiple languages with translation capabilities

Multi-language Translation

  • DeepL Integration: High-quality translation services for international contracts
  • Arabic Contract Support: Specialized handling for Arabic legal documents
  • Batch Translation: Process multiple documents simultaneously

Enterprise Security

  • User Authentication: Secure JWT-based authentication system
  • Role-based Access Control: User and admin role management
  • File Upload Security: Secure document handling with UploadThing integration

Architecture

Frontend (Next.js 16)

  • React 19: Modern UI components with TypeScript
  • Tailwind CSS: Responsive design system
  • Radix UI: Accessible component library
  • Recharts: Data visualization and analytics

Backend Services

  • Next.js API Routes: RESTful API endpoints
  • MongoDB: Document database for contract storage
  • Mongoose: ODM for MongoDB integration
  • JWT Authentication: Secure token-based authentication

AI & ML Services

  • OpenAI GPT-4o: Contract analysis and information extraction
  • OpenAI Embeddings: Semantic search and similarity matching
  • Pinecone: Vector database for knowledge base (optional)

Document Processing

  • PDF Parsing: pdf-parse library for PDF text extraction
  • DOCX Processing: mammoth library for Word document processing
  • File Upload: UploadThing for secure file handling

Project Structure

AIX-CLM/
├── app/                          # Next.js 16 App Router
│   ├── (auth)/                  # Authentication pages
│   │   ├── login/page.tsx
│   │   └── register/page.tsx
│   ├── api/                     # API routes
│   │   ├── auth/               # Authentication endpoints
│   │   ├── contracts/          # Contract management APIs
│   │   └── uploadthing/        # File upload handling
│   ├── dashboard/              # Main application dashboard
│   │   ├── contracts/          # Contract management pages
│   │   ├── upload/             # Contract upload interface
│   │   └── layout.tsx          # Dashboard layout
│   └── globals.css             # Global styles
├── components/                  # React components
│   ├── ui/                     # Reusable UI components
│   ├── AIInsights.tsx          # AI analysis insights
│   ├── ContractsChart.tsx      # Contract analytics charts
│   ├── RiskSidebar.tsx         # Risk analysis sidebar
│   └── UploadContractDialog.tsx # Contract upload modal
├── lib/                        # Utility libraries
│   ├── auth.ts                 # Authentication utilities
│   ├── contractExtractor.ts    # Contract analysis service
│   ├── mongodb.ts              # Database connection
│   └── uploadthing.ts          # File upload configuration
├── models/                     # Database models
│   ├── Contract.ts             # Contract schema
│   └── User.ts                 # User schema
├── middleware/                 # Next.js middleware
│   └── auth.ts                 # Authentication middleware
├── contract-extractor/         # Python contract analysis service
│   ├── app/contract_extractor.py
│   ├── requirements.txt
│   └── tests/
├── contract-searcher/          # Semantic search service
│   ├── app/contract_search.py
│   └── requirements.txt
├── pinecone_knowledgebase/     # Vector database service
│   ├── app/
│   └── scripts/
├── translator/                 # Translation service
│   ├── app/
│   └── requirements.txt
└── package.json                # Node.js dependencies

Getting Started

Prerequisites

  • Node.js 18+
  • MongoDB database
  • OpenAI API key
  • DeepL API key (for translation features)
  • UploadThing account (for file uploads)

Installation

  1. Clone the repository

    git clone https://github.com/OptiMealCMUQ/AIX-CLM.git
    cd AIX-CLM
  2. Install dependencies

    npm install
  3. Set up environment variables Create a .env.local file in the root directory:

    MONGODB_URI=mongodb://localhost:27017/aix-clm
    OPENAI_API_KEY=your_openai_api_key
    DEEPL_API_KEY=your_deepl_api_key
    UPLOADTHING_SECRET=your_uploadthing_secret
    UPLOADTHING_APP_ID=your_uploadthing_app_id
    JWT_SECRET=your_jwt_secret
    NEXTAUTH_URL=http://localhost:3000
  4. Start the development server

    npm run dev
  5. Access the application Open http://localhost:3000 in your browser

Python Services Setup

For advanced features, set up the Python services:

  1. Contract Extractor Service

    cd contract-extractor
    pip install -r requirements.txt
  2. Contract Search Service

    cd contract-searcher
    pip install -r requirements.txt
  3. Translation Service

    cd translator
    pip install -r requirements.txt

Configuration

Database Setup

The application uses MongoDB for data storage. Ensure your MongoDB instance is running and accessible via the MONGODB_URI environment variable.

API Keys

  • OpenAI API Key: Required for contract analysis and AI features
  • DeepL API Key: Required for translation services
  • UploadThing: Required for secure file uploads

File Upload Limits

  • Maximum file size: 10MB (configurable)
  • Supported formats: PDF, DOCX, DOC
  • Secure file handling with automatic virus scanning

Usage Guide

1. User Registration & Authentication

  • Create an account or log in with existing credentials
  • Secure JWT-based authentication with role management

2. Contract Upload

  • Navigate to the Upload page
  • Drag and drop or select contract files (PDF/DOCX)
  • Files are automatically processed and stored securely

3. Contract Analysis

  • Click "Analyze" on any uploaded contract
  • AI automatically extracts:
    • Contracting parties
    • Key dates (effective, expiration, renewal)
    • Financial terms and payment schedules
    • Governing law and jurisdiction
    • Risk assessment with severity levels
    • Missing standard clauses
    • Contract summary

4. Risk Management

  • View detailed risk analysis in the Risk Sidebar
  • Filter risks by severity (High/Medium/Low)
  • Click on risks to highlight relevant contract sections
  • Get explanations for each identified risk

5. Dashboard Analytics

  • Monitor contract statistics and trends
  • View AI insights and recommendations
  • Track analysis progress and completion rates

6. Contract Search

  • Use semantic search to find contracts by content
  • Search by parties, contract type, or specific terms
  • Leverage AI embeddings for intelligent matching

🔍 API Documentation

Authentication Endpoints

  • POST /api/auth/login - User login
  • POST /api/auth/register - User registration

Contract Management

  • GET /api/contracts - List user contracts
  • POST /api/contracts - Upload new contract
  • GET /api/contracts/[id] - Get contract details
  • POST /api/contracts/[id]/analyze - Analyze contract
  • POST /api/contracts/analyze - Bulk analysis

File Upload

  • POST /api/uploadthing - Secure file upload endpoint

Testing

Frontend Testing

npm run test

Python Services Testing

# Contract Extractor
cd contract-extractor
python -m pytest tests/

# Contract Search
cd contract-searcher
python -m pytest tests/

# Translation Service
cd translator
python -m pytest tests/

Deployment

Production Build

npm run build
npm start

Docker Deployment

A full micro-service stack is provided via docker-compose.yml. It spins up

Service Port Purpose
libretranslate 5000 Lightweight open-source translation engine
translator-api 8000 FastAPI wrapper that first calls DeepL (if configured) then falls back to LibreTranslate
analyzer-api 9000 Knowledge-base & legal reviewer (FastAPI)
contract-extractor-api 9100 GPT-powered structured information extractor
contract-searcher-api 9200 Hybrid MongoDB + semantic search endpoint

All containers share a Docker network so services can call each other by name (e.g. http://translator:8000).

1 Prerequisites

  • Docker 20.10+ and the Compose v2 plugin (docker compose version).
  • A running MongoDB instance (or use an external Atlas cluster).
  • Environment variables in a root-level .env file:
OPENAI_API_KEY=sk-...
MONGODB_URI=mongodb://mongo:27017/contract_db   # or external Atlas URI
PINECONE_API_KEY=your_pinecone_key              # only if you enable analyzer
PINECONE_INDEX_NAME=qatarlaw                    # optional, default as shown
DEEPL_API_KEY=optional_deepl_key                # improves translation quality
UPLOADTHING_SECRET=...
UPLOADTHING_APP_ID=...

2 Build & run

# build the images (first time or when code changes)
docker compose build

# start stack in the background
docker compose up -d

# follow logs (Ctrl+C to stop tailing)
docker compose logs -f

The Next.js frontend still runs outside the Compose stack (port 3000). Point it to the APIs above via environment variables or reverse-proxy.

3 Stopping / cleaning

docker compose stop            # stop containers but keep state
docker compose down            # stop & remove containers

For local experimentation you can comment out services you don’t need in docker-compose.yml (e.g. disable Pinecone-based analyzer).


FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]

Environment Variables for Production

Ensure all required environment variables are set in your production environment:

  • Database connection strings
  • API keys and secrets
  • File upload configurations
  • Authentication settings

Security Features

  • JWT Authentication: Secure token-based authentication
  • Password Hashing: bcryptjs for password security
  • File Upload Security: UploadThing integration with virus scanning
  • Input Validation: Comprehensive input sanitization
  • CORS Protection: Configured for secure cross-origin requests

Performance Optimization

  • Next.js 16: Latest performance optimizations
  • React 19: Improved rendering performance
  • MongoDB Indexing: Optimized database queries
  • Caching: Intelligent caching for API responses
  • Lazy Loading: Component-based code splitting

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the ISC License - see the LICENSE file for details.

Support

For support and questions:

  • Create an issue on GitHub
  • Contact the development team
  • Check the documentation wiki

Roadmap

Upcoming Features

  • Advanced Analytics: More detailed contract analytics and reporting
  • Workflow Automation: Automated contract approval workflows
  • Integration APIs: Third-party system integrations
  • Mobile App: React Native mobile application
  • Advanced AI: Custom trained models for specific contract types
  • Compliance Monitoring: Automated compliance checking
  • Contract Templates: AI-generated contract templates

Version History

  • v1.0.0: Initial release with core contract analysis features
  • v1.1.0: Added translation services and multi-language support
  • v1.2.0: Enhanced risk analysis and missing clause detection
  • v1.3.0: Semantic search and vector-based contract discovery

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages