ClauseIQ is an advanced, AI-powered document analysis and contract intelligence platform. It leverages Retrieval-Augmented Generation (RAG), semantic vector search, and hybrid heuristic fallbacks to automatically analyze legal documents, extract clauses, generate compliance checklists, identify risks, and compare document versions with blazing speed and minimal API costs.
- Intelligent Document Processing: Upload PDFs to automatically parse, chunk, and semantically index the content using FAISS and Google Generative AI embeddings.
-
Deep Legal Insights:
- Summarization: Generates structured executive summaries and extracts key obligations.
- Compliance Checklists: Automatically evaluates documents against standard business requirements (e.g., NDA, Indemnification).
- Risk Analysis: Flags High, Medium, and Low risks with citations back to the source text.
- Clause Explorer: Browse all extracted clauses of a contract grouped, identified, and mapped back to their source page numbers using an overlap matching heuristic.
-
Document Versioning & Comparison Engine: Upload a newer version of a contract to run a
rapidfuzz-powered differential analysis. The system intelligently highlights added, removed, unchanged, and modified clauses, using Gemini only to analyze the semantic compliance impact of modifications. -
Context-Aware RAG Chat (Multi-Stage Retrieval Pipeline): Ask questions about your document and get answers cited directly to the exact page and section. Instead of a basic single-pass vector search, ClauseIQ implements a production-grade multi-stage pipeline:
-
Candidate Expansion: Queries FAISS for
top_k * 2candidates to maximize recall. -
Metadata Scoping: Restricts vectors strictly to the active
document_idto prevent cross-document leakage. -
Hybrid Reranking: Re-scores chunks using a weighted combination of semantic similarity (
$0.7$ ) and Jaccard token overlap ($0.3$ ) to prioritize exact keyword matches (e.g. key figures, dates, negations). - Context Synthesis: Feeds the top 5 reranked results to Gemini for generation.
-
Candidate Expansion: Queries FAISS for
- Workspace Portfolio Dashboard: A centralized, multi-tenant workspace overview showing key performance indicators (total uploads, comparisons, chats, analyses), a recent activity audit feed, and quick-access documents.
- Version History Switcher: Seamless document lineage exploration. Switch between uploaded versions of a document family via a topological dropdown list directly on the document details workspace.
- Cascading Document Deletion: Safe, multi-stage document purging. Safely deletes physical files, database records (chunks, snapshots, logs), and executes offline FAISS index rebuilding.
- Premium Glassmorphism UI: Responsive dashboard design utilizing a modern glassmorphism aesthetic built using React, GSAP, Anime.js, and Framer Motion.
-
Cost Optimization & Offline Resilience:
- Persistent Caching: Responses are snapshotted in SQLite; repeated analysis costs $0 and runs instantly.
- Graceful Fallbacks: If the Gemini API rate limit is exceeded, the system automatically falls back to offline Regex parsing and heuristic rules so you are never left blocked.
- Multi-Format Export Engine: Instantly export comprehensive analysis reports to PDF, DOCX, or JSON.
- Observability Dashboard: Real-time metrics UI tracking API usage, cache hits, misses, and overall cost savings.
- Challenge: Vector databases can return semantically similar chunks from unrelated documents.
- Solution: Implemented metadata-scoped retrieval using
document_idfiltering during FAISS candidate selection to guarantee that chat responses only use chunks belonging to the active document.
- Challenge: Gemini rate limits and service outages can make AI-powered systems unusable.
- Solution: Built a multi-layer fallback architecture that replaces AI functionality with local heuristic processing for summaries, compliance analysis, risk detection, and clause extraction.
- Challenge: Embedding similarity often misses legally significant changes involving numbers, dates, or negations.
- Solution: Implemented a RapidFuzz-powered comparison engine with semantic impact analysis triggered only for modified clauses, reducing API costs while improving precision.
- Challenge: Deleting a document requires removing its vectors from the FAISS index. Doing this online via AI re-embedding is slow and expensive.
- Solution: Built an offline vector reconstruction engine. It retrieves all existing vectors from the flat index using
reconstruct(i), filters out chunks matching the deleteddocument_id, and rebuilds the flat L2 index (faiss.IndexFlatL2) using raw NumPy array manipulation, completely avoiding external AI API calls.
ClauseIQ follows a highly decoupled, abstraction-centric architecture designed for multi-tenant data isolation, database independence, and storage engine independence:
graph TD;
Client[React Frontend] -->|JWT Auth Header| API[FastAPI Router / get_current_user]
subgraph "Authentication & Authorization"
API -->|JWT Validation| AuthContext[Auth Service]
end
subgraph "Routing & Isolated Services"
API -->|tenant context: user_id| Services[Business Services]
Services --> AIService[AI Gateway]
Services --> DeletionService[Deletion Service]
Services --> ActivityService[Activity Service]
end
subgraph "Abstraction Interfaces"
Services -->|IStorageProvider| Storage[LocalStorageProvider]
Services -->|IVectorStore + user_id| Vectors[FAISSVectorStore]
Services -->|DB Repositories + user_id| Repos[SQL Repositories]
end
subgraph "Physical Data Layer (Tenant Partitioned)"
Storage --> Disk[(Local disk / uploads/)]
Vectors -->|Zero-API Offline Reconstruction| FAISSIndex["faiss_index.bin"]
Repos --> SQLiteDB[(SQLite / test.db)]
end
subgraph "External"
AIService <-->|GenAI API / Rate Limited| Gemini[Google Gemini 2.5]
end
%% Fallback Logic
AIService -.->|Quota Exceeded| Fallbacks[Offline Heuristics & Regex]
To support secure SaaS operations, ClauseIQ implements strict tenant isolation at every level of the request lifecycle:
-
Authentication & Route Protection:
- Every business route is protected via FastAPI's dependency injection (
Depends(get_current_user)). - JWT access and refresh tokens secure API endpoints. User identity is validated, generating a scoped tenant context (
user_id).
- Every business route is protected via FastAPI's dependency injection (
-
Database Scoping (SQLite):
- High-level schema tables (
Document,Chunk,Clause,AnalysisSnapshot,Metrics,ActivityLog) are mapped with auser_idforeign key. - Repositories (repositories/) strictly query data filtering by the caller's
user_id. Any attempt to retrieve or mutate records of another user results in a403 Forbiddenresponse.
- High-level schema tables (
-
Secure Vector Store Isolation (FAISS):
- To prevent cross-tenant vector index leakage, the in-memory
FAISSVectorStorefilters matching results post-query. - It enforces that retrieved document chunks must match both the active
document_idand the request owner'suser_id.
- To prevent cross-tenant vector index leakage, the in-memory
-
Activity & Audit Logging:
- Every major tenant operation (document uploads, summary generation, checklist runs, chat queries, exports, and version comparisons) creates an audit trail entry in the
ActivityLogdatabase table.
- Every major tenant operation (document uploads, summary generation, checklist runs, chat queries, exports, and version comparisons) creates an audit trail entry in the
-
Dynamic Schema Migration (SQLite):
- On startup, the backend automatically inspects the SQLite database. If an outdated single-tenant schema is detected (e.g. missing
user_idcolumn), it automatically wipes the database and resets FAISS index files to maintain environment integrity.
- On startup, the backend automatically inspects the SQLite database. If an outdated single-tenant schema is detected (e.g. missing
Frontend:
- React 18 + Vite
- Vanilla CSS (Glassmorphism UI)
- GSAP (UI entry animations)
- Anime.js (Particle transitions)
- Framer Motion (Layout transitions)
- Axios for API communication
Backend:
- Python 3.12 + FastAPI
- SQLAlchemy + SQLite (Decoupled via Repository Pattern & Interfaces)
- FAISS (Decoupled via IVectorStore Interface)
- Disk File Storage (Decoupled via IStorageProvider Interface)
google-genai(Official Google Generative AI SDK)rapidfuzz(Blazing fast string matching for version diffs)python-docx&reportlab(Export Generation)
- Node.js (v18+)
- Python (3.10+)
- A Google Gemini API Key
git clone https://github.com/yourusername/clauseiq.git
cd clauseiqNavigate to the backend directory and install the dependencies:
cd backend
pip install -r requirements.txtCreate a .env file in the backend/ directory by copying .env.example:
# Google Gemini API Key
GEMINI_API_KEY=your_gemini_api_key_here
# JWT Configuration
JWT_SECRET_KEY=replace_this_with_a_long_random_secret_key
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60
# Database
DATABASE_URL=sqlite:///./test.dbNavigate to the frontend directory and install dependencies:
cd ../frontend
npm installYou need two terminal windows to run both the backend and frontend simultaneously.
Terminal 1: Start the Backend (FastAPI)
cd backend
uvicorn app.main:app --reloadThe backend will be available at http://localhost:8000
Terminal 2: Start the Frontend (Vite)
cd frontend
npm run devThe frontend will be available at http://localhost:5173
clauseiq/
βββ backend/
β βββ app/
β β βββ api/routes/ # FastAPI Route Controllers (chat, documents, dashboard, activity, metrics, export, etc.)
β β βββ core/ # Configuration and Exception handling
β β βββ db/ # SQLite Session configurations
β β βββ models/ # SQLAlchemy schemas (Document, Chunk, Clause, AnalysisSnapshot, Metrics, ActivityLog)
β β βββ repositories/ # Abstraction Layer (Document, Chunk, Clause, Snapshot, Metrics, Dashboard, ActivityLog Repositories)
β β βββ schemas/ # Pydantic validation schemas
β β βββ services/ # Core Business Logic (AI, RAG, Comparison, Exports, Dashboard, Deletion, Activity)
β β βββ storage/ # File Storage Provider Abstraction (LocalStorageProvider & IStorageProvider)
β β βββ vector_store/ # Vector Database Abstraction (FAISSVectorStore & IVectorStore)
β βββ exports/ # Generated PDF and DOCX reports
β βββ test.db # Local SQLite Database
β βββ uploads/ # Local PDF Storage Storage Directory
βββ frontend/
βββ src/
βββ components/ # React Components (layout/, views/, ui/)
β βββ layout/ # Persistent App Shell (Sidebar, DashboardLayout)
β βββ views/ # Routed workspaces (WorkspaceDashboard, MyDocuments, DocumentDetails, UploadScreen, AnalyticsPage, ProfilePage, ChatView)
β βββ ui/ # Reusable UI tokens (Button, Tabs, etc.)
βββ App.jsx # Main Application Container & Route Transitions
βββ index.css # Global Design Tokens & Theme Variables
βββ main.jsx # Application React mount entrypoint
βββ styles/ # Application resets & layout styles
This project is proprietary and built for enterprise deployment. All rights reserved.