# medansoftware/c45-algorithm-php architecture

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

- Interactive diagram: https://gitdiagram.com/medansoftware/c45-algorithm-php
- Repository: https://github.com/medansoftware/c45-algorithm-php

## Overview

This PHP library turns tabular data into a C4.5 decision tree, then supports prediction, evaluation, and tree export. The main workflow is data ingestion and indexing, gain-based split selection, recursive tree construction, and classification. The README documents Excel, CSV, and array inputs plus multiple exports; those capabilities are represented, though their runtime wiring is inferred only where the sampled source supports it.

Main entry points: [`src/C45.php`](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45.php) (C4.5 coordinator), [`src/C45/DataInput.php`](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/DataInput.php) (DataInput), [`src/C45/Calculator/AbstractCalculator.php`](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/Calculator/AbstractCalculator.php) (Calculator base), [`src/C45/TreeNode.php`](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/TreeNode.php) (TreeNode)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Data input"]
  node_input["DataInput<br/>[DataInput.php]"]
  node_index["Value index<br/>[DataInput.php]"]
  node_api["Input interface"]
end

subgraph group_learning["Tree learning"]
  node_c45["C4.5 coordinator<br/>[C45.php]"]
  node_gain["Gain calculator<br/>[GainCalculator.php]"]
  node_split["Split-info calculator"]
  node_ratio["Gain-ratio calculator"]
  node_abstract["Calculator base"]
end

subgraph group_use["Prediction and output"]
  node_tree["TreeNode<br/>[TreeNode.php]"]
end

node_client(("PHP client"))
node_tabular["Tabular data"]
node_spreadsheet["Spreadsheet reader"]
node_results["Predictions and exports"]

node_client -->|"configures and builds"| node_c45
node_client -->|"supplies array data"| node_input
node_tabular -->|"loads file data"| node_input
node_input -.->|"reads Excel/CSV"| node_spreadsheet
node_input -->|"builds value index"| node_index
node_c45 -->|"queries rows and classes"| node_input
node_c45 -->|"requests gains"| node_gain
node_c45 -->|"requests split info"| node_split
node_c45 -->|"requests gain ratios"| node_ratio
node_gain -->|"uses shared setup"| node_abstract
node_split -->|"uses shared setup"| node_abstract
node_ratio -->|"uses shared setup"| node_abstract
node_abstract -->|"queries data"| node_input
node_c45 -->|"constructs tree"| node_tree
node_client -->|"classifies records"| node_tree
node_c45 -->|"evaluates predictions"| node_tree
node_tree -->|"returns prediction or export"| node_results

click node_input "https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/DataInput.php"
click node_index "https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/DataInput.php"
click node_api "https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/DataInput/DataInputInterface.php"
click node_c45 "https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45.php"
click node_gain "https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/Calculator/GainCalculator.php"
click node_split "https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/Calculator/SplitInfoCalculator.php"
click node_ratio "https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/Calculator/GainRatioCalculator.php"
click node_abstract "https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/Calculator/AbstractCalculator.php"
click node_tree "https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/TreeNode.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_input,node_index,node_api,node_client toneBlue
class node_c45,node_gain,node_split,node_ratio,node_abstract toneAmber
class node_tree toneMint
class node_tabular,node_spreadsheet,node_results toneIndigo
```

## Components

### Data input

- [DataInput](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/DataInput.php): `src/C45/DataInput.php`
- [Value index](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/DataInput.php): `src/C45/DataInput.php`
- [Input interface](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/DataInput/DataInputInterface.php): `src/C45/DataInput/DataInputInterface.php`

### Tree learning

- [C4.5 coordinator](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45.php): `src/C45.php`
- [Gain calculator](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/Calculator/GainCalculator.php): `src/C45/Calculator/GainCalculator.php`
- [Split-info calculator](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/Calculator/SplitInfoCalculator.php): `src/C45/Calculator/SplitInfoCalculator.php`
- [Gain-ratio calculator](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/Calculator/GainRatioCalculator.php): `src/C45/Calculator/GainRatioCalculator.php`
- [Calculator base](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/Calculator/AbstractCalculator.php): `src/C45/Calculator/AbstractCalculator.php`

### Prediction and output

- [TreeNode](https://github.com/medansoftware/c45-algorithm-php/blob/master/src/C45/TreeNode.php): `src/C45/TreeNode.php`

### Other components

- **PHP client**
- **Tabular data**
- **Spreadsheet reader**
- **Predictions and exports**

## Connections

- PHP client → C4.5 coordinator: configures and builds
- PHP client → DataInput: supplies array data
- Tabular data → DataInput: loads file data
- DataInput → Spreadsheet reader: reads Excel/CSV
- DataInput → Value index: builds value index
- C4.5 coordinator → DataInput: queries rows and classes
- C4.5 coordinator → Gain calculator: requests gains
- C4.5 coordinator → Split-info calculator: requests split info
- C4.5 coordinator → Gain-ratio calculator: requests gain ratios
- Gain calculator → Calculator base: uses shared setup
- Split-info calculator → Calculator base: uses shared setup
- Gain-ratio calculator → Calculator base: uses shared setup
- Calculator base → DataInput: queries data
- C4.5 coordinator → TreeNode: constructs tree
- PHP client → TreeNode: classifies records
- C4.5 coordinator → TreeNode: evaluates predictions
- TreeNode → Predictions and exports: returns prediction or export
