# policyengine/policyengine-uk architecture

> Architecture diagram of the GitHub repository policyengine/policyengine-uk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/policyengine/policyengine-uk
- Repository: https://github.com/policyengine/policyengine-uk

## Overview

##### Main modules
- Input/Pre-processing Layer: Represent the collection and fusion of microdata (e.g. the Family Resources Survey and other datasets), including the reweighting process.
- Parameters Module: This is where all system rates, thresholds, and other static elements reside. The “parameters” subfolder (with its extensive substructure for different government departments such as gov, hmrc, dwp, etc.) is a key component.
- Variables Module: Contains all formulas, rules, and calculations that relate the parameters, economic factors, and household data. This folder encapsulates the core computation logic that transforms inputs into outputs.
- Reforms Module: Captures alternative policy scenarios. This module defines how reforms are integrated and run alongside baseline calculations.
- Core Simulation Engine: Located in the “policyengine_uk” folder and through scripts in system.py or repo.py, this engine orchestrates the simulation run. It interacts with the input data, loads parameters and variables, and applies reforms.

##### Relationships and interactions
- Data Input feeds into a Data Pre-processing Unit that cleans and fuses the microdata.
- The Pre-processed data is then passed to the Simulation Engine.
- The Engine retrieves system parameters from the “parameters” module and computation formulas from the “variables” module.
- Reform options (from the “reforms” module) can override or alter default behavior in the simulation.
- Final outputs (simulation results, policy outcome metrics) are produced after processing the data through the calculation engine.
- The testing framework validates behaviors at each step.

##### Architectural patterns
- Separation of concerns is evident: one set of modules solely defines static policy parameters, another encapsulates formula computations, and another handles reforms.

##### Technologies and frameworks
- That the project leverages the PolicyEngine Core framework and is based on OpenFisca—this may be indicated externally.

##### Final advice
- Since the project is a full-fledged microsimulation tool, emphasize the separation between configuration (parameters/variables), simulation logic, and data input/output.

## Diagram (Mermaid)

```mermaid
flowchart TD
    ED["External Data Sources"]:::dataStyle
    IP["Input/Pre-processing Layer"]:::inputStyle
    SE["Core Simulation Engine"]:::simulationStyle
    PA["Parameters Repository"]:::configStyle
    VA["Variables/Formula Engine"]:::configStyle
    RF["Reforms Module"]:::reformStyle
    OP["Output Generator"]:::simulationStyle
    TS["Testing and Validation"]:::testStyle

    ED --> IP
    IP --> SE
    SE --> OP
    SE -->|"gets_params"| PA
    SE -->|"gets_vars"| VA
    SE -->|"applies"| RF
    PA -->|"tested_by"| TS
    VA -->|"tested_by"| TS
    SE -->|"tested_by"| TS

    classDef dataStyle fill:#FFF176,stroke:#333,stroke-width:2px,color:#000;
    classDef inputStyle fill:#81D4FA,stroke:#333,stroke-width:2px,color:#000;
    classDef simulationStyle fill:#FFCC80,stroke:#333,stroke-width:2px,color:#000;
    classDef configStyle fill:#A5D6A7,stroke:#333,stroke-width:2px,color:#000;
    classDef reformStyle fill:#CE93D8,stroke:#333,stroke-width:2px,color:#000;
    classDef testStyle fill:#90CAF9,stroke:#333,stroke-width:2px,color:#000;

    click IP "https://github.com/policyengine/policyengine-uk/tree/master/policyengine_uk/variables/input"
    click PA "https://github.com/policyengine/policyengine-uk/tree/master/policyengine_uk/parameters"
    click VA "https://github.com/policyengine/policyengine-uk/tree/master/policyengine_uk/variables"
    click RF "https://github.com/policyengine/policyengine-uk/tree/master/policyengine_uk/reforms"
    click SE "https://github.com/policyengine/policyengine-uk/blob/master/policyengine_uk/system.py"
    click SE "https://github.com/policyengine/policyengine-uk/blob/master/policyengine_uk/repo.py"
    click TS "https://github.com/policyengine/policyengine-uk/tree/master/policyengine_uk/tests"
```
