# adhiraj808/lexdraft-ai architecture

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

- Interactive diagram: https://gitdiagram.com/adhiraj808/lexdraft-ai
- Repository: https://github.com/adhiraj808/lexdraft-ai

## Overview

LegalDraftAI takes a lawyer’s case facts through a React dashboard into authenticated case APIs, stores case records, then preprocesses and extracts entities, classifies the case, retrieves precedents, and generates a draft. Users can review drafts, regenerate sections, and export PDF. The graph includes the documented chat/RAG and Google sign-in capabilities; some route and UI wiring is represented at subsystem level because those files were not excerpted. NLP stage calls and persistence are supported by the pipeline and service excerpts.

Main entry points: [`backend/app/nlp/pipeline.py`](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/pipeline.py) (NLP orchestrator), [`backend/app/services/case_service.py`](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/services/case_service.py) (Case processing service), [`frontend/src/App.jsx`](https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/App.jsx) (React app and pages), [`backend/main.py`](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/main.py) (FastAPI application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web application"]
  node_frontend["React app and pages<br/>[App.jsx]"]
  node_case_ui["Case entry and review<br/>[NewCasePage.jsx]"]
  node_chat_ui["Legal chat workspace<br/>[NewChatPage.jsx]"]
  node_auth_ui["Authentication state<br/>[useAuth.jsx]"]
  node_api_client["HTTP API client<br/>[api.js]"]
end

subgraph group_api["API and services"]
  node_api_server["FastAPI application<br/>[main.py]"]
  node_auth_routes["Auth endpoints<br/>[auth.py]"]
  node_case_routes["Case endpoints<br/>[cases.py]"]
  node_rag_routes["RAG endpoints<br/>[rag.py]"]
  node_auth_service["Authentication logic<br/>[auth_service.py]"]
  node_case_service["Case processing service<br/>[case_service.py]"]
  node_pdf["PDF export<br/>[pdf_generator.py]"]
end

subgraph group_nlp["Legal intelligence"]
  node_pipeline["NLP orchestrator<br/>[pipeline.py]"]
  node_preprocessor["Legal text preprocessing<br/>[preprocessor.py]"]
  node_ner["Entity extraction<br/>[ner.py]"]
  node_classifier["Case classification<br/>[classifier.py]"]
  node_retriever["Precedent retrieval<br/>[retriever.py]"]
  node_generator["Draft generation<br/>[generator.py]"]
end

subgraph group_state["Persistence and identity"]
  node_postgres[("PostgreSQL records<br/>[postgres.py]")]
  node_redis[("Redis cache and progress<br/>[redis_client.py]")]
  node_user_model["User records<br/>[user.py]"]
  node_case_model["Case and draft records<br/>[case.py]"]
end

node_lawyer(("Lawyer"))
node_google["Google identity"]
node_precedents[("Legal knowledge store")]
node_llm["Groq service"]

node_lawyer -->|"uses"| node_frontend
node_frontend -->|"routes to"| node_case_ui
node_frontend -->|"routes to"| node_chat_ui
node_frontend -->|"provides auth"| node_auth_ui
node_case_ui -->|"submits cases"| node_api_client
node_chat_ui -->|"sends requests"| node_api_client
node_auth_ui -->|"calls auth"| node_api_client
node_api_client -.->|"HTTP requests"| node_api_server
node_api_server -->|"registers routes"| node_auth_routes
node_api_server -->|"registers routes"| node_case_routes
node_api_server -->|"registers routes"| node_rag_routes
node_auth_routes -->|"delegates auth"| node_auth_service
node_auth_service -.->|"queries and commits"| node_postgres
node_auth_service -->|"creates users"| node_user_model
node_auth_service -->|"verifies credentials"| node_google
node_case_routes -->|"delegates cases"| node_case_service
node_case_service -->|"processes case"| node_pipeline
node_case_service -.->|"persists results"| node_postgres
node_case_service -->|"stores case and draft"| node_case_model
node_case_service -->|"caches and publishes"| node_redis
node_pipeline -->|"cleans text"| node_preprocessor
node_pipeline -->|"extracts entities"| node_ner
node_pipeline -->|"classifies facts"| node_classifier
node_pipeline -->|"retrieves precedents"| node_retriever
node_pipeline -->|"generates sections"| node_generator
node_retriever -.->|"queries knowledge"| node_precedents
node_generator -.->|"may use"| node_llm
node_case_routes -->|"exports PDF"| node_pdf
node_case_ui -.->|"presents drafts"| node_lawyer

click node_frontend "https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/App.jsx"
click node_case_ui "https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/pages/NewCasePage.jsx"
click node_chat_ui "https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/pages/NewChatPage.jsx"
click node_auth_ui "https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/hooks/useAuth.jsx"
click node_api_client "https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/services/api.js"
click node_api_server "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/main.py"
click node_auth_routes "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/api/routes/auth.py"
click node_case_routes "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/api/routes/cases.py"
click node_rag_routes "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/api/routes/rag.py"
click node_auth_service "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/services/auth_service.py"
click node_case_service "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/services/case_service.py"
click node_pipeline "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/pipeline.py"
click node_preprocessor "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/preprocessor.py"
click node_ner "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/ner.py"
click node_classifier "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/classifier.py"
click node_retriever "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/retriever.py"
click node_generator "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/generator.py"
click node_pdf "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/utils/pdf_generator.py"
click node_postgres "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/db/postgres.py"
click node_redis "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/db/redis_client.py"
click node_user_model "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/models/user.py"
click node_case_model "https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/models/case.py"

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_frontend,node_case_ui,node_chat_ui,node_auth_ui,node_api_client toneBlue
class node_api_server,node_auth_routes,node_case_routes,node_rag_routes,node_auth_service,node_case_service,node_pdf,node_precedents toneAmber
class node_pipeline,node_preprocessor,node_ner,node_classifier,node_retriever,node_generator toneMint
class node_postgres,node_redis,node_user_model,node_case_model toneRose
class node_lawyer,node_google,node_llm toneIndigo
```

## Components

### Web application

- [React app and pages](https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Case entry and review](https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/pages/NewCasePage.jsx): `frontend/src/pages/NewCasePage.jsx`
- [Legal chat workspace](https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/pages/NewChatPage.jsx): `frontend/src/pages/NewChatPage.jsx`
- [Authentication state](https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/hooks/useAuth.jsx): `frontend/src/hooks/useAuth.jsx`
- [HTTP API client](https://github.com/adhiraj808/lexdraft-ai/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### API and services

- [FastAPI application](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/main.py): `backend/main.py`
- [Auth endpoints](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/api/routes/auth.py): `backend/app/api/routes/auth.py`
- [Case endpoints](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/api/routes/cases.py): `backend/app/api/routes/cases.py`
- [RAG endpoints](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/api/routes/rag.py): `backend/app/api/routes/rag.py`
- [Authentication logic](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/services/auth_service.py): `backend/app/services/auth_service.py`
- [Case processing service](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/services/case_service.py): `backend/app/services/case_service.py`
- [PDF export](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/utils/pdf_generator.py): `backend/app/utils/pdf_generator.py`

### Legal intelligence

- [NLP orchestrator](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/pipeline.py): `backend/app/nlp/pipeline.py`
- [Legal text preprocessing](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/preprocessor.py): `backend/app/nlp/preprocessor.py`
- [Entity extraction](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/ner.py): `backend/app/nlp/ner.py`
- [Case classification](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/classifier.py): `backend/app/nlp/classifier.py`
- [Precedent retrieval](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/retriever.py): `backend/app/nlp/retriever.py`
- [Draft generation](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/nlp/generator.py): `backend/app/nlp/generator.py`

### Persistence and identity

- [PostgreSQL records](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/db/postgres.py): `backend/app/db/postgres.py`
- [Redis cache and progress](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/db/redis_client.py): `backend/app/db/redis_client.py`
- [User records](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/models/user.py): `backend/app/models/user.py`
- [Case and draft records](https://github.com/adhiraj808/lexdraft-ai/blob/main/backend/app/models/case.py): `backend/app/models/case.py`

### Other components

- **Lawyer**
- **Google identity**
- **Legal knowledge store**
- **Groq service**

## Connections

- Lawyer → React app and pages: uses (evidence: `frontend/src/App.jsx`)
- React app and pages → Case entry and review: routes to (evidence: `frontend/src/App.jsx`)
- React app and pages → Legal chat workspace: routes to (evidence: `frontend/src/App.jsx`)
- React app and pages → Authentication state: provides auth (evidence: `frontend/src/App.jsx`)
- Case entry and review → HTTP API client: submits cases (evidence: `frontend/src/pages/NewCasePage.jsx`)
- Legal chat workspace → HTTP API client: sends requests (evidence: `frontend/src/pages/NewChatPage.jsx`)
- Authentication state → HTTP API client: calls auth (evidence: `frontend/src/hooks/useAuth.jsx`)
- HTTP API client → FastAPI application: HTTP requests
- FastAPI application → Auth endpoints: registers routes (evidence: `backend/main.py`)
- FastAPI application → Case endpoints: registers routes (evidence: `backend/main.py`)
- FastAPI application → RAG endpoints: registers routes (evidence: `backend/main.py`)
- Auth endpoints → Authentication logic: delegates auth (evidence: `backend/app/api/routes/auth.py`)
- Authentication logic → PostgreSQL records: queries and commits
- Authentication logic → User records: creates users (evidence: `backend/app/services/auth_service.py`)
- Authentication logic → Google identity: verifies credentials (evidence: `backend/app/services/auth_service.py`)
- Case endpoints → Case processing service: delegates cases (evidence: `backend/app/api/routes/cases.py`)
- Case processing service → NLP orchestrator: processes case (evidence: `backend/app/services/case_service.py`)
- Case processing service → PostgreSQL records: persists results
- Case processing service → Case and draft records: stores case and draft (evidence: `backend/app/services/case_service.py`)
- Case processing service → Redis cache and progress: caches and publishes (evidence: `backend/app/services/case_service.py`)
- NLP orchestrator → Legal text preprocessing: cleans text (evidence: `backend/app/nlp/pipeline.py`)
- NLP orchestrator → Entity extraction: extracts entities (evidence: `backend/app/nlp/pipeline.py`)
- NLP orchestrator → Case classification: classifies facts (evidence: `backend/app/nlp/pipeline.py`)
- NLP orchestrator → Precedent retrieval: retrieves precedents (evidence: `backend/app/nlp/pipeline.py`)
- NLP orchestrator → Draft generation: generates sections (evidence: `backend/app/nlp/pipeline.py`)
- Precedent retrieval → Legal knowledge store: queries knowledge
- Draft generation → Groq service: may use
- Case endpoints → PDF export: exports PDF (evidence: `backend/app/api/routes/cases.py`)
- Case entry and review → Lawyer: presents drafts
