# raiyashu2004/juris architecture

> Architecture diagram of the GitHub repository raiyashu2004/juris, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raiyashu2004/juris
- Repository: https://github.com/raiyashu2004/juris

## Overview

1. **System shape**
   JurisAI is a two-tier application: a React/Vite single-page frontend and a FastAPI backend. The frontend owns the user experience and lightweight client state; the backend owns legal AI orchestration, retrieval, and security-sensitive API calls.

2. **Frontend boundary**
   The frontend lives under `frontend/src` and is organized by screens such as Chat, Legal Research, Case Finder, Document Analyzer, Draft Generator, My Documents, Saved Research, and Settings. This suggests a single SPA that routes between legal workflows rather than multiple separate apps.

3. **Client state and persistence**
   The README indicates chat history is kept in browser storage for persistent conversational sessions. That means the frontend is not just rendering results; it also preserves user interaction state locally to avoid server-side session dependency.

4. **Backend API surface**
   `backend/main.py` is the FastAPI entrypoint, with route modules split by domain: `auth`, `chat`, `documents`, and `cases`. This is a clean API boundary where each legal workflow is exposed through its own router instead of a single monolithic endpoint set.

5. **AI orchestration layer**
   The core AI work is isolated in `backend/services/`: `llm.py` for model access, `embeddings.py` for vectorization, `rag.py` for retrieval-augmented generation, and `langchain_chat.py` for conversational memory/chain behavior. This indicates the backend acts as an LLM orchestration proxy rather than embedding AI logic in route handlers.

6. **Legal document pipeline**
   `document_analyser.py` is the dedicated service for uploaded document review, summarization, and risk flagging. The document flow likely enters through the documents router, is processed in this service layer, and returns structured AI feedback to the frontend.

7. **Legal knowledge retrieval**
   The `data/` scripts (`ingest_constitution.py`, `ingest_judgments.py`) show an offline ingestion pipeline for Indian legal sources. These scripts appear to prepare the corpus that feeds embeddings and RAG, so the app’s answers are grounded in constitutional text and case law rather than general-purpose chat.

8. **Auth and security boundary**
   Authentication is separated into `backend/routers/auth.py` and `backend/utils/auth.py`, with a mirrored frontend auth context in `frontend/src/context/AuthContext.jsx`. This suggests a dedicated identity boundary around login/session handling, distinct from the AI and document features.

9. **Persistence and shared utilities**
   `backend/models/db_models.py`, `backend/utils/database.py`, and `backend/utils/config.py` indicate shared backend infrastructure for config and any persisted records. The README notes the deployment is designed to work without requiring a provisioned PostgreSQL database, so persistence is intentionally lightweight and deployment-friendly.

10. **External services and runtime**
    The key external dependency is Google Gemini, accessed from the backend using an API key. The frontend points to the backend via `VITE_BACKEND_URL`, and the repo is set up for Vercel-hosted frontend plus Render-hosted backend, with `docker-compose.yml` and `render.yaml` capturing deployment wiring.

11. **Build and delivery**
    The frontend is built with Vite into `frontend/dist`, which is what gets served in production. The backend runs as a Python ASGI service under Uvicorn/FastAPI. This separation makes the UI deployable as static assets while keeping AI and retrieval logic server-side.

12. **Useful diagram takeaway**
    A good architecture diagram should show: user → React SPA → FastAPI routers → AI/services layer → Gemini + legal corpus. Separately, show offline ingestion feeding the corpus, and local browser storage supporting persistent chat history on the client.

