# ๐Ÿ’ป SaulGPT Local Development & Setup Guide **Document Version:** 2.2.0 **Target Release:** Production Cloud & Local Workstation This guide walks you through setting up, configuring, and testing the full **SaulGPT** stack on your local development machine. --- ## ๐Ÿ“‹ 1. Prerequisites Before starting, ensure you have the following installed on your machine: - **Python:** 3.10 or 3.11 ([python.org](https://www.python.org/downloads/)) - **Node.js:** 18+ LTS ([nodejs.org](https://nodejs.org/)) - **Git:** Latest version - **A Groq Cloud API Key:** Free tier from [console.groq.com](https://console.groq.com/) --- ## โšก 2. One-Click Quick Start (Windows) For rapid local testing on Windows: 1. **One-Time Setup:** Double-click `scripts\setup.bat` โ€” This will create the Python virtual environment (`.venv`), install all backend dependencies, download the spaCy English NLP model, and run `npm install` in `saulgpt-ui/`. 2. **Run the Application:** Double-click `start.vbs` โ€” It silently launches: - Python FastAPI backend on `http://localhost:8000` - React + Vite development server on `http://localhost:5173` - Automatically opens your default web browser to the app. --- ## ๐Ÿ› ๏ธ 3. Step-by-Step Manual Setup ### 3.1 Backend Configuration ```bash # 1. Clone the repository git clone https://github.com/lbbaalaji0406/legalgpt.git cd legalgpt # 2. Create and activate virtual environment python -m venv .venv # On Windows: .venv\Scripts\activate # On Linux/macOS: source .venv/bin/activate # 3. Install dependencies pip install -r backend/requirements.txt pip install -r requirements.txt # 4. Download spaCy English model python -m spacy download en_core_web_sm ``` ### 3.2 Environment Variables Configuration Create a `.env` file in the project root: ```bash copy .env.example .env ``` Populate the following variables: ```ini # LLM Provider (Groq Cloud) GROQ_API_KEY=gsk_your_groq_api_key_here GROQ_MODEL=llama-3.1-8b-instant # Persistence Mode: # Leave blank to use local SQLite (backend/saulgpt.db) # OR provide a Supabase IPv4 Pooler connection string for cloud sync: DATABASE_URL=postgresql://postgres.[ref]:[password]@aws-0-ap-southeast-1.pooler.supabase.com:5432/postgres # Security & Public URL JWT_SECRET=development-secret-key-replace-in-production PUBLIC_API_URL=http://localhost:8000 ``` ### 3.3 Vector Database Verification Pre-embedded ChromaDB vector collections are included in `data/vector_db/` (~2,449 chunks across 9 acts and landmark precedents). If you need to rebuild the vector database from raw JSON sources: ```bash cd backend python 02_chunk_and_embed.py cd .. ``` ### 3.4 Frontend Setup ```bash cd saulgpt-ui npm install cd .. ``` --- ## ๐Ÿƒ 4. Running the Application ### Terminal 1: Backend API Server ```bash cd backend ..\.venv\Scripts\python.exe -m uvicorn api_server:app --host 0.0.0.0 --port 8000 --reload ``` The FastAPI documentation is available at: `http://localhost:8000/docs` ### Terminal 2: React Frontend UI ```bash cd saulgpt-ui npm run dev ``` The development UI is available at: `http://localhost:5173` --- ## ๐Ÿงช 5. Testing & Evaluation ### 5.1 Automated RAG Pipeline Evaluation Run the automated evaluation suite to benchmark retrieval accuracy, hallucination prevention, and keyword precision across 8 gold-standard test scenarios: ```bash cd backend ..\.venv\Scripts\python.exe eval_pipeline.py ``` ### 5.2 Isolated Agent Endpoint Testing You can test specific subsystems directly using `curl` or Postman: ```bash # 1. Health & Database Check curl http://localhost:8000/api/health # 2. Knowledge Retrieval (Layer 2 + Layer 3) curl "http://localhost:8000/api/test/knowledge?q=What+is+Section+138+of+Negotiable+Instruments+Act" # 3. Advocate Mode IRAC Analysis curl "http://localhost:8000/api/test/analysis?q=Employer+withheld+three+months+salary+without+cause" # 4. Procedural Pathfinder curl "http://localhost:8000/api/test/pathfinder?q=How+do+I+file+an+e-FIR+for+cyber+theft" # 5. Document Drafter Scrutiny Test curl -X POST http://localhost:8000/api/test/scrutiny \ -H "Content-Type: application/json" \ -d '{"doc_type": "cheque_bounce", "date_of_default": "2024-05-10", "notice_date": "2024-05-20"}' ``` --- ## ๐Ÿ“‚ 6. Repository Layout & File Map ``` legalgpt-master/ โ”œโ”€โ”€ ARCH.md # Quick-Reference Architecture & Topology Map โ”œโ”€โ”€ CLAUDE.md # Agent Memory, Conventions & Session Logs โ”œโ”€โ”€ DEPLOYMENT_GUIDE.md # Production Cloud Deployment Guide โ”œโ”€โ”€ README.md # Project Overview & Hugging Face Frontmatter โ”œโ”€โ”€ app.py # ZeroGPU Gradio 5.20 + FastAPI Entrypoint โ”œโ”€โ”€ deploy_hf.py # Automated Hugging Face Space Deployment Script โ”œโ”€โ”€ requirements.txt # Root dependencies for Hugging Face container โ”‚ โ”œโ”€โ”€ backend/ # Python Backend โ”‚ โ”œโ”€โ”€ api_server.py # Core FastAPI application & route dispatcher โ”‚ โ”œโ”€โ”€ pipeline_orchestrator.py# 6-Layer Deterministic RAG controller โ”‚ โ”œโ”€โ”€ actor_critic.py # Actor-Critic Fine-Grained Process Reward Model โ”‚ โ”œโ”€โ”€ interview_state.py # Document drafting state machine & fallback spec โ”‚ โ”œโ”€โ”€ document_generator.py # 4-Family .docx generator (RPAD, Pleadings, Affidavits) โ”‚ โ”œโ”€โ”€ evidence_processor.py # Section 63 BSA Digital Certs & Forensic Processor โ”‚ โ”œโ”€โ”€ layer1_understanding.py # Query understanding, Hindi HyDE, spaCy NER โ”‚ โ”œโ”€โ”€ layer2_retrieval.py # ChromaDB vector retrieval & Cross-Encoder (CPU) โ”‚ โ”œโ”€โ”€ layer3_reasoning.py # Groq LLM synthesis & IRAC reasoning โ”‚ โ”œโ”€โ”€ layer4_validation.py # DeBERTa NLI & SC Struck-Down Firewall โ”‚ โ”œโ”€โ”€ layer5_external.py # IndianKanoon / DuckDuckGo live search fallback โ”‚ โ”œโ”€โ”€ layer6_evaluator.py # 25,000-character contract risk evaluation โ”‚ โ”œโ”€โ”€ layer6_knowledge_graph.py# Relational legal knowledge graph (NetworkX) โ”‚ โ”œโ”€โ”€ database.py # Dual Supabase PostgreSQL + SQLite CRUD engine โ”‚ โ”œโ”€โ”€ auth.py # JWT token generation & bcrypt authentication โ”‚ โ”œโ”€โ”€ discovery_agent.py # Phase 1: 3-turn empathetic investigation โ”‚ โ”œโ”€โ”€ strategy_agent.py # Phase 2: SWOT matrix & 4-path generation โ”‚ โ”œโ”€โ”€ irac_agent.py # Advocate Mode IRAC structured brief generator โ”‚ โ”œโ”€โ”€ scrutiny_agent.py # Pre-draft limitation and validity scrutiny โ”‚ โ”œโ”€โ”€ eval_pipeline.py # Automated RAG benchmarking test harness โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ trial_studio/ # Pre-Trial Studio & Moot Court Subsystem โ”‚ โ”‚ โ”œโ”€โ”€ cross_examiner_agent.py # Hostile Sec 146 BSA cross-examination โ”‚ โ”‚ โ”œโ”€โ”€ defense_fortifier_agent.py# Corner Coach procedural objections โ”‚ โ”‚ โ”œโ”€โ”€ precedent_engine.py # 50,000+ SC/HC landmark judgments index โ”‚ โ”‚ โ””โ”€โ”€ session_manager.py # Moot session persistence โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ agents/ # Specialized Agent Definitions โ”‚ โ”‚ โ”œโ”€โ”€ manager.py # Sub-agent dispatch manager โ”‚ โ”‚ โ”œโ”€โ”€ llm_client.py # Centralized Groq LLM client factory โ”‚ โ”‚ โ”œโ”€โ”€ triage.py # Query classification โ”‚ โ”‚ โ”œโ”€โ”€ researcher.py # Knowledge retrieval agent โ”‚ โ”‚ โ”œโ”€โ”€ drafter.py # Document interview agent โ”‚ โ”‚ โ””โ”€โ”€ reviewer.py # Contract reviewer agent โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ prompts/ # LLM Prompt Templates โ”‚ โ”œโ”€โ”€ triage.py โ”‚ โ”œโ”€โ”€ discovery.py โ”‚ โ”œโ”€โ”€ strategy.py โ”‚ โ””โ”€โ”€ irac.py โ”‚ โ”œโ”€โ”€ saulgpt-ui/ # React 18 + Vite Frontend โ”‚ โ”œโ”€โ”€ src/ โ”‚ โ”‚ โ”œโ”€โ”€ App.jsx # Main Omni-Box interface & state router โ”‚ โ”‚ โ”œโ”€โ”€ AuthPage.jsx # JWT Authentication & guest session takeover โ”‚ โ”‚ โ”œโ”€โ”€ ConversationsSidebar.jsx # Cloud-persisted conversation history โ”‚ โ”‚ โ”œโ”€โ”€ TrialStudio.jsx # Split-Chamber Pre-Trial Moot Court Arena โ”‚ โ”‚ โ”œโ”€โ”€ EvidenceUploader.jsx# Sec 63 BSA drag-and-drop evidence uploader โ”‚ โ”‚ โ”œโ”€โ”€ TriageCards.jsx # Phase 2 SWOT strategic path cards โ”‚ โ”‚ โ”œโ”€โ”€ VetoCard.jsx # Scrutiny blocker & limitation warning โ”‚ โ”‚ โ”œโ”€โ”€ BNSCorrectionNotice.jsx # 2024 Transition notification badge โ”‚ โ”‚ โ”œโ”€โ”€ JurisdictionBadge.jsx # Court pecuniary & territorial indicator โ”‚ โ”‚ โ”œโ”€โ”€ UrgencyBanner.jsx # Statutory limitation countdown banner โ”‚ โ”‚ โ”œโ”€โ”€ ApiKeyModal.jsx # Bring-Your-Own-Key (BYOK) settings modal โ”‚ โ”‚ โ”œโ”€โ”€ LegalGlossary.js # 200+ Indian legal term dictionary โ”‚ โ”‚ โ””โ”€โ”€ usePDF.js # Client-side jsPDF vector rendering engine โ”‚ โ”œโ”€โ”€ package.json โ”‚ โ””โ”€โ”€ vite.config.js โ”‚ โ”œโ”€โ”€ docs/ # Technical & Architectural Documentation โ”‚ โ”œโ”€โ”€ ARCHITECTURE.md # Comprehensive system architecture & data flows โ”‚ โ”œโ”€โ”€ FDD.md # Functional Design Document โ”‚ โ”œโ”€โ”€ TDD.md # Technical Design Document โ”‚ โ”œโ”€โ”€ CHANGELOG_DECISIONS.md # Architectural Decision Records (ADRs 001 - 030) โ”‚ โ”œโ”€โ”€ FEATURES.md # Complete 10-module feature breakdown โ”‚ โ”œโ”€โ”€ API_REFERENCE.md # REST API endpoints & schemas โ”‚ โ””โ”€โ”€ SETUP_GUIDE.md # This setup guide โ”‚ โ”œโ”€โ”€ data/ โ”‚ โ”œโ”€โ”€ raw_data/ # JSON statutory texts (BNS, BNSS, BSA, CPC, NIA, etc.) โ”‚ โ””โ”€โ”€ vector_db/ # Pre-embedded ChromaDB vector indexes โ”‚ โ””โ”€โ”€ scripts/ โ”œโ”€โ”€ setup.bat # Windows automated setup script โ””โ”€โ”€ start.bat # Windows startup batch script ```