# the-strategy-unit/nhp_reskit architecture

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

- Interactive diagram: https://gitdiagram.com/the-strategy-unit/nhp_reskit
- Repository: https://github.com/the-strategy-unit/nhp_reskit

## Overview

#### Purpose and package surface
`reskit` is an R package for turning NHP model-result datasets into analysis-ready summaries, presentation tables, and plots. The public entry surface is the exported R functions documented in `man/`; package initialization and namespace identity are defined by `R/reskit-package.R`, `DESCRIPTION`, and `NAMESPACE`.

#### Results ingestion boundary
The principal input boundary is Azure Blob Storage accessed through `azkit`, with Azure authentication and `AZ_STORAGE_EP` supplied externally. `read_results_parquet_files()` loads a results folder into a named list of tibbles, optionally selecting table basenames. Core implementation: `R/read_results_parquet_files.R`; Azure/GitHub-oriented retrieval helpers: `R/get_github_file.R`, `R/helpers.R`.

#### Result normalization and compatibility
Raw model-result lists are adapted before reporting. `shim_results()` provides a compatibility/normalization layer for result structures, while shared transformations, result emptiness handling, and baseline/horizon calculations support downstream compilers. Paths: `R/shim_results.R`, `R/helpers.R`, `R/calculate_principal_stats.R`.

#### Principal activity and LOS reporting pipeline
Dedicated compilation stages derive principal point-of-delivery (POD), detailed activity, and length-of-stay datasets from model results. These datasets then feed table builders and export functions rather than exposing raw source tables directly. Paths: `R/principal_pod_data.R`, `R/detailed_activity_data.R`, `R/principal_los_data.R`.

#### Distribution analysis pipeline
Distribution-specific preparation compiles both plot-level observations and summary-level metrics, then renders cumulative or beeswarm visualizations and formatted summary tables. This separates statistical shaping from presentation. Paths: `R/distribution_plot_data.R`, `R/distribution_summary_data.R`, `R/distribution_plots.R`.

#### Impact analysis pipeline
Impact reporting produces grouped and TPMA-oriented impact datasets and corresponding plots. It appears to combine model outcomes with geographic/label lookups, maintaining a distinct path from POD and distribution reporting. Paths: `R/impact_data.R`, `R/impact_plots.R`, `R/get_principal_pods.R`.

#### Presentation and exports
The package’s output boundary is primarily `gt` HTML tables and plot objects, with explicit export routines for compiled datasets. Shared table formatting and no-data presentation are centralized rather than repeated per report family. Paths: `R/tables.R`, `R/demo_results_tables.R`, `R/impact_plots.R`.

#### Runtime, delivery, and documentation
This is an R-package runtime intended for use inside analysts’ R sessions, not a standalone service. Azure Storage and `azkit` are material external dependencies; GitHub may supply supporting lookup/assets through retrieval helpers. Package checks and documentation publishing run through GitHub Actions: `.github/workflows/R-CMD-check.yaml`, `.github/workflows/pkgdown.yaml`; the usage-oriented guide is `vignettes/plots_tables.qmd`.

