# ashba2801/chatlaw architecture

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

- Interactive diagram: https://gitdiagram.com/ashba2801/chatlaw
- Repository: https://github.com/ashba2801/chatlaw

## Overview

ChatLaw is a multilingual legal-information and workflow platform. A browser user asks a grounded legal question, optionally using voice or case context; the web application proxies requests to the FastAPI RAG engine, which retrieves legal material and generates cited answers. Separate workflows support guided document drafting and private case workspaces, while deterministic case intelligence helps users identify forums and nearby advocates. The repository also includes a PDF-to-legal-corpus ingestion path. The README documents the cross-service architecture; source excerpts establish selected route, persistence, retrieval, and ingestion links, but not every runtime connection.

Main entry points: [`web/app/(product)/layout.tsx`](https://github.com/ashba2801/chatlaw/blob/main/web/app/(product)/layout.tsx) (Web application), [`rag-engine/api/routes/chat.py`](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/api/routes/chat.py) (Chat endpoint), [`web/app/api/rag/[...path]/route.ts`](https://github.com/ashba2801/chatlaw/blob/main/web/app/api/rag/%5B...path%5D/route.ts) (RAG proxy), [`web/components/cases/CaseDetail.tsx`](https://github.com/ashba2801/chatlaw/blob/main/web/components/cases/CaseDetail.tsx) (Case workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_webapp["Web application<br/>[layout.tsx]"]
  node_chatui["Legal chat<br/>[ChatInterface.tsx]"]
  node_voiceui["Voice chat<br/>[useVoiceChat.ts]"]
  node_researchui["Research workspace"]
  node_caseui["Case workspace<br/>[CaseDetail.tsx]"]
  node_docui["Document editor<br/>[DocumentEditor.tsx]"]
end

subgraph group_api["API and workflows"]
  node_webproxy["RAG proxy<br/>[route.ts]"]
  node_caseapi["Case API<br/>[route.ts]"]
  node_caseintel["Case intelligence<br/>[route.ts]"]
  node_docapi["Document API<br/>[route.ts]"]
  node_ragapi["FastAPI routes<br/>[main.py]"]
  node_chatroute["Chat endpoint<br/>[chat.py]"]
  node_searchroute["Search endpoint<br/>[search.py]"]
  node_conversation["Conversation service"]
  node_directory["Court and advocate directory<br/>[providers.ts]"]
end

subgraph group_rag["Legal RAG"]
  node_casequery["Case query analysis"]
  node_retrieval["Vector retrieval<br/>[vector_search.py]"]
  node_answer["Answer generation<br/>[answer.py]"]
  node_drafting["Document drafting"]
  node_templates["Legal templates<br/>[templates.py]"]
  node_casefinder["Case-law retrieval<br/>[retrieval.py]"]
end

subgraph group_corpus["Legal corpus"]
  node_pdfparser["PDF legal parser<br/>[pdf_parser.py]"]
  node_ingestmodels["Ingestion models<br/>[models.py]"]
  node_embeddingingest["Embedding ingestion<br/>[ingestion.py]"]
  node_legaldb[("Postgres and pgvector<br/>[vector-search.ts]")]
end

node_citizen(("Browser user"))

node_citizen -->|"uses"| node_webapp
node_webapp -->|"presents"| node_chatui
node_webapp -->|"presents"| node_researchui
node_webapp -->|"presents"| node_caseui
node_webapp -->|"presents"| node_docui
node_chatui -.->|"requests answers"| node_webproxy
node_voiceui -.->|"sends chat"| node_webproxy
node_researchui -.->|"requests research"| node_webproxy
node_webproxy -->|"proxies requests"| node_ragapi
node_caseui -.->|"manages cases"| node_caseapi
node_caseui -.->|"requests classification"| node_caseintel
node_docui -.->|"manages drafts"| node_docapi
node_caseintel -.->|"uses providers"| node_directory
node_ragapi -->|"registers"| node_chatroute
node_ragapi -->|"registers"| node_searchroute
node_chatroute -.->|"retrieves context"| node_retrieval
node_chatroute -.->|"generates answer"| node_answer
node_chatroute -->|"handles draft turns"| node_drafting
node_chatroute -->|"reads history"| node_conversation
node_searchroute -->|"searches"| node_retrieval
node_retrieval -->|"queries vectors"| node_legaldb
node_drafting -.->|"uses templates"| node_templates
node_casequery -->|"informs retrieval"| node_casefinder
node_pdfparser -->|"builds structured data"| node_ingestmodels
node_pdfparser -.->|"supplies corpus chunks"| node_embeddingingest
node_embeddingingest -.->|"stores embeddings"| node_legaldb

click node_webapp "https://github.com/ashba2801/chatlaw/blob/main/web/app/(product)/layout.tsx"
click node_chatui "https://github.com/ashba2801/chatlaw/blob/main/web/components/chat/ChatInterface.tsx"
click node_voiceui "https://github.com/ashba2801/chatlaw/blob/main/web/lib/speech/useVoiceChat.ts"
click node_researchui "https://github.com/ashba2801/chatlaw/blob/main/web/components/research/ResearchWorkspace.tsx"
click node_caseui "https://github.com/ashba2801/chatlaw/blob/main/web/components/cases/CaseDetail.tsx"
click node_docui "https://github.com/ashba2801/chatlaw/blob/main/web/components/documents/DocumentEditor.tsx"
click node_webproxy "https://github.com/ashba2801/chatlaw/blob/main/web/app/api/rag/%5B...path%5D/route.ts"
click node_caseapi "https://github.com/ashba2801/chatlaw/blob/main/web/app/api/cases/%5Bid%5D/route.ts"
click node_caseintel "https://github.com/ashba2801/chatlaw/blob/main/web/app/api/case-intelligence/route.ts"
click node_docapi "https://github.com/ashba2801/chatlaw/blob/main/web/app/api/documents/route.ts"
click node_ragapi "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/api/main.py"
click node_chatroute "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/api/routes/chat.py"
click node_searchroute "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/api/routes/search.py"
click node_conversation "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/api/conversation_service.py"
click node_casequery "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/cases/query_understanding.py"
click node_retrieval "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/retrieval/vector_search.py"
click node_answer "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/generation/answer.py"
click node_drafting "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/conversation/document_drafting.py"
click node_templates "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/documents/templates.py"
click node_casefinder "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/cases/retrieval.py"
click node_pdfparser "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/ingestion/parsers/pdf_parser.py"
click node_ingestmodels "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/ingestion/models.py"
click node_embeddingingest "https://github.com/ashba2801/chatlaw/blob/main/rag-engine/embeddings/ingestion.py"
click node_legaldb "https://github.com/ashba2801/chatlaw/blob/main/database/lib/vector-search.ts"
click node_directory "https://github.com/ashba2801/chatlaw/blob/main/web/lib/case-intelligence/providers.ts"

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_webapp,node_chatui,node_voiceui,node_researchui,node_caseui,node_docui,node_citizen toneBlue
class node_webproxy,node_caseapi,node_caseintel,node_docapi,node_ragapi,node_chatroute,node_searchroute,node_conversation,node_directory toneAmber
class node_casequery,node_retrieval,node_answer,node_drafting,node_templates,node_casefinder toneMint
class node_pdfparser,node_ingestmodels,node_embeddingingest,node_legaldb toneRose
```

## Components

### Web experience

- [Web application](https://github.com/ashba2801/chatlaw/blob/main/web/app/(product)/layout.tsx): `web/app/(product)/layout.tsx`
- [Legal chat](https://github.com/ashba2801/chatlaw/blob/main/web/components/chat/ChatInterface.tsx): `web/components/chat/ChatInterface.tsx`
- [Voice chat](https://github.com/ashba2801/chatlaw/blob/main/web/lib/speech/useVoiceChat.ts): `web/lib/speech/useVoiceChat.ts`
- [Research workspace](https://github.com/ashba2801/chatlaw/blob/main/web/components/research/ResearchWorkspace.tsx): `web/components/research/ResearchWorkspace.tsx`
- [Case workspace](https://github.com/ashba2801/chatlaw/blob/main/web/components/cases/CaseDetail.tsx): `web/components/cases/CaseDetail.tsx`
- [Document editor](https://github.com/ashba2801/chatlaw/blob/main/web/components/documents/DocumentEditor.tsx): `web/components/documents/DocumentEditor.tsx`

### API and workflows

- [RAG proxy](https://github.com/ashba2801/chatlaw/blob/main/web/app/api/rag/%5B...path%5D/route.ts): `web/app/api/rag/[...path]/route.ts`
- [Case API](https://github.com/ashba2801/chatlaw/blob/main/web/app/api/cases/%5Bid%5D/route.ts): `web/app/api/cases/[id]/route.ts`
- [Case intelligence](https://github.com/ashba2801/chatlaw/blob/main/web/app/api/case-intelligence/route.ts): `web/app/api/case-intelligence/route.ts`
- [Document API](https://github.com/ashba2801/chatlaw/blob/main/web/app/api/documents/route.ts): `web/app/api/documents/route.ts`
- [FastAPI routes](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/api/main.py): `rag-engine/api/main.py`
- [Chat endpoint](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/api/routes/chat.py): `rag-engine/api/routes/chat.py`
- [Search endpoint](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/api/routes/search.py): `rag-engine/api/routes/search.py`
- [Conversation service](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/api/conversation_service.py): `rag-engine/api/conversation_service.py`
- [Court and advocate directory](https://github.com/ashba2801/chatlaw/blob/main/web/lib/case-intelligence/providers.ts): `web/lib/case-intelligence/providers.ts`

### Legal RAG

- [Case query analysis](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/cases/query_understanding.py): `rag-engine/cases/query_understanding.py`
- [Vector retrieval](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/retrieval/vector_search.py): `rag-engine/retrieval/vector_search.py`
- [Answer generation](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/generation/answer.py): `rag-engine/generation/answer.py`
- [Document drafting](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/conversation/document_drafting.py): `rag-engine/conversation/document_drafting.py`
- [Legal templates](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/documents/templates.py): `rag-engine/documents/templates.py`
- [Case-law retrieval](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/cases/retrieval.py): `rag-engine/cases/retrieval.py`

### Legal corpus

- [PDF legal parser](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/ingestion/parsers/pdf_parser.py): `rag-engine/ingestion/parsers/pdf_parser.py`
- [Ingestion models](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/ingestion/models.py): `rag-engine/ingestion/models.py`
- [Embedding ingestion](https://github.com/ashba2801/chatlaw/blob/main/rag-engine/embeddings/ingestion.py): `rag-engine/embeddings/ingestion.py`
- [Postgres and pgvector](https://github.com/ashba2801/chatlaw/blob/main/database/lib/vector-search.ts): `database/lib/vector-search.ts`

### Other components

- **Browser user**

## Connections

- Browser user → Web application: uses
- Web application → Legal chat: presents
- Web application → Research workspace: presents
- Web application → Case workspace: presents
- Web application → Document editor: presents
- Legal chat → RAG proxy: requests answers
- Voice chat → RAG proxy: sends chat
- Research workspace → RAG proxy: requests research
- RAG proxy → FastAPI routes: proxies requests
- Case workspace → Case API: manages cases
- Case workspace → Case intelligence: requests classification
- Document editor → Document API: manages drafts
- Case intelligence → Court and advocate directory: uses providers
- FastAPI routes → Chat endpoint: registers (evidence: `rag-engine/api/main.py`)
- FastAPI routes → Search endpoint: registers (evidence: `rag-engine/api/main.py`)
- Chat endpoint → Vector retrieval: retrieves context
- Chat endpoint → Answer generation: generates answer
- Chat endpoint → Document drafting: handles draft turns (evidence: `rag-engine/api/routes/chat.py`)
- Chat endpoint → Conversation service: reads history (evidence: `rag-engine/api/routes/chat.py`)
- Search endpoint → Vector retrieval: searches
- Vector retrieval → Postgres and pgvector: queries vectors
- Document drafting → Legal templates: uses templates
- Case query analysis → Case-law retrieval: informs retrieval (evidence: `rag-engine/cases/retrieval.py`)
- PDF legal parser → Ingestion models: builds structured data (evidence: `rag-engine/ingestion/parsers/pdf_parser.py`)
- PDF legal parser → Embedding ingestion: supplies corpus chunks
- Embedding ingestion → Postgres and pgvector: stores embeddings
