NyayaMitra is a legal-assistant project with:
- Backend: FastAPI + RAG (ChromaDB)
- Frontend: React + Vite
This guide helps other developers run the project locally after cloning from GitHub.
- Python
3.11+(tested with3.12) - Node.js
18+and npm - macOS/Linux shell commands below (Windows users can adapt to PowerShell)
git clone <your-repo-url>
cd nyayamitraCreate and activate a Python virtual environment, then install dependencies:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtCreate your .env file from the example:
cp .env.example .envThen edit .env and add at least one provider key (recommended: GROQ_API_KEY or GEMINI_API_KEY).
If no key is set, the app can still run in context-only mode.
This repo can include a refined prebuilt chroma_db/ so new users can run quickly.
No ingestion step needed. Just run backend + frontend.
From project root:
rm -rf chroma_db
source .venv/bin/activate
python scripts/prepare_rag_chunks.py --include-qa --include-criminal-primer --include-legal-vector-10k
python scripts/ingest_chroma.pyThis recreates the local vector store in chroma_db/.
User accounts are stored in legal_advisor.db at the project root (nyayamitra/legal_advisor.db), not inside backend/. Open it with DB Browser for SQLite or run python scripts/inspect_users_db.py — the file is binary, so the IDE text view will not show rows. See DATABASE_URL and JWT_SECRET in .env.
- Sign up / log in in the UI before Chat or Action plan.
- API:
POST /api/auth/signup,POST /api/auth/login,GET /api/auth/me(Bearer token). - Protected routes:
/api/ask,/api/chat,/api/planrequireAuthorization: Bearer <token>.
On Render, set a strong JWT_SECRET; SQLite data is ephemeral on free tier unless you add persistent disk.
From project root:
source .venv/bin/activate
uvicorn backend.main:app --reload --host 127.0.0.1 --port 8000Backend URLs:
- API base:
http://127.0.0.1:8000 - Health:
http://127.0.0.1:8000/health
Open a second terminal:
cd frontend
npm install
npm run devFrontend URL:
http://localhost:5173
Vite is already configured to proxy /api and /health to backend 127.0.0.1:8000.
source .venv/bin/activate
python scripts/smoke_api.pyThese files are project data and should be committed so others (and hosts like Render) have everything they need:
ai_legal_phase4_diverse.jsonlegal_vector_dataset_10k.jsondata/raw/*.jsonl(constitution + QA + criminal primer shards forprepare_rag_chunks.py)data/chunks/rag_chunks.jsonl(optional but speeds rebuilds; otherwise regenerate with the script)chroma_db/(refined vector DB; includes Chroma’s*.sqlite3files —.gitignoreis set so those are not excluded)
You can add and commit them with:
git add README.md ai_legal_phase4_diverse.json legal_vector_dataset_10k.json data/raw chroma_db
# optional (skip if you will regenerate chunks on the server):
git add data/chunks/rag_chunks.jsonl
git commit -m "Add setup README and include required datasets and chroma DB"
git pushDeploy the FastAPI backend on Render and the Vite React frontend on Vercel. The UI calls the API using VITE_API_BASE_URL (see frontend/src/api.js); locally that variable is unset so /api and /health still go through the Vite dev proxy.
- Push this repo to GitHub (include
chroma_db/if you want RAG without running ingest on the server; see note above). - In Render: New → Blueprint (connect the repo and select
render.yaml) or Web Service with:- Root directory: repository root (where
requirements.txtlives). - Build command:
pip install -r requirements.txt - Start command:
uvicorn backend.main:app --host 0.0.0.0 --port $PORT - Python version:
3.11+(this repo includes runtime.txt for Render’s native Python runtime).
- Root directory: repository root (where
- Environment variables on the service (minimum for a working UI against prod API):
CORS_ORIGINS— comma-separated list including your Vercel production URL (e.g.https://your-app.vercel.app). Addhttp://localhost:5173if you want a local frontend to talk to the hosted API.GROQ_API_KEY/GEMINI_API_KEY/OPENAI_API_KEY— optional; without them the API stays in context-only mode (see .env.example).
- After deploy, copy the service URL (e.g.
https://nyayamitra-api.onrender.com). Checkhttps://<that-host>/healthin a browser.
Blueprint reference: render.yaml (secret keys use sync: false so Render prompts you when applying the blueprint).
Free tier: Services may spin down after idle time (cold starts). Chroma + sentence-transformers are memory-heavy; if the service crashes on startup, try a paid instance with more RAM or a smaller index.
- New Project → import the same GitHub repo.
- Set Root Directory to
frontend(Vite app; vercel.json sets build/output). - Under Environment Variables, add
VITE_API_BASE_URL= your Render URL without a trailing slash (e.g.https://nyayamitra-api.onrender.com). Redeploy after changing it. - Deploy. Open the Vercel URL; the header should load
/healthfrom Render and show chunk count whenchroma_dbis present on the server.
See frontend/.env.example for a short reminder.
GET https://<render-host>/healthreturns JSON withokandchroma_documents.- Vercel app loads without CORS errors in the browser console; chat or plan returns a response.
- Backend not starting: check you used
--host 127.0.0.1 --port 8000(host and port order matters). - Frontend shows proxy errors: backend is not running on
127.0.0.1:8000. - Missing API keys: add provider keys in
.envor use context-only mode. - Production CORS errors: set
CORS_ORIGINSon Render to your exact Vercelhttps://…origin (comma-separated if multiple). - Production UI cannot reach API: set
VITE_API_BASE_URLon Vercel to the Render URL and redeploy the frontend.