How devantaris/ai-legal-document-intelligence-system works
LegalIQ is a multi-user legal-document analysis application. Users authenticate, upload contracts, and follow their ingestion status; once processing finishes, they can ask cited questions, inspect summaries, key terms and classified clauses, or compare two documents. The backend extracts page-aware text, chunks and embeds it, then stores it for retrieval and analysis. The README documents PostgreSQL/pgvector and local file storage, plus Z.ai and Ollama providers. Relationships for unsampled analysis services and storage are shown only where the README or source index supports them.
Main entry points: __init__.py Provider selection · router.py API router · database.py PostgreSQL and pgvector · App.tsx App routing
Components 31
Web application
- App routing
frontend/src/App.tsx - Auth state
frontend/src/stores/auth.ts - API client
frontend/src/lib/api.ts - Document dashboard
frontend/src/pages/DashboardPage.tsx - Document workspace
frontend/src/pages/DocumentPage.tsx - Analysis panels
frontend/src/components/SummaryPanel.tsx - Chat panel
frontend/src/components/ChatPanel.tsx - Compare page
frontend/src/pages/ComparePage.tsx
API and access
- FastAPI application
backend/app/main.py - API router
backend/app/api/router.py - Authentication routes
backend/app/api/auth.py - Document routes
backend/app/api/documents.py - Chat routes
backend/app/api/chat.py - Analysis routes
backend/app/api/analysis.py - Comparison routes
backend/app/api/compare.py
Document intelligence
- Ingestion orchestrator
backend/app/services/ingestion.py - Text extraction
backend/app/services/extraction.py - Structure-aware chunking
backend/app/services/chunking.py - Hybrid retrieval
backend/app/services/retrieval.py - RAG chat
backend/app/services/chat.py - Summarization
backend/app/services/summarization.py - Key-term extraction
backend/app/services/key_terms.py - Clause classification
backend/app/services/clauses.py - Clause comparison
backend/app/services/compare.py
Persistence and models
- PostgreSQL and pgvector
backend/app/core/database.py - Domain models
backend/app/models - Uploaded files
LLM providers
- Provider selection
backend/app/services/llm/__init__.py - Z.ai provider
backend/app/services/llm/zai.py - Ollama provider
backend/app/services/llm/ollama.py
Other components
- User
Connections 43
- User → App routing: uses
- App routing → Auth state: checks session
frontend/src/App.tsx - App routing → Document dashboard: routes to
frontend/src/App.tsx - App routing → Document workspace: routes to
frontend/src/App.tsx - App routing → Compare page: routes to
frontend/src/App.tsx - Auth state → API client: requests auth
frontend/src/stores/auth.ts - Document dashboard → API client: requests documents
frontend/src/pages/DashboardPage.tsx - Document workspace → Analysis panels: renders
frontend/src/pages/DocumentPage.tsx - Document workspace → Chat panel: renders
frontend/src/pages/DocumentPage.tsx - Document workspace → API client: requests analysis
frontend/src/pages/DocumentPage.tsx - Compare page → API client: requests comparison
frontend/src/pages/ComparePage.tsx - API client → FastAPI application: sends HTTP and SSE
- FastAPI application → API router: mounts routes
backend/app/main.py - API router → Authentication routes: registers
backend/app/api/router.py - API router → Document routes: registers
backend/app/api/router.py - API router → Chat routes: registers
backend/app/api/router.py - API router → Analysis routes: registers
backend/app/api/router.py - API router → Comparison routes: registers
backend/app/api/router.py - Document routes → Ingestion orchestrator: starts processing
backend/app/api/documents.py - Document routes → Uploaded files: stores upload
- Ingestion orchestrator → Text extraction: extracts pages
backend/app/services/ingestion.py - Ingestion orchestrator → Structure-aware chunking: builds chunks
backend/app/services/ingestion.py - Ingestion orchestrator → Provider selection: embeds chunks
backend/app/services/ingestion.py - Ingestion orchestrator → PostgreSQL and pgvector: writes chunks and status
backend/app/services/ingestion.py - Document routes → PostgreSQL and pgvector: persists document
backend/app/api/documents.py - Chat routes → RAG chat: delegates chat
backend/app/api/chat.py - RAG chat → Hybrid retrieval: retrieves context
- Hybrid retrieval → PostgreSQL and pgvector: searches chunks
- Hybrid retrieval → Provider selection: embeds query
backend/app/services/retrieval.py - RAG chat → Provider selection: generates answer
- Analysis routes → Summarization: requests summary
backend/app/api/analysis.py - Analysis routes → Key-term extraction: extracts terms
backend/app/api/analysis.py - Analysis routes → Clause classification: lists clauses
backend/app/api/analysis.py - Comparison routes → Clause comparison: compares documents
backend/app/api/compare.py - Summarization → Provider selection: uses LLM
- Key-term extraction → Provider selection: uses LLM
- Clause classification → Provider selection: uses LLM
- Clause comparison → Provider selection: uses LLM
- Analysis routes → PostgreSQL and pgvector: reads and stores results
backend/app/api/analysis.py - Comparison routes → PostgreSQL and pgvector: reads clauses
backend/app/api/compare.py - PostgreSQL and pgvector → Domain models: maps domain records
backend/app/models/__init__.py - Provider selection → Z.ai provider: selects by config
backend/app/services/llm/__init__.py - Provider selection → Ollama provider: selects by config
backend/app/services/llm/__init__.py