# aditya11-05/judgebert-lmp architecture

> Architecture diagram of the GitHub repository aditya11-05/judgebert-lmp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aditya11-05/judgebert-lmp
- Repository: https://github.com/aditya11-05/judgebert-lmp

## Overview

JUDGEBERT-LMP is a research prototype for legal-meaning-preservation scoring, with a Streamlit interface and FastAPI service. A user submits a sentence pair or CSV; the frontend validates and sends requests, while the backend returns a model score only when a trained model is available, plus rule-based findings and optional baseline scores. The repository also includes dataset preparation and human-annotation capabilities. The README documents planned/unavailable model capabilities; those are shown as such. Some dataset and annotation wiring is based on indexed references rather than inspected implementation excerpts.

Main entry points: [`frontend/streamlit_app.py`](https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/streamlit_app.py) (Streamlit app), [`app/service.py`](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/service.py) (Analysis service), [`app/explanations/engine.py`](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/engine.py) (Legal findings), [`frontend/batch.py`](https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/batch.py) (CSV batch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User interfaces"]
  node_streamlit["Streamlit app<br/>[streamlit_app.py]"]
  node_batch["CSV batch<br/>[batch.py]"]
  node_client["HTTP client<br/>[api_client.py]"]
  node_presenters["Result presenters<br/>[presenters.py]"]
  node_annotation_ui["Annotation interface<br/>[annotation.py]"]
end

subgraph group_api["Analysis API"]
  node_routes["HTTP routes<br/>[routes.py]"]
  node_service["Analysis service<br/>[service.py]"]
  node_config["Runtime settings<br/>[config.py]"]
end

subgraph group_explain["Findings and scoring"]
  node_explanations["Legal findings<br/>[engine.py]"]
  node_lexicon["English features<br/>[lexicon_en.py]"]
  node_rules["Change rules<br/>[rules.py]"]
  node_alignment["Text alignment<br/>[alignment.py]"]
  node_scoring["Score categories<br/>[scoring.py]"]
  node_app_explanation_dataset["Explanation dataset<br/>[dataset.py]"]
end

subgraph group_models["Models and baselines"]
  node_inference["Model inference<br/>[inference.py]"]
  node_xlmr["XLM-R regressor<br/>[xlmr.py]"]
  node_baseline_registry["Baseline registry"]
  node_baseline_models["Baseline models<br/>[baselines.py]"]
  node_evaluate["Model evaluation<br/>[evaluate.py]"]
end

subgraph group_research["Research data"]
  node_dataset_load["Dataset loading<br/>[load_dataset.py]"]
  node_dataset_validate["Dataset validation"]
  node_dataset_split["Group-aware splitting<br/>[split_dataset.py]"]
  node_annotation_store[("Annotation storage")]
end

node_user(("Research user"))
node_api_server{{"FastAPI service"}}

node_user -->|"uses"| node_streamlit
node_streamlit -->|"requests through"| node_client
node_streamlit -->|"runs"| node_batch
node_streamlit -->|"displays with"| node_presenters
node_streamlit -->|"offers"| node_annotation_ui
node_batch -->|"submits batches"| node_client
node_batch -->|"formats results"| node_presenters
node_client -->|"sends HTTP"| node_api_server
node_api_server -->|"serves routes"| node_routes
node_routes -->|"dispatches to"| node_service
node_service -->|"requests scores"| node_inference
node_service -->|"generates findings"| node_explanations
node_service -->|"categorizes scores"| node_scoring
node_service -->|"requests baselines"| node_baseline_registry
node_inference -->|"loads and runs"| node_xlmr
node_baseline_registry -->|"loads and scores"| node_baseline_models
node_explanations -->|"extracts features"| node_lexicon
node_explanations -->|"applies rules"| node_rules
node_explanations -->|"marks spans"| node_alignment
node_dataset_load -->|"validates data"| node_dataset_validate
node_dataset_validate -->|"checks explanation schema"| node_app_explanation_dataset
node_annotation_ui -->|"records annotations"| node_annotation_store

click node_streamlit "https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/streamlit_app.py"
click node_batch "https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/batch.py"
click node_client "https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/api_client.py"
click node_presenters "https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/presenters.py"
click node_annotation_ui "https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/annotation.py"
click node_routes "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/routes.py"
click node_service "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/service.py"
click node_config "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/config.py"
click node_explanations "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/engine.py"
click node_lexicon "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/lexicon_en.py"
click node_rules "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/rules.py"
click node_alignment "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/alignment.py"
click node_scoring "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/scoring.py"
click node_inference "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/inference.py"
click node_xlmr "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/models/xlmr.py"
click node_baseline_registry "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/baseline_service.py"
click node_baseline_models "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/models/baselines.py"
click node_evaluate "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/models/evaluate.py"
click node_dataset_load "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/data/load_dataset.py"
click node_dataset_validate "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/data/validate_dataset.py"
click node_dataset_split "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/data/split_dataset.py"
click node_annotation_store "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/data/annotation_store.py"
click node_app_explanation_dataset "https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/dataset.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_streamlit,node_batch,node_client,node_presenters,node_annotation_ui,node_user toneBlue
class node_routes,node_service,node_config toneAmber
class node_explanations,node_lexicon,node_rules,node_alignment,node_scoring,node_app_explanation_dataset,node_api_server toneMint
class node_inference,node_xlmr,node_baseline_registry,node_baseline_models,node_evaluate toneRose
class node_dataset_load,node_dataset_validate,node_dataset_split,node_annotation_store toneIndigo
```

## Components

### User interfaces

- [Streamlit app](https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/streamlit_app.py): `frontend/streamlit_app.py`
- [CSV batch](https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/batch.py): `frontend/batch.py`
- [HTTP client](https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/api_client.py): `frontend/api_client.py`
- [Result presenters](https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/presenters.py): `frontend/presenters.py`
- [Annotation interface](https://github.com/aditya11-05/judgebert-lmp/blob/main/frontend/annotation.py): `frontend/annotation.py`

### Analysis API

- [HTTP routes](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/routes.py): `app/routes.py`
- [Analysis service](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/service.py): `app/service.py`
- [Runtime settings](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/config.py): `app/config.py`

### Findings and scoring

- [Legal findings](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/engine.py): `app/explanations/engine.py`
- [English features](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/lexicon_en.py): `app/explanations/lexicon_en.py`
- [Change rules](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/rules.py): `app/explanations/rules.py`
- [Text alignment](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/alignment.py): `app/explanations/alignment.py`
- [Score categories](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/scoring.py): `app/scoring.py`
- [Explanation dataset](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/explanations/dataset.py): `app/explanations/dataset.py`

### Models and baselines

- [Model inference](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/inference.py): `app/inference.py`
- [XLM-R regressor](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/models/xlmr.py): `app/models/xlmr.py`
- [Baseline registry](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/baseline_service.py): `app/baseline_service.py`
- [Baseline models](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/models/baselines.py): `app/models/baselines.py`
- [Model evaluation](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/models/evaluate.py): `app/models/evaluate.py`

### Research data

- [Dataset loading](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/data/load_dataset.py): `app/data/load_dataset.py`
- [Dataset validation](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/data/validate_dataset.py): `app/data/validate_dataset.py`
- [Group-aware splitting](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/data/split_dataset.py): `app/data/split_dataset.py`
- [Annotation storage](https://github.com/aditya11-05/judgebert-lmp/blob/main/app/data/annotation_store.py): `app/data/annotation_store.py`

### Other components

- **Research user**
- **FastAPI service**

## Connections

- Research user → Streamlit app: uses
- Streamlit app → HTTP client: requests through (evidence: `frontend/streamlit_app.py`)
- Streamlit app → CSV batch: runs (evidence: `frontend/streamlit_app.py`)
- Streamlit app → Result presenters: displays with (evidence: `frontend/streamlit_app.py`)
- Streamlit app → Annotation interface: offers (evidence: `frontend/streamlit_app.py`)
- CSV batch → HTTP client: submits batches (evidence: `frontend/batch.py`)
- CSV batch → Result presenters: formats results (evidence: `frontend/batch.py`)
- HTTP client → FastAPI service: sends HTTP (evidence: `frontend/api_client.py`)
- FastAPI service → HTTP routes: serves routes
- HTTP routes → Analysis service: dispatches to (evidence: `app/routes.py`)
- Analysis service → Model inference: requests scores (evidence: `app/service.py`)
- Analysis service → Legal findings: generates findings (evidence: `app/service.py`)
- Analysis service → Score categories: categorizes scores (evidence: `app/service.py`)
- Analysis service → Baseline registry: requests baselines (evidence: `app/service.py`)
- Model inference → XLM-R regressor: loads and runs (evidence: `app/inference.py`)
- Baseline registry → Baseline models: loads and scores (evidence: `app/baseline_service.py`)
- Legal findings → English features: extracts features (evidence: `app/explanations/engine.py`)
- Legal findings → Change rules: applies rules (evidence: `app/explanations/engine.py`)
- Legal findings → Text alignment: marks spans (evidence: `app/explanations/engine.py`)
- Dataset loading → Dataset validation: validates data (evidence: `app/data/load_dataset.py`)
- Dataset validation → Explanation dataset: checks explanation schema (evidence: `app/data/validate_dataset.py`)
- Annotation interface → Annotation storage: records annotations (evidence: `frontend/annotation.py`)
