Upload any legal contract. Get instant AI-powered risk analysis, clause-by-clause review, obligation tracking, and expiry alerts β all in real-time.
| Feature | Description |
|---|---|
| π Contract Upload | Upload PDF, DOCX, or plain text contracts |
| π€ AI Analysis | Risk scoring, clause flagging, obligation extraction via OpenRouter LLM |
| β‘ Real-Time Updates | WebSocket notifications when analysis completes |
| π Version Comparison | AI-powered diff between contract versions |
| π Expiry Alerts | Automated email + socket alerts before contract expiry |
| π’ Multi-Tenant | Organization-based isolation with RBAC (admin/manager/viewer) |
| π Quota Management | Redis-based monthly analysis limits per subscription tier |
| π Enterprise Security | JWT rotation, token blacklist, rate limiting, input validation |
| Category | Technology |
|---|---|
| Runtime | Node.js β₯ 20 (ES Modules) |
| Framework | Express.js 4.19 |
| Database | MongoDB 8 + Mongoose ODM |
| Cache & Pub/Sub | Redis (ioredis) |
| Message Queue | RabbitMQ (amqplib) |
| Real-Time | Socket.io with Redis adapter |
| AI Engine | OpenRouter API (Llama 3.1, Mistral 7B) |
| Auth | JWT (access + refresh tokens) with bcrypt |
| Validation | Joi + Zod |
| Nodemailer (SMTP) | |
| File Parsing | pdf-parse, mammoth (DOCX) |
| Logging | Winston + Morgan |
| Security | Helmet, CORS, express-mongo-sanitize, rate limiting |
| Scheduling | node-cron |
LexAI/
βββ server.js # API entry point (HTTP + Socket.io + cron)
βββ worker.js # Background worker (RabbitMQ consumers)
βββ package.json # Dependencies & scripts
βββ scripts/seed.js # First admin user seed script
β
βββ src/
βββ app.js # Express middleware & route setup
βββ config/ # DB, Redis, RabbitMQ, Socket.io, env validation
βββ constants/ # HTTP codes, plans, queues, roles
βββ models/ # 7 Mongoose models
βββ services/ # 13 business logic services
βββ controllers/ # 7 HTTP request handlers
βββ middleware/ # 7 middleware (auth, RBAC, validation, rate limit)
βββ validators/ # 4 Joi schema files
βββ routes/ # 8 Express routers
βββ utils/ # 8 shared utilities
βββ sockets/ # Socket.io event bridge
βββ workers/ # RabbitMQ consumers (analysis + alerts)
βββ jobs/ # Cron jobs (daily expiry scan)
π For a detailed explanation of every file and how data flows through the system, see PROJECT_GUIDE.md.
Create a .env file in the project root:
# App
NODE_ENV=development
PORT=3000
API_VERSION=v1
# MongoDB
MONGO_URI=mongodb://localhost:27017/lexai
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
# RabbitMQ
RABBITMQ_URL=amqp://guest:guest@localhost:5672
ANALYSIS_QUEUE=lexai.analysis.queue
ALERT_QUEUE=lexai.alert.queue
DLX_EXCHANGE=lexai.dlx
# JWT (use strong, random 32+ character strings)
JWT_ACCESS_SECRET=your-access-secret-at-least-32-chars-long
JWT_REFRESH_SECRET=your-refresh-secret-at-least-32-chars-long
JWT_ACCESS_EXPIRY=15m
JWT_REFRESH_EXPIRY=7d
# OpenRouter AI
OPENROUTER_API_KEY=sk-or-v1-your-key
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
AI_PRIMARY_MODEL=meta-llama/llama-3.1-8b-instruct:free
AI_FALLBACK_MODEL=mistralai/mistral-7b-instruct:free
# Rate Limiting
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX=100
# File Upload
MAX_FILE_SIZE_MB=5
ALLOWED_MIME_TYPES=application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,text/plain
# CORS
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173
# Email (Ethereal for testing)
SMTP_HOST=smtp.ethereal.email
SMTP_PORT=587
SMTP_USER=
SMTP_PASS=
EMAIL_FROM=noreply@lexai.io
# External APIs
REST_COUNTRIES_URL=https://restcountries.com/v3.1
WORLD_TIME_API_URL=https://worldtimeapi.org/api- Node.js β₯ 20
- MongoDB (local or Atlas)
- Redis (local or cloud)
- RabbitMQ (local or CloudAMQP)
git clone https://github.com/YOUR_USERNAME/LexAI.git
cd LexAI
npm installIf you have Docker:
docker-compose up -d # Starts MongoDB, Redis, RabbitMQcp .env.example .env # Copy and fill in your valuesnpm run seednpm run dev # Development with auto-reload
# or
npm start # ProductionIn a separate terminal:
npm run dev:worker # Development
# or
npm run start:worker # Productioncurl http://localhost:3000/health| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/v1/auth/register |
β | Register new user |
POST |
/api/v1/auth/verify-email |
β | Verify email token |
POST |
/api/v1/auth/login |
β | Login, get tokens |
POST |
/api/v1/auth/refresh-token |
πͺ | Refresh access token |
POST |
/api/v1/auth/logout |
β | Blacklist current token |
POST |
/api/v1/auth/forgot-password |
β | Request password reset |
POST |
/api/v1/auth/reset-password |
β | Reset with token |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
GET |
/api/v1/users/me |
β | Get my profile + quota |
PATCH |
/api/v1/users/me |
β | Update my name |
PATCH |
/api/v1/users/me/password |
β | Change password |
GET |
/api/v1/users/:id |
π Admin | Get user by ID |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/v1/orgs |
β | Create organization |
GET |
/api/v1/orgs/:orgId |
β | Get org details |
PATCH |
/api/v1/orgs/:orgId |
π Admin/Mgr | Update org |
POST |
/api/v1/orgs/:orgId/invite |
π Admin/Mgr | Invite member |
POST |
/api/v1/orgs/:orgId/invite/accept |
β | Accept invite |
PATCH |
/api/v1/orgs/:orgId/members/:userId/role |
π Admin | Change role |
DELETE |
/api/v1/orgs/:orgId/members/:userId |
π Admin | Remove member |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/v1/contracts |
β | Upload contract (file/text) |
GET |
/api/v1/contracts |
β | List with pagination/filter |
GET |
/api/v1/contracts/:id |
β | Get full contract |
PATCH |
/api/v1/contracts/:id |
β | Update metadata |
DELETE |
/api/v1/contracts/:id |
π Admin/Mgr | Soft delete |
POST |
/api/v1/contracts/:id/versions |
β | Upload new version |
GET |
/api/v1/contracts/:id/versions |
β | Version history |
POST |
/api/v1/contracts/:id/compare |
β | Compare versions (AI) |
GET |
/api/v1/contracts/:id/audit |
β | Audit trail |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/v1/analyses |
β | Request AI analysis |
GET |
/api/v1/analyses/:id |
β | Get analysis result |
GET |
/api/v1/analyses/contract/:contractId |
β | All analyses for contract |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
GET |
/api/v1/admin/stats |
π Admin | Platform statistics |
GET |
/api/v1/admin/queue/status |
π Admin | RabbitMQ queue status |
GET |
/api/v1/admin/users |
π Admin | List all users |
GET |
/api/v1/admin/audit-logs |
π Admin | Global audit logs |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
GET |
/health |
β | Service health check |
π For complete request/response examples with dummy data, see POSTMAN_COLLECTION.md.
π Full ER diagram with all fields and data types is in PROJECT_GUIDE.md.
Quick overview of model relationships:
User ββbelongs toβββΆ Organization
Organization ββhas manyβββΆ Contract, Invitation, AuditLog, Notification
Contract ββhas manyβββΆ Analysis, Version (embedded), Party (embedded)
Analysis ββcontainsβββΆ Clause (embedded)
LexAI is deployment-ready for Render.com (free tier supported).
π Full step-by-step deployment guide with GitHub setup, service configuration, env vars, and common error fixes: DEPLOYMENT.md.
Live URL format after deployment:
https://lexai-api.onrender.com/health
https://lexai-api.onrender.com/api/v1/auth/login
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'feat: add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
Use Conventional Commits:
| Prefix | Usage |
|---|---|
feat: |
New feature |
fix: |
Bug fix |
docs: |
Documentation only |
refactor: |
Code change, no feature/bug fix |
test: |
Adding/updating tests |
chore: |
Maintenance tasks |
This project is licensed under the ISC License. See LICENSE for details.
Built with β€οΈ by the LexAI Team