Main entry points: [`R/calculate_principal_stats.R`](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/calculate_principal_stats.R) (Shared result transforms), [`R/impact_data.R`](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/impact_data.R) (Impact data compiler), [`R/tables.R`](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/tables.R) (Tables & dataset exports), [`R/distribution_plot_data.R`](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/distribution_plot_data.R) (Distribution data compilers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Ingestion"]
  node_azure[("Azure Blob Storage<br/>external storage")]
  node_retrieval["Azure/GitHub retrieval<br/>R helpers<br/>[get_github_file.R]"]
  node_parquet_reader["Parquet results reader<br/>ingestion"]
  node_raw_results[("Model result tables<br/>tibble list")]
end

subgraph group_core["Result Compilation"]
  node_shim["Results compatibility shim<br/>normalization<br/>[shim_results.R]"]
  node_shared_transforms["Shared result transforms<br/>calculation"]
end

subgraph group_reports["Reporting Pipelines"]
  node_principal_compilers["POD, activity &amp; LOS compilers<br/>dataset compilation"]
  node_distribution_data["Distribution data compilers<br/>dataset compilation"]
  node_impact_data["Impact data compiler<br/>dataset compilation<br/>[impact_data.R]"]
  node_pod_lookup["Principal POD lookup"]
  node_distribution_views["Distribution plots &amp; tables<br/>presentation"]
  node_impact_views["Impact plots<br/>presentation<br/>[impact_plots.R]"]
end

subgraph group_delivery["Delivery"]
  node_table_export["Tables &amp; dataset exports<br/>presentation/export<br/>[tables.R]"]
  node_outputs["Tables, plots &amp; exports<br/>output boundary"]
  node_automation{{"Checks &amp; documentation publishing<br/>GitHub Actions<br/>[R-CMD-check.yaml]"}}
  node_guide["Plots and tables guide<br/>vignette<br/>[plots_tables.qmd]"]
end

node_analyst(("Analyst R session<br/>runtime"))
node_package["reskit public API<br/>R package<br/>[reskit-package.R]"]

node_analyst -->|"uses"| node_package
node_package -->|"ingests results"| node_parquet_reader
node_azure -->|"results files"| node_retrieval
node_retrieval -->|"retrieved files"| node_parquet_reader
node_parquet_reader -->|"loads"| node_raw_results
node_raw_results -->|"normalizes"| node_shim
node_shim -->|"standardized results"| node_shared_transforms
node_shared_transforms -->|"report-ready inputs"| node_principal_compilers
node_shared_transforms -->|"report-ready inputs"| node_distribution_data
node_shared_transforms -->|"report-ready inputs"| node_impact_data
node_pod_lookup -->|"labels and geography"| node_impact_data
node_distribution_data -->|"plot and summary data"| node_distribution_views
node_impact_data -->|"impact datasets"| node_impact_views
node_principal_compilers -->|"compiled datasets"| node_table_export
node_distribution_data -->|"summary datasets"| node_table_export
node_impact_data -->|"impact datasets"| node_table_export
node_distribution_views -->|"plots and tables"| node_outputs
node_impact_views -->|"plots"| node_outputs
node_table_export -->|"gt tables and exports"| node_outputs
node_automation -->|"publishes"| node_guide

click node_package "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/reskit-package.R"
click node_retrieval "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/get_github_file.R"
click node_parquet_reader "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/read_results_parquet_files.R"
click node_shim "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/shim_results.R"
click node_shared_transforms "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/calculate_principal_stats.R"
click node_principal_compilers "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/principal_pod_data.R"
click node_distribution_data "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/distribution_plot_data.R"
click node_impact_data "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/impact_data.R"
click node_pod_lookup "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/get_principal_pods.R"
click node_distribution_views "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/distribution_plots.R"
click node_impact_views "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/impact_plots.R"
click node_table_export "https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/tables.R"
click node_automation "https://github.com/the-strategy-unit/nhp_reskit/blob/main/.github/workflows/R-CMD-check.yaml"
click node_guide "https://github.com/the-strategy-unit/nhp_reskit/blob/main/vignettes/plots_tables.qmd"

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_azure,node_retrieval,node_parquet_reader,node_raw_results toneBlue
class node_shim,node_shared_transforms toneAmber
class node_principal_compilers,node_distribution_data,node_impact_data,node_pod_lookup,node_distribution_views,node_impact_views toneMint
class node_table_export,node_outputs,node_automation,node_guide toneRose
class node_analyst,node_package toneNeutral
```

## Components

### Ingestion

- **Azure Blob Storage**: external storage · Results source; credentials and endpoint are external.
- [Azure/GitHub retrieval](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/get_github_file.R): R helpers · Retrieves result files and supporting assets. · `R/get_github_file.R`
- [Parquet results reader](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/read_results_parquet_files.R): ingestion · Loads selected result tables into named tibble lists. · `R/read_results_parquet_files.R`
- **Model result tables**: tibble list

### Result Compilation

- [Results compatibility shim](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/shim_results.R): normalization · Adapts result structures for reporting. · `R/shim_results.R`
- [Shared result transforms](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/calculate_principal_stats.R): calculation · Handles empty results plus baseline and horizon calculations. · `R/calculate_principal_stats.R`

### Reporting Pipelines

- [POD, activity & LOS compilers](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/principal_pod_data.R): dataset compilation · Derives reporting datasets from normalized results. · `R/principal_pod_data.R`
- [Distribution data compilers](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/distribution_plot_data.R): dataset compilation · Creates plot observations and summary metrics. · `R/distribution_plot_data.R`
- [Impact data compiler](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/impact_data.R): dataset compilation · Builds grouped and TPMA impact datasets. · `R/impact_data.R`
- [Principal POD lookup](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/get_principal_pods.R): lookup · Supplies geographic and label context for impact reporting. · `R/get_principal_pods.R`
- [Distribution plots & tables](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/distribution_plots.R): presentation · Renders cumulative/beeswarm plots and formatted summaries. · `R/distribution_plots.R`
- [Impact plots](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/impact_plots.R): presentation · `R/impact_plots.R`

### Delivery

- [Tables & dataset exports](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/tables.R): presentation/export · Centralizes gt formatting, no-data views, and exports. · `R/tables.R`
- **Tables, plots & exports**: output boundary · gt HTML tables, plot objects, and compiled datasets.
- [Checks & documentation publishing](https://github.com/the-strategy-unit/nhp_reskit/blob/main/.github/workflows/R-CMD-check.yaml): GitHub Actions · Runs package checks and publishes documentation. · `.github/workflows/R-CMD-check.yaml`
- [Plots and tables guide](https://github.com/the-strategy-unit/nhp_reskit/blob/main/vignettes/plots_tables.qmd): vignette · `vignettes/plots_tables.qmd`

### Other components

- **Analyst R session**: runtime · Interactive package consumer.
- [reskit public API](https://github.com/the-strategy-unit/nhp_reskit/blob/main/R/reskit-package.R): R package · Exported functions and package initialization. · `R/reskit-package.R`

## Connections

- Analyst R session → reskit public API: uses
- reskit public API → Parquet results reader: ingests results
- Azure Blob Storage → Azure/GitHub retrieval: results files
- Azure/GitHub retrieval → Parquet results reader: retrieved files
- Parquet results reader → Model result tables: loads
- Model result tables → Results compatibility shim: normalizes
- Results compatibility shim → Shared result transforms: standardized results
- Shared result transforms → POD, activity & LOS compilers: report-ready inputs
- Shared result transforms → Distribution data compilers: report-ready inputs
- Shared result transforms → Impact data compiler: report-ready inputs
- Principal POD lookup → Impact data compiler: labels and geography
- Distribution data compilers → Distribution plots & tables: plot and summary data
- Impact data compiler → Impact plots: impact datasets
- POD, activity & LOS compilers → Tables & dataset exports: compiled datasets
- Distribution data compilers → Tables & dataset exports: summary datasets
- Impact data compiler → Tables & dataset exports: impact datasets
- Distribution plots & tables → Tables, plots & exports: plots and tables
- Impact plots → Tables, plots & exports: plots
- Tables & dataset exports → Tables, plots & exports: gt tables and exports
- Checks & documentation publishing → Plots and tables guide: publishes
