# iceteasa/unifi-ptz-better-patrol architecture

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

- Interactive diagram: https://gitdiagram.com/iceteasa/unifi-ptz-better-patrol
- Repository: https://github.com/iceteasa/unifi-ptz-better-patrol

## Overview

UniFi PTZ Better Patrol is a motion-aware patrol service for UniFi Protect PTZ cameras. An operator configures patrol behavior, then the service discovers cameras and presets, patrols those positions, and pauses or backs off for motion, tracking, or manual control. The README also documents scheduling, camera-specific overrides, automatic Protect-setting changes, re-authentication, and shutdown behavior. Source excerpts were unavailable, so implementation-level calls between scripts are not asserted; documented relationships are cited to the README, and uncertain links are marked unverified.

Main entry points: [`ptz-patrol.sh`](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/ptz-patrol.sh) (Patrol process), [`config.json.example`](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/config.json.example) (Patrol settings), [`discover.sh`](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/discover.sh) (Camera discovery), [`api.sh`](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/api.sh) (Protect API access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Configuration and control"]
  node_config["Patrol settings"]
  node_service["Systemd service<br/>[ptz-patrol.service]"]
end

subgraph group_patrol["Patrol runtime"]
  node_runner["Patrol process<br/>[ptz-patrol.sh]"]
  node_schedule["Schedule and overrides<br/>[ptz-patrol.sh]"]
  node_monitor["Activity monitoring<br/>[ptz-patrol.sh]"]
end

subgraph group_protect["Protect integration"]
  node_discovery["Camera discovery<br/>[discover.sh]"]
  node_api["Protect API access<br/>[api.sh]"]
end

node_operator(("Operator"))
node_nvr["UniFi Protect NVR"]
node_cameras["PTZ cameras"]

node_operator -->|"edits"| node_config
node_config -->|"configures"| node_runner
node_service -->|"starts or restarts"| node_runner
node_runner -.->|"discovers cameras"| node_discovery
node_runner -.->|"uses"| node_api
node_api -.->|"authenticates and requests"| node_nvr
node_discovery -.->|"finds cameras and presets"| node_nvr
node_runner -->|"moves through presets"| node_cameras
node_cameras -->|"provides activity state"| node_monitor
node_schedule -->|"limits patrol"| node_runner
node_monitor -->|"pauses or backs off"| node_runner
node_runner -->|"adjusts Protect settings"| node_nvr

click node_config "https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/config.json.example"
click node_service "https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/ptz-patrol.service"
click node_runner "https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/ptz-patrol.sh"
click node_schedule "https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/ptz-patrol.sh"
click node_monitor "https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/ptz-patrol.sh"
click node_discovery "https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/discover.sh"
click node_api "https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/api.sh"

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_config,node_service toneBlue
class node_runner,node_schedule,node_monitor toneAmber
class node_discovery,node_api toneMint
class node_operator,node_nvr,node_cameras toneIndigo
```

## Components

### Configuration and control

- [Patrol settings](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/config.json.example): `config.json.example`
- [Systemd service](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/ptz-patrol.service): `ptz-patrol.service`

### Patrol runtime

- [Patrol process](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/ptz-patrol.sh): `ptz-patrol.sh`
- [Schedule and overrides](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/ptz-patrol.sh): `ptz-patrol.sh`
- [Activity monitoring](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/ptz-patrol.sh): `ptz-patrol.sh`

### Protect integration

- [Camera discovery](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/discover.sh): `discover.sh`
- [Protect API access](https://github.com/iceteasa/unifi-ptz-better-patrol/blob/main/api.sh): `api.sh`

### Other components

- **Operator**
- **UniFi Protect NVR**
- **PTZ cameras**

## Connections

- Operator → Patrol settings: edits (evidence: `README.md`)
- Patrol settings → Patrol process: configures (evidence: `README.md`)
- Systemd service → Patrol process: starts or restarts (evidence: `README.md`)
- Patrol process → Camera discovery: discovers cameras
- Patrol process → Protect API access: uses
- Protect API access → UniFi Protect NVR: authenticates and requests
- Camera discovery → UniFi Protect NVR: finds cameras and presets
- Patrol process → PTZ cameras: moves through presets (evidence: `README.md`)
- PTZ cameras → Activity monitoring: provides activity state (evidence: `README.md`)
- Schedule and overrides → Patrol process: limits patrol (evidence: `README.md`)
- Activity monitoring → Patrol process: pauses or backs off (evidence: `README.md`)
- Patrol process → UniFi Protect NVR: adjusts Protect settings (evidence: `README.md`)
