Skip to content

krisjosh7/ParaDocs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ParaDocs — Electron + React (Vite) + FastAPI

Minimal desktop demo: Electron wraps a Vite dev server UI and spawns a local FastAPI (uvicorn) process. The React UI talks to the backend over HTTP.

Architecture

Piece Role
Electron (main process) Desktop shell; starts uvicorn from backend/; waits for GET /health; opens a window loading the React dev URL; stops uvicorn on quit.
React (renderer) UI in the Electron window; fetch to http://127.0.0.1:8000 (health + echo).
FastAPI Local HTTP API on 127.0.0.1:8000; mock JSON only. CORS allows all origins for local dev.

RAG Storage Layer (Backend)

The backend now includes a deterministic RAG data layer with endpoints:

  • POST /store: body is Document without doc_id (case_id, raw_text, source, optional timestamp); generates doc_id, parses, ingests.
  • POST /parse: body is full Document (includes doc_id, ISO timestamp); returns StructuredDocument (nested summary, jurisdiction, source_span on facts).
  • POST /ingest: body is { "document": Document, "structured": StructuredDocument }; returns { "num_chunks", "doc_id" }.
  • POST /query: body is QueryInput (case_id, query, top_k, optional filters.type); returns QueryResult (query, chunks with chunk_id + metadata, structured_hits with doc_id, sources).

Local model prerequisites

Run Ollama and pull a chat model used for extraction, for example:

ollama pull llama3.1:8b

Sentence-transformers embeddings are loaded automatically by Python from Hugging Face.

Prerequisites

  • Node.js and npm
  • Python 3 with pip

Setup

  1. Python dependencies (virtualenv recommended):

    cd backend
    python -m venv .venv

    Activate the environment, then install:

    • macOS / Linux (folder name can be .venv or venv):

      source .venv/bin/activate
      pip install -r requirements.txt
    • Windows (cmd):

      .venv\Scripts\activate
      pip install -r requirements.txt

    On Windows, if python is not on PATH, use py -3 instead, or set PYTHON when running Electron (see below).

  2. Node dependencies:

    npm install
    npm install --prefix frontend

Run (one command)

From the repo root:

npm run dev

This runs:

  1. Vite dev server for the React app (http://127.0.0.1:5173).
  2. Electron after the dev server is reachable; Electron spawns uvicorn and polls http://127.0.0.1:8000/health before opening the window.

Use Ping Backend and Echo in the UI to hit the API.

Environment

  • PYTHON: Optional. Path or command for the Python executable used to run uvicorn (overrides py -3 on Windows and python elsewhere).
  • CASES_ROOT: Optional base directory for case files (default: backend/cases).
  • GROQ_API_KEY: Required for legal-structure parsing on RAG ingest. Without it, Discovery uploads still save to the context library, but cases/{case_id}/structured/{doc_id}.json is not written and the UI may show an indexing error on the card.
  • CHROMA_PERSIST_DIR: Optional Chroma persistence directory (default: backend/chroma).
  • OLLAMA_MODEL: Ollama extraction model (default: llama3.1:8b).
  • EMBED_MODEL: sentence-transformers embedding model (default: all-MiniLM-L6-v2).

Manual backend (optional)

With the venv activated (see Setup):

cd backend
source .venv/bin/activate   # macOS/Linux — Windows: .venv\Scripts\activate
uvicorn main:app --host 127.0.0.1 --port 8000

RAG endpoint quick test

curl -X POST http://127.0.0.1:8000/store \
  -H "Content-Type: application/json" \
  -d '{
    "case_id":"case-123",
    "raw_text":"John Doe sued Acme Corp after a collision on Jan 2, 2024.",
    "source":"upload"
  }'
curl -X POST http://127.0.0.1:8000/query \
  -H "Content-Type: application/json" \
  -d '{"case_id":"case-123","query":"What happened and who are the parties?","top_k":5,"filters":{"type":null}}'

filters.type can be null, or "raw", "summary", "event", or "claim" to restrict vector hits.

Backend unit tests

With the venv activated (see Setup):

cd backend
source .venv/bin/activate   # macOS/Linux — or: source venv/bin/activate
pip install -r requirements.txt   # once, if not already installed
python -m pytest tests/ -v

Tests use a temporary Chroma directory and cases root (CHROMA_PERSIST_DIR, CASES_ROOT) and mock embed_texts so they run without downloading embedding models. /store is tested with parse_legal_structure mocked so Ollama is not required.

  • Integration (RAG path, no Ollama): python -m pytest tests/ -m integration -q
  • Live Ollama (optional, needs Ollama on 127.0.0.1:11434): python -m pytest tests/ -m ollama -q

Coverage (app modules under backend/, excludes tests/; config in backend/pyproject.toml):

cd backend
source .venv/bin/activate
python -m pytest tests/ -q --cov=. --cov-report=term-missing

Local coverage data files (backend/.coverage, etc.) are gitignored.

Project layout

electron/main.js   # Electron entry
frontend/          # Vite + React
backend/main.py    # FastAPI app
backend/tests/     # pytest — conftest.py + rag/, upload/, parser/, …

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors