# ministryofjustice/hmpps-court-case-enrichment-worker architecture

> Architecture diagram of the GitHub repository ministryofjustice/hmpps-court-case-enrichment-worker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ministryofjustice/hmpps-court-case-enrichment-worker
- Repository: https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker

## Overview

This Kotlin Spring service enriches Common Platform and Libra defendant records, using CPR and Offender Search data, then returns results through API endpoints or persists them to Court Case Service. The principal workflow is scheduled batch execution: fetch court-specific targets, enrich each identifier, and persist each result. The README documents the batch schedule and manual triggering; sampled code confirms the internal calls and downstream clients. Other HTTP/API and operational capabilities are represented from the source index; their full implementations were not all sampled.

Main entry points: [`src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt`](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt) (Batch orchestration), [`src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentService.kt`](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentService.kt) (Defendant enrichment), [`src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CourtCaseServiceClient.kt`](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CourtCaseServiceClient.kt) (Court Case client), [`src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/batch/BatchManager.kt`](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/batch/BatchManager.kt) (Batch manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_batch["Batch manager<br/>[BatchManager.kt]"]
  node_jobapi["Job endpoint"]
  node_enrichapi["Enrichment endpoint"]
end

subgraph group_workflow["Enrichment workflow"]
  node_job["Batch orchestration"]
  node_targets["Target retrieval"]
  node_enrichment["Defendant enrichment"]
  node_domain["Enrichment results"]
  node_jobresult["Job summary"]
  node_persistmodel["Persistence mapping"]
end

subgraph group_connectors["Service connectors"]
  node_ccsclient["Court Case client"]
  node_cprclient["CPR client<br/>[CprClient.kt]"]
  node_offenderclient["Offender Search client"]
  node_summary["Call summaries"]
end

subgraph group_platform["HTTP platform"]
  node_health["Health and ping<br/>[HealthPingCheck.kt]"]
  node_ping["Ping endpoint<br/>[PingResource.kt]"]
  node_security["Security configuration"]
  node_properties["Enrichment settings"]
  node_webconfig["Web client setup"]
  node_logging["Request logging"]
end

node_operator(("Scheduler or caller"))
node_ccs{{"Court Case Service"}}
node_cpr{{"Person Record Service"}}
node_offender{{"Offender Search"}}

node_operator -->|"starts scheduled"| node_batch
node_operator -.->|"requests job"| node_jobapi
node_operator -.->|"requests enrichment"| node_enrichapi
node_batch -->|"dispatches job"| node_job
node_jobapi -->|"invokes job"| node_job
node_enrichapi -->|"invokes enrichment"| node_enrichment
node_job -->|"fetches targets"| node_targets
node_targets -->|"requests IDs"| node_ccsclient
node_ccsclient -->|"reads and writes"| node_ccs
node_job -->|"enriches targets"| node_enrichment
node_enrichment -->|"loads person"| node_cprclient
node_enrichment -->|"searches CRNs"| node_offenderclient
node_cprclient -->|"reads records"| node_cpr
node_offenderclient -->|"searches offenders"| node_offender
node_job -->|"persists results"| node_ccsclient
node_job -->|"reads settings"| node_properties
node_job -->|"creates summary"| node_jobresult
node_job -->|"collects calls"| node_summary
node_enrichment -->|"creates results"| node_domain
node_ccsclient -->|"sends request"| node_persistmodel
node_ping -.->|"checks health"| node_health
node_security -.->|"configures access"| node_webconfig
node_logging -.->|"filters requests"| node_webconfig

click node_batch "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/batch/BatchManager.kt"
click node_jobapi "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/DefendantEnrichmentJobResource.kt"
click node_enrichapi "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/DefendantEnrichmentResource.kt"
click node_job "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt"
click node_targets "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/EnrichmentTargetService.kt"
click node_enrichment "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentService.kt"
click node_domain "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/model/EnrichmentSourceType.kt"
click node_jobresult "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/model/DefendantEnrichmentJobResult.kt"
click node_persistmodel "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/model/courtcase/PersistEnrichmentResultRequest.kt"
click node_ccsclient "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CourtCaseServiceClient.kt"
click node_cprclient "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CprClient.kt"
click node_offenderclient "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/OffenderSearchClient.kt"
click node_summary "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/ServiceCallSummary.kt"
click node_health "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/health/HealthPingCheck.kt"
click node_ping "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/PingResource.kt"
click node_security "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/SecurityConfiguration.kt"
click node_properties "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/DefendantEnrichmentProperties.kt"
click node_webconfig "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/WebClientConfiguration.kt"
click node_logging "https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/RequestLoggingFilter.kt"

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_batch,node_jobapi,node_enrichapi toneBlue
class node_job,node_targets,node_enrichment,node_domain,node_jobresult,node_persistmodel toneAmber
class node_ccsclient,node_cprclient,node_offenderclient,node_summary toneMint
class node_health,node_ping,node_security,node_properties,node_webconfig,node_logging,node_operator toneRose
class node_ccs,node_cpr,node_offender toneIndigo
```

## Components

### Entry points

- [Batch manager](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/batch/BatchManager.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/batch/BatchManager.kt`
- [Job endpoint](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/DefendantEnrichmentJobResource.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/DefendantEnrichmentJobResource.kt`
- [Enrichment endpoint](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/DefendantEnrichmentResource.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/DefendantEnrichmentResource.kt`

### Enrichment workflow

- [Batch orchestration](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt`
- [Target retrieval](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/EnrichmentTargetService.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/EnrichmentTargetService.kt`
- [Defendant enrichment](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentService.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentService.kt`
- [Enrichment results](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/model/EnrichmentSourceType.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/model/EnrichmentSourceType.kt`
- [Job summary](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/model/DefendantEnrichmentJobResult.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/model/DefendantEnrichmentJobResult.kt`
- [Persistence mapping](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/model/courtcase/PersistEnrichmentResultRequest.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/model/courtcase/PersistEnrichmentResultRequest.kt`

### Service connectors

- [Court Case client](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CourtCaseServiceClient.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CourtCaseServiceClient.kt`
- [CPR client](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CprClient.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CprClient.kt`
- [Offender Search client](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/OffenderSearchClient.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/OffenderSearchClient.kt`
- [Call summaries](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/ServiceCallSummary.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/ServiceCallSummary.kt`

### HTTP platform

- [Health and ping](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/health/HealthPingCheck.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/health/HealthPingCheck.kt`
- [Ping endpoint](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/PingResource.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/PingResource.kt`
- [Security configuration](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/SecurityConfiguration.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/SecurityConfiguration.kt`
- [Enrichment settings](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/DefendantEnrichmentProperties.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/DefendantEnrichmentProperties.kt`
- [Web client setup](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/WebClientConfiguration.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/WebClientConfiguration.kt`
- [Request logging](https://github.com/ministryofjustice/hmpps-court-case-enrichment-worker/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/RequestLoggingFilter.kt): `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/config/RequestLoggingFilter.kt`

### Other components

- **Scheduler or caller**
- **Court Case Service**
- **Person Record Service**
- **Offender Search**

## Connections

- Scheduler or caller → Batch manager: starts scheduled (evidence: `README.md`)
- Scheduler or caller → Job endpoint: requests job
- Scheduler or caller → Enrichment endpoint: requests enrichment
- Batch manager → Batch orchestration: dispatches job (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/batch/BatchManager.kt`)
- Job endpoint → Batch orchestration: invokes job (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/DefendantEnrichmentJobResource.kt`)
- Enrichment endpoint → Defendant enrichment: invokes enrichment (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/resource/DefendantEnrichmentResource.kt`)
- Batch orchestration → Target retrieval: fetches targets (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt`)
- Target retrieval → Court Case client: requests IDs (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/EnrichmentTargetService.kt`)
- Court Case client → Court Case Service: reads and writes (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CourtCaseServiceClient.kt`)
- Batch orchestration → Defendant enrichment: enriches targets (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt`)
- Defendant enrichment → CPR client: loads person (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentService.kt`)
- Defendant enrichment → Offender Search client: searches CRNs (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentService.kt`)
- CPR client → Person Record Service: reads records (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CprClient.kt`)
- Offender Search client → Offender Search: searches offenders (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/OffenderSearchClient.kt`)
- Batch orchestration → Court Case client: persists results (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt`)
- Batch orchestration → Enrichment settings: reads settings (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt`)
- Batch orchestration → Job summary: creates summary (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt`)
- Batch orchestration → Call summaries: collects calls (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentJobService.kt`)
- Defendant enrichment → Enrichment results: creates results (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/service/DefendantEnrichmentService.kt`)
- Court Case client → Persistence mapping: sends request (evidence: `src/main/kotlin/uk/gov/justice/digital/hmpps/courtcaseenrichmentworker/restclient/CourtCaseServiceClient.kt`)
- Ping endpoint → Health and ping: checks health
- Security configuration → Web client setup: configures access
- Request logging → Web client setup: filters requests
