# gilgamish-hub/legal-auditor-ai architecture

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

- Interactive diagram: https://gitdiagram.com/gilgamish-hub/legal-auditor-ai
- Repository: https://github.com/gilgamish-hub/legal-auditor-ai

## Overview

Legal Auditor AI is a contract-auditing application: users provide contract text or a PDF, then receive clause classifications, risk levels, highlighted key words, and downloadable reports. Its supporting workflow prepares lawyer-annotated CUAD data, including an “Other” class and contract-level splits, for baseline and LegalBERT training. The graph preserves those documented capabilities. The training module and label-mapping implementation were not excerpted, so their internal relationships are shown only where the README or indexed references support them.

Main entry points: [`src/inference/predict.py`](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/inference/predict.py) (Document audit), [`src/app.py`](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/app.py) (Streamlit interface), [`src/data/preprocess.py`](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/data/preprocess.py) (Clause preprocessing), [`data/processed`](https://github.com/gilgamish-hub/legal-auditor-ai/tree/main/data/processed) (Train validation test data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_product["Audit application"]
  node_app["Streamlit interface<br/>[app.py]"]
  node_pdf["PDF text extraction<br/>[app.py]"]
  node_report["Audit reports and dashboard<br/>[app.py]"]
end

subgraph group_inference["Clause analysis"]
  node_audit["Document audit<br/>[predict.py]"]
  node_splitter["Clause splitting<br/>[text.py]"]
  node_classifier["LegalBERT classifier<br/>[predict.py]"]
  node_risk["Risk scoring<br/>[predict.py]"]
  node_keywords["Key-word attribution<br/>[predict.py]"]
end

subgraph group_dataset["Dataset preparation"]
  node_cuad["CUAD corpus<br/>[cuad.json]"]
  node_loader["CUAD extraction<br/>[load_cuad.py]"]
  node_mapping["Label mapping<br/>[label_mapping.py]"]
  node_preprocess["Clause preprocessing<br/>[preprocess.py]"]
  node_builder["Dataset orchestration<br/>[build_dataset.py]"]
  node_splits[("Train validation test data")]
end

subgraph group_models["Model development"]
  node_baseline["TF-IDF baseline<br/>[baseline.py]"]
  node_training["LegalBERT fine-tuning<br/>[train_legalbert.py]"]
end

node_user(("Contract reviewer"))
node_modelhub["Hugging Face model"]

node_user -->|"submits text"| node_app
node_user -->|"uploads PDF"| node_pdf
node_pdf -->|"provides text"| node_app
node_app -->|"requests audit"| node_audit
node_audit -->|"splits clauses"| node_splitter
node_audit -->|"classifies clauses"| node_classifier
node_audit -->|"scores risk"| node_risk
node_audit -->|"finds key words"| node_keywords
node_classifier -->|"loads model"| node_modelhub
node_audit -->|"returns results"| node_app
node_app -->|"renders and exports"| node_report
node_cuad -->|"provides annotations"| node_loader
node_builder -->|"extracts spans"| node_loader
node_builder -->|"prepares samples"| node_preprocess
node_preprocess -->|"maps labels"| node_mapping
node_preprocess -->|"writes datasets"| node_splits
node_baseline -->|"loads datasets"| node_splits
node_training -->|"trains on datasets"| node_splits

click node_app "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/app.py"
click node_pdf "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/app.py"
click node_report "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/app.py"
click node_audit "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/inference/predict.py"
click node_splitter "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/utils/text.py"
click node_classifier "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/inference/predict.py"
click node_risk "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/inference/predict.py"
click node_keywords "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/inference/predict.py"
click node_cuad "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/data/raw/cuad.json"
click node_loader "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/data/load_cuad.py"
click node_mapping "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/data/label_mapping.py"
click node_preprocess "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/data/preprocess.py"
click node_builder "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/data/build_dataset.py"
click node_splits "https://github.com/gilgamish-hub/legal-auditor-ai/tree/main/data/processed"
click node_baseline "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/models/baseline.py"
click node_training "https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/models/train_legalbert.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_app,node_pdf,node_report,node_user toneBlue
class node_audit,node_splitter,node_classifier,node_risk,node_keywords toneAmber
class node_cuad,node_loader,node_mapping,node_preprocess,node_builder,node_splits toneMint
class node_baseline,node_training toneRose
class node_modelhub toneIndigo
```

## Components

### Audit application

- [Streamlit interface](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/app.py): `src/app.py`
- [PDF text extraction](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/app.py): `src/app.py`
- [Audit reports and dashboard](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/app.py): `src/app.py`

### Clause analysis

- [Document audit](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/inference/predict.py): `src/inference/predict.py`
- [Clause splitting](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/utils/text.py): `src/utils/text.py`
- [LegalBERT classifier](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/inference/predict.py): `src/inference/predict.py`
- [Risk scoring](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/inference/predict.py): `src/inference/predict.py`
- [Key-word attribution](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/inference/predict.py): `src/inference/predict.py`

### Dataset preparation

- [CUAD corpus](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/data/raw/cuad.json): `data/raw/cuad.json`
- [CUAD extraction](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/data/load_cuad.py): `src/data/load_cuad.py`
- [Label mapping](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/data/label_mapping.py): `src/data/label_mapping.py`
- [Clause preprocessing](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/data/preprocess.py): `src/data/preprocess.py`
- [Dataset orchestration](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/data/build_dataset.py): `src/data/build_dataset.py`
- [Train validation test data](https://github.com/gilgamish-hub/legal-auditor-ai/tree/main/data/processed): `data/processed`

### Model development

- [TF-IDF baseline](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/models/baseline.py): `src/models/baseline.py`
- [LegalBERT fine-tuning](https://github.com/gilgamish-hub/legal-auditor-ai/blob/main/src/models/train_legalbert.py): `src/models/train_legalbert.py`

### Other components

- **Contract reviewer**
- **Hugging Face model**

## Connections

- Contract reviewer → Streamlit interface: submits text (evidence: `README.md`)
- Contract reviewer → PDF text extraction: uploads PDF (evidence: `README.md`)
- PDF text extraction → Streamlit interface: provides text (evidence: `src/app.py`)
- Streamlit interface → Document audit: requests audit (evidence: `src/app.py`)
- Document audit → Clause splitting: splits clauses (evidence: `src/inference/predict.py`)
- Document audit → LegalBERT classifier: classifies clauses (evidence: `src/inference/predict.py`)
- Document audit → Risk scoring: scores risk (evidence: `src/inference/predict.py`)
- Document audit → Key-word attribution: finds key words (evidence: `src/inference/predict.py`)
- LegalBERT classifier → Hugging Face model: loads model (evidence: `src/inference/predict.py`)
- Document audit → Streamlit interface: returns results (evidence: `src/app.py`)
- Streamlit interface → Audit reports and dashboard: renders and exports (evidence: `src/app.py`)
- CUAD corpus → CUAD extraction: provides annotations (evidence: `README.md`)
- Dataset orchestration → CUAD extraction: extracts spans (evidence: `src/data/build_dataset.py`)
- Dataset orchestration → Clause preprocessing: prepares samples (evidence: `src/data/build_dataset.py`)
- Clause preprocessing → Label mapping: maps labels (evidence: `src/data/preprocess.py`)
- Clause preprocessing → Train validation test data: writes datasets (evidence: `src/data/preprocess.py`)
- TF-IDF baseline → Train validation test data: loads datasets (evidence: `README.md`)
- LegalBERT fine-tuning → Train validation test data: trains on datasets (evidence: `README.md`)
