# l0cka/caselaw-guard architecture

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

- Interactive diagram: https://gitdiagram.com/l0cka/caselaw-guard
- Repository: https://github.com/l0cka/caselaw-guard

## Overview

CaseLaw Guard extracts case-law citations from text, routes each citation to a configured legal-source adapter, and returns a fail-closed verification report through the CLI, REST API, or MCP server. Its Australian path supports offline lookups from a provenance-bearing local index, plus building, fetching, inspecting, and migrating indexes. CourtListener provides the U.S. lookup integration and optional result cache. Relationships among sampled modules are cited to source; documented entry points and index-fetch behavior are cited to the README. Other unsampled wiring is omitted.

Main entry points: [`src/caselaw_guard/verifier.py`](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/verifier.py) (Verification orchestration), [`src/caselaw_guard/australia/index_builder.py`](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/index_builder.py) (Index builder and migration), [`src/caselaw_guard/australia/index_store.py`](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/index_store.py) (Local index store), [`src/caselaw_guard/cli.py`](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/cli.py) (CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI<br/>[cli.py]"]
  node_rest["REST API<br/>[api.py]"]
  node_mcp["MCP server<br/>[mcp_server.py]"]
end

subgraph group_verification["Verification core"]
  node_extract["Citation extraction<br/>[extractors.py]"]
  node_verify["Verification orchestration<br/>[verifier.py]"]
  node_contracts["Result contracts<br/>[models.py]"]
end

subgraph group_australia["Australian index"]
  node_au_service["Australian lookup service<br/>[service.py]"]
  node_au_normalization["Citation normalization<br/>[normalization.py]"]
  node_au_courts["Court metadata<br/>[courts.py]"]
  node_au_store[("Local index store<br/>[index_store.py]")]
  node_au_models["Index contracts<br/>[models.py]"]
  node_au_builder["Index builder and migration<br/>[index_builder.py]"]
  node_au_fetcher["Index fetcher<br/>[index_fetcher.py]"]
end

subgraph group_providers["Lookup providers"]
  node_adapter_base["Adapter contract<br/>[base.py]"]
  node_adapter_config["Adapter configuration<br/>[__init__.py]"]
  node_courtlistener["CourtListener adapter<br/>[courtlistener.py]"]
  node_au_adapter["Australian adapter<br/>[australia.py]"]
end

node_author(("Draft author or agent"))
node_courtlistener_service["CourtListener service"]
node_corpus[("Open Australian Legal Corpus")]
node_release_assets[("Versioned index release assets")]
node_local_index[("Local Australian index file")]
node_report["Verification report"]

node_author -->|"submits text"| node_cli
node_author -->|"posts text"| node_rest
node_author -->|"sends text"| node_mcp
node_cli -->|"verifies text"| node_verify
node_rest -->|"verifies text"| node_verify
node_mcp -->|"verifies text"| node_verify
node_verify -->|"extracts citations"| node_extract
node_verify -->|"builds adapters"| node_adapter_config
node_verify -->|"dispatches lookup"| node_adapter_base
node_verify -->|"returns report"| node_contracts
node_extract -->|"creates matches"| node_contracts
node_adapter_config -->|"configures"| node_courtlistener
node_adapter_config -->|"configures"| node_au_adapter
node_courtlistener -->|"queries"| node_courtlistener_service
node_courtlistener -->|"maps results"| node_contracts
node_au_adapter -->|"looks up citation"| node_au_service
node_au_adapter -->|"maps results"| node_contracts
node_au_service -->|"normalizes citation"| node_au_normalization
node_au_service -->|"queries index"| node_au_store
node_au_store -->|"validates entries"| node_au_models
node_au_store -->|"normalizes legacy keys"| node_au_normalization
node_au_store -->|"resolves court codes"| node_au_courts
node_au_builder -->|"reads JSONL"| node_corpus
node_au_builder -->|"normalizes citations"| node_au_normalization
node_au_builder -->|"resolves courts"| node_au_courts
node_au_builder -->|"creates index"| node_au_models
node_au_builder -->|"loads for migration"| node_au_store
node_au_builder -->|"writes index"| node_local_index
node_cli -->|"builds or migrates"| node_au_builder
node_cli -->|"inspects index"| node_au_store
node_cli -->|"fetches release"| node_au_fetcher
node_au_fetcher -->|"downloads assets"| node_release_assets
node_au_fetcher -->|"replaces atomically"| node_local_index
node_au_service -->|"returns lookup result"| node_report
node_verify -->|"returns JSON"| node_report

click node_cli "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/cli.py"
click node_rest "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/api.py"
click node_mcp "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/mcp_server.py"
click node_extract "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/extractors.py"
click node_verify "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/verifier.py"
click node_contracts "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/models.py"
click node_adapter_base "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/adapters/base.py"
click node_adapter_config "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/adapters/__init__.py"
click node_courtlistener "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/adapters/courtlistener.py"
click node_au_adapter "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/adapters/australia.py"
click node_au_service "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/service.py"
click node_au_normalization "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/normalization.py"
click node_au_courts "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/courts.py"
click node_au_store "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/index_store.py"
click node_au_models "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/models.py"
click node_au_builder "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/index_builder.py"
click node_au_fetcher "https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/index_fetcher.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_cli,node_rest,node_mcp toneBlue
class node_extract,node_verify,node_contracts,node_corpus,node_release_assets,node_local_index toneAmber
class node_au_service,node_au_normalization,node_au_courts,node_au_store,node_au_models,node_au_builder,node_au_fetcher toneMint
class node_adapter_base,node_adapter_config,node_courtlistener,node_au_adapter toneRose
class node_author,node_courtlistener_service,node_report toneIndigo
```

## Components

### User interfaces

- [CLI](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/cli.py): `src/caselaw_guard/cli.py`
- [REST API](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/api.py): `src/caselaw_guard/api.py`
- [MCP server](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/mcp_server.py): `src/caselaw_guard/mcp_server.py`

### Verification core

- [Citation extraction](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/extractors.py): `src/caselaw_guard/extractors.py`
- [Verification orchestration](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/verifier.py): `src/caselaw_guard/verifier.py`
- [Result contracts](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/models.py): `src/caselaw_guard/models.py`

### Australian index

- [Australian lookup service](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/service.py): `src/caselaw_guard/australia/service.py`
- [Citation normalization](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/normalization.py): `src/caselaw_guard/australia/normalization.py`
- [Court metadata](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/courts.py): `src/caselaw_guard/australia/courts.py`
- [Local index store](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/index_store.py): `src/caselaw_guard/australia/index_store.py`
- [Index contracts](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/models.py): `src/caselaw_guard/australia/models.py`
- [Index builder and migration](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/index_builder.py): `src/caselaw_guard/australia/index_builder.py`
- [Index fetcher](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/australia/index_fetcher.py): `src/caselaw_guard/australia/index_fetcher.py`

### Lookup providers

- [Adapter contract](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/adapters/base.py): `src/caselaw_guard/adapters/base.py`
- [Adapter configuration](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/adapters/__init__.py): `src/caselaw_guard/adapters/__init__.py`
- [CourtListener adapter](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/adapters/courtlistener.py): `src/caselaw_guard/adapters/courtlistener.py`
- [Australian adapter](https://github.com/l0cka/caselaw-guard/blob/main/src/caselaw_guard/adapters/australia.py): `src/caselaw_guard/adapters/australia.py`

### Other components

- **Draft author or agent**
- **CourtListener service**
- **Open Australian Legal Corpus**
- **Versioned index release assets**
- **Local Australian index file**
- **Verification report**

## Connections

- Draft author or agent → CLI: submits text (evidence: `README.md`)
- Draft author or agent → REST API: posts text (evidence: `README.md`)
- Draft author or agent → MCP server: sends text (evidence: `README.md`)
- CLI → Verification orchestration: verifies text (evidence: `src/caselaw_guard/cli.py`)
- REST API → Verification orchestration: verifies text (evidence: `src/caselaw_guard/api.py`)
- MCP server → Verification orchestration: verifies text (evidence: `src/caselaw_guard/mcp_server.py`)
- Verification orchestration → Citation extraction: extracts citations (evidence: `src/caselaw_guard/verifier.py`)
- Verification orchestration → Adapter configuration: builds adapters (evidence: `src/caselaw_guard/verifier.py`)
- Verification orchestration → Adapter contract: dispatches lookup (evidence: `src/caselaw_guard/verifier.py`)
- Verification orchestration → Result contracts: returns report (evidence: `src/caselaw_guard/verifier.py`)
- Citation extraction → Result contracts: creates matches (evidence: `src/caselaw_guard/extractors.py`)
- Adapter configuration → CourtListener adapter: configures (evidence: `src/caselaw_guard/adapters/__init__.py`)
- Adapter configuration → Australian adapter: configures (evidence: `src/caselaw_guard/adapters/__init__.py`)
- CourtListener adapter → CourtListener service: queries (evidence: `src/caselaw_guard/adapters/courtlistener.py`)
- CourtListener adapter → Result contracts: maps results (evidence: `src/caselaw_guard/adapters/courtlistener.py`)
- Australian adapter → Australian lookup service: looks up citation (evidence: `src/caselaw_guard/adapters/australia.py`)
- Australian adapter → Result contracts: maps results (evidence: `src/caselaw_guard/adapters/australia.py`)
- Australian lookup service → Citation normalization: normalizes citation (evidence: `src/caselaw_guard/australia/service.py`)
- Australian lookup service → Local index store: queries index (evidence: `src/caselaw_guard/australia/service.py`)
- Local index store → Index contracts: validates entries (evidence: `src/caselaw_guard/australia/index_store.py`)
- Local index store → Citation normalization: normalizes legacy keys (evidence: `src/caselaw_guard/australia/index_store.py`)
- Local index store → Court metadata: resolves court codes (evidence: `src/caselaw_guard/australia/index_store.py`)
- Index builder and migration → Open Australian Legal Corpus: reads JSONL (evidence: `src/caselaw_guard/australia/index_builder.py`)
- Index builder and migration → Citation normalization: normalizes citations (evidence: `src/caselaw_guard/australia/index_builder.py`)
- Index builder and migration → Court metadata: resolves courts (evidence: `src/caselaw_guard/australia/index_builder.py`)
- Index builder and migration → Index contracts: creates index (evidence: `src/caselaw_guard/australia/index_builder.py`)
- Index builder and migration → Local index store: loads for migration (evidence: `src/caselaw_guard/australia/index_builder.py`)
- Index builder and migration → Local Australian index file: writes index (evidence: `src/caselaw_guard/australia/index_builder.py`)
- CLI → Index builder and migration: builds or migrates (evidence: `src/caselaw_guard/cli.py`)
- CLI → Local index store: inspects index (evidence: `src/caselaw_guard/cli.py`)
- CLI → Index fetcher: fetches release (evidence: `src/caselaw_guard/cli.py`)
- Index fetcher → Versioned index release assets: downloads assets (evidence: `README.md`)
- Index fetcher → Local Australian index file: replaces atomically (evidence: `README.md`)
- Australian lookup service → Verification report: returns lookup result (evidence: `README.md`)
- Verification orchestration → Verification report: returns JSON (evidence: `README.md`)