Main entry points: [`backend/main.py`](https://github.com/raiyashu2004/juris/blob/main/backend/main.py) (FastAPI app), [`frontend/src/App.jsx`](https://github.com/raiyashu2004/juris/blob/main/frontend/src/App.jsx) (React SPA), [`backend/services/rag.py`](https://github.com/raiyashu2004/juris/blob/main/backend/services/rag.py) (RAG engine), [`backend/routers/auth.py`](https://github.com/raiyashu2004/juris/blob/main/backend/routers/auth.py) (Auth API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_spa["React SPA<br/>ui shell<br/>[App.jsx]"]
  node_routes["Legal pages<br/>screen set"]
  node_authctx["Auth state<br/>client auth<br/>[AuthContext.jsx]"]
  node_browserstore[("Browser storage<br/>local persistence")]
end

subgraph group_backend["Backend"]
  node_backendapi["FastAPI app<br/>api entry<br/>[main.py]"]
  node_authrouter["Auth API<br/>router<br/>[auth.py]"]
  node_chatrouter["Chat API<br/>router<br/>[chat.py]"]
  node_docrouter["Documents API<br/>router<br/>[documents.py]"]
  node_casesrouter["Cases API<br/>router<br/>[cases.py]"]
  node_llm["LLM access<br/>model client<br/>[llm.py]"]
  node_rag["RAG engine<br/>retrieval service<br/>[rag.py]"]
  node_embeddings["Embeddings<br/>vectorization<br/>[embeddings.py]"]
  node_chatsvc["Chat chains<br/>conversation service<br/>[langchain_chat.py]"]
  node_docsvc["Doc analyzer<br/>analysis service"]
  node_authutil["Auth utils<br/>security helper<br/>[auth.py]"]
  node_config["Config<br/>settings<br/>[config.py]"]
  node_database[("Database<br/>persistence<br/>[database.py]")]
  node_models["DB models<br/>schema models<br/>[db_models.py]"]
end

subgraph group_data["Data"]
  node_corpus[("Legal corpus<br/>document store")]
  node_ingest["Ingestion scripts<br/>offline pipeline"]
end

subgraph group_deploy["Delivery"]
  node_build["Frontend build<br/>static bundle"]
  node_runtime["Deploy config<br/>deployment<br/>[docker-compose.yml]"]
end

node_user(("User<br/>actor"))

node_user -->|"uses"| node_spa
node_spa -->|"navigates"| node_routes
node_spa -->|"auth state"| node_authctx
node_spa -->|"persists chat"| node_browserstore
node_routes -->|"calls"| node_backendapi
node_backendapi -->|"mounts"| node_authrouter
node_backendapi -->|"mounts"| node_chatrouter
node_backendapi -->|"mounts"| node_docrouter
node_backendapi -->|"mounts"| node_casesrouter
node_authrouter -->|"uses"| node_authutil
node_authrouter -->|"reads/writes"| node_database
node_chatrouter -->|"delegates"| node_chatsvc
node_chatrouter -->|"retrieves"| node_rag
node_docrouter -->|"delegates"| node_docsvc
node_casesrouter -->|"searches"| node_rag
node_rag -->|"vectorizes"| node_embeddings
node_rag -->|"generates"| node_llm
node_chatsvc -->|"chains"| node_llm
node_docsvc -->|"analyzes"| node_llm
node_rag -->|"queries"| node_corpus
node_ingest -->|"builds"| node_corpus
node_backendapi -->|"configures"| node_config
node_backendapi -->|"uses"| node_models
node_runtime -->|"runs"| node_backendapi
node_build -->|"serves"| node_spa

click node_spa "https://github.com/raiyashu2004/juris/blob/main/frontend/src/App.jsx"
click node_routes "https://github.com/raiyashu2004/juris/tree/main/frontend/src/pages"
click node_authctx "https://github.com/raiyashu2004/juris/blob/main/frontend/src/context/AuthContext.jsx"
click node_backendapi "https://github.com/raiyashu2004/juris/blob/main/backend/main.py"
click node_authrouter "https://github.com/raiyashu2004/juris/blob/main/backend/routers/auth.py"
click node_chatrouter "https://github.com/raiyashu2004/juris/blob/main/backend/routers/chat.py"
click node_docrouter "https://github.com/raiyashu2004/juris/blob/main/backend/routers/documents.py"
click node_casesrouter "https://github.com/raiyashu2004/juris/blob/main/backend/routers/cases.py"
click node_llm "https://github.com/raiyashu2004/juris/blob/main/backend/services/llm.py"
click node_rag "https://github.com/raiyashu2004/juris/blob/main/backend/services/rag.py"
click node_embeddings "https://github.com/raiyashu2004/juris/blob/main/backend/services/embeddings.py"
click node_chatsvc "https://github.com/raiyashu2004/juris/blob/main/backend/services/langchain_chat.py"
click node_docsvc "https://github.com/raiyashu2004/juris/blob/main/backend/services/document_analyser.py"
click node_authutil "https://github.com/raiyashu2004/juris/blob/main/backend/utils/auth.py"
click node_config "https://github.com/raiyashu2004/juris/blob/main/backend/utils/config.py"
click node_database "https://github.com/raiyashu2004/juris/blob/main/backend/utils/database.py"
click node_models "https://github.com/raiyashu2004/juris/blob/main/backend/models/db_models.py"
click node_ingest "https://github.com/raiyashu2004/juris/tree/main/data"
click node_build "https://github.com/raiyashu2004/juris/tree/main/frontend/dist"
click node_runtime "https://github.com/raiyashu2004/juris/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spa,node_routes,node_authctx,node_browserstore toneBlue
class node_backendapi,node_authrouter,node_chatrouter,node_docrouter,node_casesrouter,node_llm,node_rag,node_embeddings,node_chatsvc,node_docsvc,node_authutil,node_config,node_database,node_models toneAmber
class node_corpus,node_ingest toneMint
class node_build,node_runtime toneRose
class node_user toneNeutral
```

## Components

### Frontend

React/Vite single-page app and local UI state

- [React SPA](https://github.com/raiyashu2004/juris/blob/main/frontend/src/App.jsx): ui shell · Single-page frontend that routes between legal workflows · `frontend/src/App.jsx`
- [Legal pages](https://github.com/raiyashu2004/juris/tree/main/frontend/src/pages): screen set · Chat, research, case finder, analyzer, draft, documents, saved research, settings · `frontend/src/pages`
- [Auth state](https://github.com/raiyashu2004/juris/blob/main/frontend/src/context/AuthContext.jsx): client auth · Frontend authentication context and session handling · `frontend/src/context/AuthContext.jsx`
- **Browser storage**: local persistence · Client-side storage for chat history and lightweight session state

### Backend

FastAPI API, orchestration, and persistence boundary

- [FastAPI app](https://github.com/raiyashu2004/juris/blob/main/backend/main.py): api entry · Backend entrypoint mounting the domain routers · `backend/main.py`
- [Auth API](https://github.com/raiyashu2004/juris/blob/main/backend/routers/auth.py): router · Login, registration, and session-related endpoints · `backend/routers/auth.py`
- [Chat API](https://github.com/raiyashu2004/juris/blob/main/backend/routers/chat.py): router · Conversational legal assistant endpoints · `backend/routers/chat.py`
- [Documents API](https://github.com/raiyashu2004/juris/blob/main/backend/routers/documents.py): router · Upload and document workflow endpoints · `backend/routers/documents.py`
- [Cases API](https://github.com/raiyashu2004/juris/blob/main/backend/routers/cases.py): router · Case search and finder endpoints · `backend/routers/cases.py`
- [LLM access](https://github.com/raiyashu2004/juris/blob/main/backend/services/llm.py): model client · Direct access to Gemini or other hosted model APIs · `backend/services/llm.py`
- [RAG engine](https://github.com/raiyashu2004/juris/blob/main/backend/services/rag.py): retrieval service · Retrieval-augmented generation over legal sources · `backend/services/rag.py`
- [Embeddings](https://github.com/raiyashu2004/juris/blob/main/backend/services/embeddings.py): vectorization · Text embedding generation for search and retrieval · `backend/services/embeddings.py`
- [Chat chains](https://github.com/raiyashu2004/juris/blob/main/backend/services/langchain_chat.py): conversation service · Conversational memory and chain behavior · `backend/services/langchain_chat.py`
- [Doc analyzer](https://github.com/raiyashu2004/juris/blob/main/backend/services/document_analyser.py): analysis service · Document review, summarization, and risk flagging · `backend/services/document_analyser.py`
- [Auth utils](https://github.com/raiyashu2004/juris/blob/main/backend/utils/auth.py): security helper · Backend authentication helpers and token/session logic · `backend/utils/auth.py`
- [Config](https://github.com/raiyashu2004/juris/blob/main/backend/utils/config.py): settings · Shared backend configuration and environment access · `backend/utils/config.py`
- [Database](https://github.com/raiyashu2004/juris/blob/main/backend/utils/database.py): persistence · Backend database utilities and shared persistence layer · `backend/utils/database.py`
- [DB models](https://github.com/raiyashu2004/juris/blob/main/backend/models/db_models.py): schema models · Data models for persisted records · `backend/models/db_models.py`

### Data

Offline legal corpus ingestion scripts

- **Legal corpus**: document store · Ingested constitutional text and judgments used for retrieval
- [Ingestion scripts](https://github.com/raiyashu2004/juris/tree/main/data): offline pipeline · Scripts that prepare constitutional and judgment sources · `data`

### Delivery

Build and deployment wiring

- [Frontend build](https://github.com/raiyashu2004/juris/tree/main/frontend/dist): static bundle · Vite production output served as static assets · `frontend/dist`
- [Deploy config](https://github.com/raiyashu2004/juris/blob/main/docker-compose.yml): deployment · Docker and Render wiring for frontend/backend delivery · `docker-compose.yml`

### Other components

- **User**: actor · Lawyer or end user interacting with the app

## Connections

- User → React SPA: uses · User interacts with the web app
- React SPA → Legal pages: navigates · SPA switches between legal workflows
- React SPA → Auth state: auth state · Frontend keeps login state in context
- React SPA → Browser storage: persists chat · Chat history is kept locally in the browser
- Legal pages → FastAPI app: calls · Screens invoke backend APIs
- FastAPI app → Auth API: mounts · Main app exposes auth routes
- FastAPI app → Chat API: mounts · Main app exposes chat routes
- FastAPI app → Documents API: mounts · Main app exposes document routes
- FastAPI app → Cases API: mounts · Main app exposes case routes
- Auth API → Auth utils: uses · Authentication helpers protect the API
- Auth API → Database: reads/writes · Auth state may be persisted
- Chat API → Chat chains: delegates · Chat endpoints use conversation services
- Chat API → RAG engine: retrieves · Chat answers are grounded with RAG when needed
- Documents API → Doc analyzer: delegates · Document upload flow is analyzed by service layer
- Cases API → RAG engine: searches · Case workflows rely on retrieval
- RAG engine → Embeddings: vectorizes · Retrieval depends on embedding generation
- RAG engine → LLM access: generates · Retrieved context is turned into answers by the model client
- Chat chains → LLM access: chains · Conversation logic calls the model client
- Doc analyzer → LLM access: analyzes · Document analysis uses hosted LLMs
- RAG engine → Legal corpus: queries · Retrieval searches the ingested legal corpus
- Ingestion scripts → Legal corpus: builds · Offline scripts prepare the corpus used at runtime
- FastAPI app → Config: configures · Runtime settings and API keys come from shared config
- FastAPI app → DB models: uses · API and services share persistence models
- Deploy config → FastAPI app: runs · Deployment launches the ASGI backend
- Frontend build → React SPA: serves · Production frontend is the built static bundle
