# syzio/hungarian-php architecture

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

- Interactive diagram: https://gitdiagram.com/syzio/hungarian-php
- Repository: https://github.com/syzio/hungarian-php

## Overview

This small PHP library solves a caller-supplied assignment matrix with the Hungarian algorithm and returns an immutable result object. The main workflow validates the matrix, prepares it for the selected mode and shape, computes an optimal matching, then removes dummy or forbidden assignments. The README also documents rectangular matrices, forbidden cells, and result accessors/serialization. The graph follows the sampled implementation; it omits tests and delivery tooling.

Main entry points: [`src/Hungarian.php`](https://github.com/syzio/hungarian-php/blob/main/src/Hungarian.php) (Hungarian solver), [`src/Mode.php`](https://github.com/syzio/hungarian-php/blob/main/src/Mode.php) (Solve mode), [`src/Result.php`](https://github.com/syzio/hungarian-php/blob/main/src/Result.php) (Assignment result), [`src/InvalidMatrixException.php`](https://github.com/syzio/hungarian-php/blob/main/src/InvalidMatrixException.php) (Invalid matrix error)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_caller(("Library caller"))
node_mode{{"Solve mode<br/>[Mode.php]"}}
node_solver["Hungarian solver<br/>[Hungarian.php]"]
node_validation["Matrix validation<br/>[Hungarian.php]"]
node_preparation["Matrix preparation<br/>[Hungarian.php]"]
node_algorithm["Munkres algorithm<br/>[Hungarian.php]"]
node_result["Assignment result<br/>[Result.php]"]
node_invalid["Invalid matrix error"]

node_caller -->|"submits matrix"| node_solver
node_caller -->|"selects mode"| node_mode
node_mode -->|"configures"| node_solver
node_solver -->|"validates"| node_validation
node_validation -.->|"throws"| node_invalid
node_solver -->|"prepares matrix"| node_preparation
node_solver -->|"runs matching"| node_algorithm
node_solver -->|"constructs result"| node_result
node_result -->|"returns assignments"| node_caller

click node_mode "https://github.com/syzio/hungarian-php/blob/main/src/Mode.php"
click node_solver "https://github.com/syzio/hungarian-php/blob/main/src/Hungarian.php"
click node_validation "https://github.com/syzio/hungarian-php/blob/main/src/Hungarian.php"
click node_preparation "https://github.com/syzio/hungarian-php/blob/main/src/Hungarian.php"
click node_algorithm "https://github.com/syzio/hungarian-php/blob/main/src/Hungarian.php"
click node_result "https://github.com/syzio/hungarian-php/blob/main/src/Result.php"
click node_invalid "https://github.com/syzio/hungarian-php/blob/main/src/InvalidMatrixException.php"

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_caller toneIndigo
class node_mode,node_solver,node_validation,node_preparation,node_algorithm,node_result,node_invalid toneTeal
```

## Components

### Other components

- **Library caller**
- [Solve mode](https://github.com/syzio/hungarian-php/blob/main/src/Mode.php): `src/Mode.php`
- [Hungarian solver](https://github.com/syzio/hungarian-php/blob/main/src/Hungarian.php): `src/Hungarian.php`
- [Matrix validation](https://github.com/syzio/hungarian-php/blob/main/src/Hungarian.php): `src/Hungarian.php`
- [Matrix preparation](https://github.com/syzio/hungarian-php/blob/main/src/Hungarian.php): `src/Hungarian.php`
- [Munkres algorithm](https://github.com/syzio/hungarian-php/blob/main/src/Hungarian.php): `src/Hungarian.php`
- [Assignment result](https://github.com/syzio/hungarian-php/blob/main/src/Result.php): `src/Result.php`
- [Invalid matrix error](https://github.com/syzio/hungarian-php/blob/main/src/InvalidMatrixException.php): `src/InvalidMatrixException.php`

## Connections

- Library caller → Hungarian solver: submits matrix
- Library caller → Solve mode: selects mode
- Solve mode → Hungarian solver: configures
- Hungarian solver → Matrix validation: validates
- Matrix validation → Invalid matrix error: throws
- Hungarian solver → Matrix preparation: prepares matrix
- Hungarian solver → Munkres algorithm: runs matching
- Hungarian solver → Assignment result: constructs result
- Assignment result → Library caller: returns assignments
