AdvocateAI is an AI-assisted legal marketplace prototype that helps people understand a legal issue, review documents, prepare a case, and connect with relevant lawyers in one flow.
The current build is focused on making the first steps of legal help easier: understanding the problem, organizing the case, and starting communication between clients and lawyers.
- AI chat to understand a legal problem in plain language
- AI case analysis with a simple summary, urgency signals, and next-step guidance
- document upload and analysis for PDFs and images
- document batch storage with follow-up question answering over uploaded files
- structured extraction for parties, deadlines, amounts, obligations, and risks
- LangChain-backed prompting with LlamaIndex retrieval for document QA
- legal action guidance for supported common situations
- lawyer recommendations based on the case details
- case creation, case tracking, and case workspace collaboration
- client-lawyer messaging inside the case workspace
- notifications for messages, applications, and recommendations
- separate client and lawyer experiences
- optional MLOps instrumentation for AI runs via Hydra-backed config, MLflow, and Weights & Biases
- optional one-time LoRA/QLoRA fine-tuning script for running adapter training on a GPU server
Backend & APIs: FastAPI, Python, Uvicorn
RAG & Retrieval: LangChain, LlamaIndex, semantic chunking, retrieval-augmented generation
Vector Storage: FAISS (local similarity search), Qdrant (production vector retrieval), PostgreSQL with pgvector (hybrid relational + vector storage)
LLM Frameworks: HuggingFace Transformers, OpenAI API
Fine-Tuning: Optional LoRA/QLoRA adapter training via backend/train_lora.py
MLOps: MLflow experiment tracking, Weights & Biases, Hydra config management
Frontend: Flutter (Dart), Chrome target
Infrastructure: Docker, Git, Linux
The AI pipeline follows a RAG (Retrieval-Augmented Generation) flow:
- User uploads a legal document (PDF or image)
- Document is chunked and converted into vector embeddings
- Embeddings are stored in a vector store (FAISS locally, Qdrant in production, pgvector for hybrid queries)
- On user query, relevant chunks are retrieved via semantic similarity search
- Retrieved context is passed to an LLM (OpenAI API or HuggingFace model) with a structured prompt via LangChain/LlamaIndex
- LLM returns a structured response: case summary, extracted entities, urgency signals, and next-step guidance
- Optional: LoRA/QLoRA fine-tuning adapters can be trained and wired into the serving path for domain-specific legal language
- sign up and log in
- describe a legal problem and get AI guidance
- upload one or more legal documents for analysis
- receive a case summary and intake-readiness insights
- ask follow-up questions against the uploaded document batch
- view suggested lawyers for their issue
- create and manage cases
- keep a lawyer watchlist
- chat with lawyers inside a case workspace
- follow case updates, key dates, and timeline activity
- sign up and manage a lawyer profile
- set availability and maintain profile details
- browse open cases
- view recommended cases
- apply to client cases
- review case details before responding
- message clients in the shared workspace
- track activity through dashboard and notifications
- the current dataset is centered on Germany-based lawyers and legal flows
- the app already supports an end-to-end prototype experience for discovery, case intake, and lawyer connection
- uploaded document batches are stored for later Q&A and retrieval-based follow-up
- some areas are still early-stage, including payments and long-term production storage workflows
cd backend
python -m venv venv
venv\Scripts\activate
pip install -r ..\requirements.txt
uvicorn app:app --reload --host 0.0.0.0 --port 8000Create a .env file inside backend/ with the required database and API key settings.
Once the backend is running, you can verify service and database readiness at http://localhost:8000/health. The root / route still returns a lightweight OK response.
Optional MLOps settings:
MLOPS_ENABLED=true|falseMLFLOW_ENABLED=true|falseMLFLOW_TRACKING_URIfor a local or remote MLflow serverMLFLOW_EXPERIMENT_NAMEWANDB_ENABLED=true|falseWANDB_PROJECTWANDB_ENTITYWANDB_MODEsuch asofflineordisabled
The default backend config lives in backend/conf/mlops.yaml. Tracking is local and non-invasive unless you enable the environment flags above.
AdvocateAI now includes a standalone adapter-training script for a one-time GPU run. It is separate from the production backend path, so the app will still use its normal inference flow unless you wire the saved adapter into serving.
Install the extra training dependencies on the GPU server:
pip install -r requirements-lora.txtRun the training script from the repository root:
python backend/train_lora.py --dataset path/to/training_data.jsonl --output-dir artifacts/lora_adapter --use-qloraThe dataset can be JSON or JSONL and should contain one of these shapes per record:
messageswith chat-style{role, content}entriespromptandresponseinstruction, optionalinput, andoutput- plain
text
The script saves the adapter under artifacts/lora_adapter/adapter and writes a training manifest with the exact settings used. If you want to make the claim that LoRA/QLoRA fine-tuning was done, run this script and keep the saved artifacts or manifest as evidence.
cd test_app
flutter pub get
flutter run -d chromeThis repository includes a Docker-based production stack:
frontend: Flutter web served by Nginx, with/apiproxied to the backendbackend: FastAPI served by Uvicorndb: PostgreSQL 16redis: Redis for cache and rate limiting
Create a production env file from the committed example:
cp .env.example .env.productionFill in the real values, especially DB_PASSWORD, GOOGLE_API_KEY, GEMINI_API_KEY, PUBLIC_APP_URL, PUBLIC_API_BASE_URL, and CORS_ALLOWED_ORIGINS.
Run the stack on the server:
docker compose --env-file .env.production -f docker-compose.prod.yml up -d --buildView service status:
docker compose --env-file .env.production -f docker-compose.prod.yml psThe GitHub Actions pipeline in .github/workflows/deploy.yml runs backend tests, validates the Docker Compose config, syncs the repository to the DigitalOcean droplet, writes .env.production from GitHub Secrets, and starts the Docker stack.
Required GitHub Secrets:
DO_HOSTDO_SSH_KEYDB_PASSWORDGOOGLE_API_KEYGEMINI_API_KEYPUBLIC_APP_URLPUBLIC_API_BASE_URLCORS_ALLOWED_ORIGINS
Optional GitHub Secrets:
DO_USERdefaults torootDO_DEPLOY_PATHdefaults to/root/AdvocateAIDB_NAMEdefaults toadvocateaiDB_USERdefaults toadvocateaiCORS_ALLOW_ORIGIN_REGEXLOG_LEVELGEMINI_MODELGEMINI_DEFAULT_TIMEOUTGEMINI_ANALYSIS_TIMEOUTGEMINI_BRIEF_TIMEOUTGEMINI_CHAT_TIMEOUTGEMINI_DOCUMENT_TIMEOUTMLOPS_ENABLEDMLOPS_LOG_PROMPTSMLFLOW_ENABLEDMLFLOW_TRACKING_URIMLFLOW_EXPERIMENT_NAMEWANDB_ENABLEDWANDB_PROJECTWANDB_ENTITYWANDB_MODE
- Username:
demo_client - Password:
demo123
- Username:
demo_lawyer - Password:
demo123
AdvocateAI is currently a working prototype for an AI-assisted legal help and lawyer-matching platform.





