# igcim/pilz architecture

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

- Interactive diagram: https://gitdiagram.com/igcim/pilz
- Repository: https://github.com/igcim/pilz

## Overview

Pilzzucht is a PHP web application for monitoring and controlling a mushroom-growing environment. Users sign in, review live readings and device state, define mushroom varieties and growth-phase setpoints, and choose operating modes or manual device actions. The ESP32 reports readings through an authenticated JSON endpoint; automatic regulation and manual controls create queued commands that the device retrieves on a later report. The map reflects excerpted callers and documented behavior; unsampled login, simulator, and management flows are represented only where their responsibilities are evident, with uncertain links omitted.

Main entry points: [`config/db.php`](https://github.com/igcim/pilz/blob/main/config/db.php) (MySQL database), [`api/messung.php`](https://github.com/igcim/pilz/blob/main/api/messung.php) (Measurement API), [`index.php`](https://github.com/igcim/pilz/blob/main/index.php) (Live dashboard), [`includes/funktionen.php`](https://github.com/igcim/pilz/blob/main/includes/funktionen.php) (Command and expiry helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_login["Sign-in<br/>[login.php]"]
  node_auth["Session and CSRF<br/>[auth.php]"]
  node_dashboard["Live dashboard<br/>[index.php]"]
  node_controlui["Control settings<br/>[steuerung.php]"]
  node_simulator["ESP simulator<br/>[esp_simulator.php]"]
  node_admin["Admin creation<br/>[admin_anlegen.php]"]
  node_header["Shared navigation<br/>[header.php]"]
end

subgraph group_profiles["Cultivation profiles"]
  node_varietylist["Variety list<br/>[pilzsorten.php]"]
  node_varietyedit["Variety editor"]
end

subgraph group_control["Control logic"]
  node_rules["Automatic regulation<br/>[regelung.php]"]
  node_helpers["Command and expiry helpers<br/>[funktionen.php]"]
end

subgraph group_device["ESP interface"]
  node_api["Measurement API<br/>[messung.php]"]
  node_dummy["CLI device model<br/>[esp_dummy.php]"]
  node_key["API key config<br/>[esp.php]"]
end

subgraph group_persistence["Persistence"]
  node_database[("MySQL database<br/>[db.php]")]
end

node_user(("Grower"))
node_esp(("ESP32"))
node_externaldb[("MySQL service")]

node_user -->|"signs in"| node_login
node_login -->|"checks credentials"| node_database
node_user -->|"views status"| node_dashboard
node_dashboard -->|"requires session"| node_auth
node_dashboard -->|"reads status and history"| node_database
node_dashboard -->|"cleans expired controls"| node_helpers
node_user -->|"sets mode and devices"| node_controlui
node_controlui -->|"requires session"| node_auth
node_controlui -->|"updates control state"| node_database
node_user -->|"manages varieties"| node_varietylist
node_varietylist -->|"reads varieties"| node_database
node_varietyedit -->|"saves profiles and phases"| node_database
node_varietyedit -->|"uses session safeguards"| node_auth
node_admin -->|"creates administrator"| node_database
node_esp -->|"posts readings"| node_api
node_dummy -->|"posts simulated readings"| node_api
node_dummy -->|"loads API key"| node_key
node_api -->|"checks API key"| node_key
node_api -->|"stores readings and retrieves commands"| node_database
node_api -->|"expires controls"| node_helpers
node_api -->|"invokes automatic rules"| node_rules
node_rules -->|"queues device commands"| node_helpers
node_helpers -->|"writes command queue"| node_database
node_api -->|"returns queued commands"| node_esp
node_simulator -->|"requires session"| node_auth
node_simulator -->|"uses device key"| node_key
node_dashboard -->|"renders navigation"| node_header
node_varietyedit -->|"renders page shell"| node_header
node_database -.->|"connects to"| node_externaldb

click node_login "https://github.com/igcim/pilz/blob/main/login.php"
click node_auth "https://github.com/igcim/pilz/blob/main/includes/auth.php"
click node_dashboard "https://github.com/igcim/pilz/blob/main/index.php"
click node_controlui "https://github.com/igcim/pilz/blob/main/steuerung.php"
click node_simulator "https://github.com/igcim/pilz/blob/main/esp_simulator.php"
click node_varietylist "https://github.com/igcim/pilz/blob/main/pilzsorten.php"
click node_varietyedit "https://github.com/igcim/pilz/blob/main/pilzsorte_bearbeiten.php"
click node_admin "https://github.com/igcim/pilz/blob/main/admin_anlegen.php"
click node_api "https://github.com/igcim/pilz/blob/main/api/messung.php"
click node_dummy "https://github.com/igcim/pilz/blob/main/tools/esp_dummy.php"
click node_key "https://github.com/igcim/pilz/blob/main/config/esp.php"
click node_rules "https://github.com/igcim/pilz/blob/main/includes/regelung.php"
click node_helpers "https://github.com/igcim/pilz/blob/main/includes/funktionen.php"
click node_database "https://github.com/igcim/pilz/blob/main/config/db.php"
click node_header "https://github.com/igcim/pilz/blob/main/includes/header.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_login,node_auth,node_dashboard,node_controlui,node_simulator,node_admin,node_header toneBlue
class node_varietylist,node_varietyedit,node_externaldb toneAmber
class node_rules,node_helpers toneMint
class node_api,node_dummy,node_key toneRose
class node_database,node_user,node_esp toneIndigo
```

## Components

### Web application

- [Sign-in](https://github.com/igcim/pilz/blob/main/login.php): `login.php`
- [Session and CSRF](https://github.com/igcim/pilz/blob/main/includes/auth.php): `includes/auth.php`
- [Live dashboard](https://github.com/igcim/pilz/blob/main/index.php): `index.php`
- [Control settings](https://github.com/igcim/pilz/blob/main/steuerung.php): `steuerung.php`
- [ESP simulator](https://github.com/igcim/pilz/blob/main/esp_simulator.php): `esp_simulator.php`
- [Admin creation](https://github.com/igcim/pilz/blob/main/admin_anlegen.php): `admin_anlegen.php`
- [Shared navigation](https://github.com/igcim/pilz/blob/main/includes/header.php): `includes/header.php`

### Cultivation profiles

- [Variety list](https://github.com/igcim/pilz/blob/main/pilzsorten.php): `pilzsorten.php`
- [Variety editor](https://github.com/igcim/pilz/blob/main/pilzsorte_bearbeiten.php): `pilzsorte_bearbeiten.php`

### Control logic

- [Automatic regulation](https://github.com/igcim/pilz/blob/main/includes/regelung.php): `includes/regelung.php`
- [Command and expiry helpers](https://github.com/igcim/pilz/blob/main/includes/funktionen.php): `includes/funktionen.php`

### ESP interface

- [Measurement API](https://github.com/igcim/pilz/blob/main/api/messung.php): `api/messung.php`
- [CLI device model](https://github.com/igcim/pilz/blob/main/tools/esp_dummy.php): `tools/esp_dummy.php`
- [API key config](https://github.com/igcim/pilz/blob/main/config/esp.php): `config/esp.php`

### Persistence

- [MySQL database](https://github.com/igcim/pilz/blob/main/config/db.php): `config/db.php`

### Other components

- **Grower**
- **ESP32**
- **MySQL service**

## Connections

- Grower → Sign-in: signs in
- Sign-in → MySQL database: checks credentials (evidence: `login.php`)
- Grower → Live dashboard: views status
- Live dashboard → Session and CSRF: requires session (evidence: `index.php`)
- Live dashboard → MySQL database: reads status and history (evidence: `index.php`)
- Live dashboard → Command and expiry helpers: cleans expired controls (evidence: `index.php`)
- Grower → Control settings: sets mode and devices
- Control settings → Session and CSRF: requires session (evidence: `steuerung.php`)
- Control settings → MySQL database: updates control state (evidence: `steuerung.php`)
- Grower → Variety list: manages varieties
- Variety list → MySQL database: reads varieties (evidence: `pilzsorten.php`)
- Variety editor → MySQL database: saves profiles and phases (evidence: `pilzsorte_bearbeiten.php`)
- Variety editor → Session and CSRF: uses session safeguards (evidence: `pilzsorte_bearbeiten.php`)
- Admin creation → MySQL database: creates administrator (evidence: `admin_anlegen.php`)
- ESP32 → Measurement API: posts readings (evidence: `api/messung.php`)
- CLI device model → Measurement API: posts simulated readings (evidence: `tools/esp_dummy.php`)
- CLI device model → API key config: loads API key (evidence: `tools/esp_dummy.php`)
- Measurement API → API key config: checks API key (evidence: `api/messung.php`)
- Measurement API → MySQL database: stores readings and retrieves commands (evidence: `api/messung.php`)
- Measurement API → Command and expiry helpers: expires controls (evidence: `api/messung.php`)
- Measurement API → Automatic regulation: invokes automatic rules (evidence: `api/messung.php`)
- Automatic regulation → Command and expiry helpers: queues device commands (evidence: `includes/regelung.php`)
- Command and expiry helpers → MySQL database: writes command queue (evidence: `includes/funktionen.php`)
- Measurement API → ESP32: returns queued commands (evidence: `api/messung.php`)
- ESP simulator → Session and CSRF: requires session (evidence: `esp_simulator.php`)
- ESP simulator → API key config: uses device key (evidence: `esp_simulator.php`)
- Live dashboard → Shared navigation: renders navigation (evidence: `index.php`)
- Variety editor → Shared navigation: renders page shell (evidence: `pilzsorte_bearbeiten.php`)
- MySQL database → MySQL service: connects to (evidence: `config/db.php`)
