# weiyuu-zlc/rag-legal architecture

> Architecture diagram of the GitHub repository weiyuu-zlc/rag-legal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/weiyuu-zlc/rag-legal
- Repository: https://github.com/weiyuu-zlc/rag-legal

## Overview

LegalMind is a Chinese-law RAG question-answering system. A user submits a question through the Streamlit app or CLI; the question processor retrieves relevant provisions, optionally reranks them, asks an LLM to answer from the retrieved context, and validates and formats article citations. Separately, the corpus workflow parses source laws, splits them into chunks, and builds unified BM25 and vector indexes. Evaluation generates questions from the corpus and measures retrieval and answer quality. The README documents the build sequence and optional reranking; some internal implementation details were not sampled, so uncertain connections are omitted.

Main entry points: [`src/questions_processing.py`](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/questions_processing.py) (Question processor), [`src/api_requests.py`](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/api_requests.py) (LLM API adapter), [`src/retrieval.py`](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/retrieval.py) (Retrieval), [`src/evaluation.py`](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/evaluation.py) (Evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_web["Web interface<br/>[app.py]"]
  node_cli["Command line<br/>[cli.py]"]
end

subgraph group_qa["Question answering"]
  node_processor["Question processor"]
  node_retrieval["Retrieval<br/>[retrieval.py]"]
  node_reranking["LLM reranking<br/>[reranking.py]"]
  node_prompts["Prompt templates<br/>[prompts.py]"]
end

subgraph group_corpus["Corpus and indexing"]
  node_source_laws["Law source files"]
  node_parser["Law parser<br/>[legal_parser.py]"]
  node_splitter["Article chunking<br/>[text_splitter.py]"]
  node_ingestion["Index builder<br/>[ingestion.py]"]
  node_index_store[("Unified indexes")]
end

subgraph group_models["Model services"]
  node_api["LLM API adapter<br/>[api_requests.py]"]
  node_parallel["Parallel API processor"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation["Evaluation<br/>[evaluation.py]"]
end

node_user(("Questioner"))
node_model_service{{"DashScope models"}}

node_user -->|"asks via"| node_web
node_user -->|"asks via"| node_cli
node_web -->|"submits question"| node_processor
node_cli -->|"submits question"| node_processor
node_processor -->|"retrieves provisions"| node_retrieval
node_retrieval -->|"reads indexes"| node_index_store
node_retrieval -->|"reranks candidates"| node_reranking
node_reranking -->|"uses prompts"| node_prompts
node_processor -->|"requests answer"| node_api
node_api -->|"uses prompts"| node_prompts
node_api -->|"calls model"| node_model_service
node_api -.->|"uses for parallel requests"| node_parallel
node_source_laws -->|"provides documents"| node_parser
node_parser -->|"produces parsed laws"| node_splitter
node_splitter -->|"provides chunks"| node_ingestion
node_ingestion -->|"writes indexes"| node_index_store
node_evaluation -->|"evaluates retrieval"| node_retrieval
node_evaluation -->|"evaluates answers"| node_processor
node_evaluation -->|"generates and judges"| node_model_service

click node_web "https://github.com/weiyuu-zlc/rag-legal/blob/main/app.py"
click node_cli "https://github.com/weiyuu-zlc/rag-legal/blob/main/cli.py"
click node_processor "https://github.com/weiyuu-zlc/rag-legal/blob/main/src/questions_processing.py"
click node_retrieval "https://github.com/weiyuu-zlc/rag-legal/blob/main/src/retrieval.py"
click node_reranking "https://github.com/weiyuu-zlc/rag-legal/blob/main/src/reranking.py"
click node_prompts "https://github.com/weiyuu-zlc/rag-legal/blob/main/src/prompts.py"
click node_api "https://github.com/weiyuu-zlc/rag-legal/blob/main/src/api_requests.py"
click node_parallel "https://github.com/weiyuu-zlc/rag-legal/blob/main/src/api_request_parallel_processor.py"
click node_source_laws "https://github.com/weiyuu-zlc/rag-legal/tree/main/data"
click node_parser "https://github.com/weiyuu-zlc/rag-legal/blob/main/src/legal_parser.py"
click node_splitter "https://github.com/weiyuu-zlc/rag-legal/blob/main/src/text_splitter.py"
click node_ingestion "https://github.com/weiyuu-zlc/rag-legal/blob/main/src/ingestion.py"
click node_evaluation "https://github.com/weiyuu-zlc/rag-legal/blob/main/src/evaluation.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_web,node_cli toneBlue
class node_processor,node_retrieval,node_reranking,node_prompts toneAmber
class node_source_laws,node_parser,node_splitter,node_ingestion,node_index_store toneMint
class node_api,node_parallel toneRose
class node_evaluation,node_user,node_model_service toneIndigo
```

## Components

### User interfaces

- [Web interface](https://github.com/weiyuu-zlc/rag-legal/blob/main/app.py): `app.py`
- [Command line](https://github.com/weiyuu-zlc/rag-legal/blob/main/cli.py): `cli.py`

### Question answering

- [Question processor](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/questions_processing.py): `src/questions_processing.py`
- [Retrieval](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/retrieval.py): `src/retrieval.py`
- [LLM reranking](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/reranking.py): `src/reranking.py`
- [Prompt templates](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/prompts.py): `src/prompts.py`

### Corpus and indexing

- [Law source files](https://github.com/weiyuu-zlc/rag-legal/tree/main/data): `data`
- [Law parser](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/legal_parser.py): `src/legal_parser.py`
- [Article chunking](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/text_splitter.py): `src/text_splitter.py`
- [Index builder](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/ingestion.py): `src/ingestion.py`
- **Unified indexes**

### Model services

- [LLM API adapter](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/api_requests.py): `src/api_requests.py`
- [Parallel API processor](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/api_request_parallel_processor.py): `src/api_request_parallel_processor.py`

### Evaluation

- [Evaluation](https://github.com/weiyuu-zlc/rag-legal/blob/main/src/evaluation.py): `src/evaluation.py`

### Other components

- **Questioner**
- **DashScope models**

## Connections

- Questioner → Web interface: asks via (evidence: `README.md`)
- Questioner → Command line: asks via (evidence: `README.md`)
- Web interface → Question processor: submits question (evidence: `app.py`)
- Command line → Question processor: submits question (evidence: `cli.py`)
- Question processor → Retrieval: retrieves provisions (evidence: `src/questions_processing.py`)
- Retrieval → Unified indexes: reads indexes (evidence: `src/retrieval.py`)
- Retrieval → LLM reranking: reranks candidates (evidence: `src/retrieval.py`)
- LLM reranking → Prompt templates: uses prompts (evidence: `src/reranking.py`)
- Question processor → LLM API adapter: requests answer (evidence: `src/questions_processing.py`)
- LLM API adapter → Prompt templates: uses prompts (evidence: `src/api_requests.py`)
- LLM API adapter → DashScope models: calls model (evidence: `README.md`)
- LLM API adapter → Parallel API processor: uses for parallel requests (evidence: `src/api_requests.py`)
- Law source files → Law parser: provides documents (evidence: `README.md`)
- Law parser → Article chunking: produces parsed laws (evidence: `README.md`)
- Article chunking → Index builder: provides chunks (evidence: `README.md`)
- Index builder → Unified indexes: writes indexes (evidence: `src/ingestion.py`)
- Evaluation → Retrieval: evaluates retrieval (evidence: `src/evaluation.py`)
- Evaluation → Question processor: evaluates answers (evidence: `src/evaluation.py`)
- Evaluation → DashScope models: generates and judges (evidence: `README.md`)
