A full-stack LegalTech application that combines Large Language Models (LLMs), Retrieval-Augmented Generation (RAG), multi-agent orchestration, and LLM fine-tuning to automate contract analysis, risk detection, and negotiation support.
- 📄 Multi-format document ingestion — PDF, DOCX, TXT, CSV, Markdown, JSON and JSONL
- 🔍 RAG-based contract analysis using LangChain and ChromaDB
- 🤖 Multi-agent analysis with four specialized agents
⚠️ Legal risk and penalty detection- 📊 Structured extraction of contractual obligations
- 🔄 Contract comparison against standard/reference contracts
- 💡 Negotiation recommendations
- 🧠 Dynamic model selection for base and fine-tuned models
- 🎯 Integrated fine-tuning pipeline using Kaggle, LoRA and Unsloth
- ☁️ Cloud inference with Groq
- 🔒 Local/offline inference with Ollama
- 🗄️ Object storage with MinIO
- 🐘 PostgreSQL for application data and metadata
- 🐳 Containerized microservices architecture with Docker Compose
LexAnalyzer follows a microservices architecture that separates the web interface, backend API, AI processing, database, and document storage.
User
|
v
Frontend / Nginx
|
v
Go Backend (REST API)
|
+----> PostgreSQL
|
+----> MinIO
|
+----> Python / FastAPI RAG Service
|
+----> ChromaDB
|
+----> Groq / Ollama
|
+----> 4 Specialized Agents
The main components are deployed as independent Docker services and communicate through the Docker network.
One of the main features of LexAnalyzer is its multi-format document ingestion pipeline.
The Knowledge Base supports the following document and data formats:
.pdf— Legal contracts and documents.docx— Word documents.txt— Plain-text documents.csv— Structured datasets.md— Markdown documents.json— Structured data and training datasets.jsonl— Training and structured datasets
Uploaded documents are processed and incorporated into the RAG pipeline, allowing the system to retrieve relevant information and enrich the context provided to the LLMs during contract analysis.
The ingestion pipeline was designed to support heterogeneous document sources rather than limiting the system to a single document format.
The Knowledge Base also integrates with the fine-tuning workflow, allowing .json and .jsonl datasets to be used for model training.
The Contract Analysis interface includes a dynamic model selector that displays the models currently available in the system:
- Base Models — Foundation models ready for immediate use, such as Llama 3.
- Fine-tuned Models — Models trained through the integrated Training module and registered in the application once training is completed successfully.
This allows users to switch between base and specialized models directly from the interface.
LexAnalyzer supports two inference modes:
Groq — Cloud inference
- Fast cloud-based LLM inference.
- No specialized local hardware required.
- Configured as the default provider.
Ollama — Local inference
- Enables local and offline model execution.
- Useful when keeping inference entirely on the local environment.
- Requires a locally downloaded model, for example:
ollama pull llama3.2The provider can be selected through the environment configuration:
LLM_PROVIDER=ollamaLexAnalyzer uses MinIO, an S3-compatible object storage service, to store the original documents uploaded to the system.
The Go backend handles document uploads and bucket management, while the Python RAG service retrieves the required document content during the analysis pipeline.
MinIO exposes:
- API: http://localhost:9000
- Web Console: http://localhost:9001
LexAnalyzer includes an integrated fine-tuning workflow that can be launched directly from the web interface.
The workflow is:
- Upload a dataset in .json or .jsonl format through the Knowledge Base.
- Select a base model and dataset.
- Launch a fine-tuning job from the Training interface.
- Connect to Kaggle automatically through the Kaggle API.
- Run the training process using GPU acceleration and parameter-efficient techniques such as LoRA and Unsloth.
- Register the trained model in LexAnalyzer once training is complete.
- Use the fine-tuned model through the dynamic model selector for subsequent contract analysis.
This creates an end-to-end workflow from dataset ingestion and model training to model registration and inference.
LexAnalyzer uses several storage components with different responsibilities:
| Service | Purpose |
|---|---|
| PostgreSQL | Stores application data and metadata |
| ChromaDB | Stores vector embeddings for RAG |
| MinIO | Stores uploaded documents and files |
AI & LLM
- Python
- LangChain
- FastAPI
- ChromaDB
- Groq
- Ollama
- LoRA
- Unsloth
- Kaggle API
Backend
- Go
- REST API
- PostgreSQL
- MinIO
Frontend & Infrastructure
- HTML
- JavaScript
- CSS
- Nginx
- Docker
- Docker Compose
Make sure you have:
- Docker
- Docker Compose
- A Groq API key if using Groq as the LLM provider
- Kaggle credentials if using the fine-tuning functionality
Create a .env file in the project root.
For Groq:
GROQ_API_KEY=your_api_key_here
LLM_PROVIDER=groqFor the fine-tuning functionality, configure the required Kaggle credentials:
KAGGLE_USERNAME=your_kaggle_username
KAGGLE_KEY=your_kaggle_api_keyBuild and launch the complete environment with:
docker-compose up --buildThe first startup may take several minutes while dependencies and embedding models are downloaded.
Once the services are running, open: http://localhost:3000
| Service | Port | Description |
|---|---|---|
| Frontend | 3000 |
Web interface served by Nginx |
| Backend API | 8080 |
REST API developed in Go |
| RAG Service | 8001 |
Python/FastAPI AI service |
| PostgreSQL | 5432 |
Application database |
| MinIO API | 9000 |
S3-compatible object storage API |
| MinIO Console | 9001 |
MinIO web interface |
If you encounter errors such as Failed to load or Cannot connect to backend:
- Make sure all Docker services have started successfully.
- Check the Docker logs for the RAG service.
- Verify that the application is accessed through port
3000.
When using Ollama without dedicated GPU hardware, processing large contracts may take significantly longer.
For faster inference, use Groq:
LLM_PROVIDER=groqProduction deployment
The project also includes a docker-compose.prod.yml configuration intended for cloud/server deployments, including Oracle Cloud infrastructure.
LexAnalyzer/
├── backend/
│ └── services/
│ └── ... # RAG, agents and embeddings
├── frontend/ # Web interface
├── chroma_db/ # Persistent vector database
├── data/ # Example datasets
└── docker-compose.yml # Service orchestration
MIT License