# ke8vpc/river-watch architecture

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

- Interactive diagram: https://gitdiagram.com/ke8vpc/river-watch
- Repository: https://github.com/ke8vpc/river-watch

## Overview

River Watch is a standalone PHP/SQLite flood-monitoring and SITREP application. Operators manage gauges and dashboards, retain and review readings, then create event-linked SITREPs whose finalized contents are frozen. The README also documents CoCoRaHS precipitation, USGS discovery and polling, camera observations and private attachments, notifications, audit, branding, and account roles. The graph follows documented workflows and visible calls; several implementation details are unsampled, so their internal links are omitted.

Main entry points: [`public/api.php`](https://github.com/ke8vpc/river-watch/blob/main/public/api.php) (Action API), [`public/app.js`](https://github.com/ke8vpc/river-watch/blob/main/public/app.js) (Web client), [`app/operations.php`](https://github.com/ke8vpc/river-watch/blob/main/app/operations.php) (SITREP lifecycle), [`app/worker.php`](https://github.com/ke8vpc/river-watch/blob/main/app/worker.php) (Scheduled worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web monitoring"]
  node_dashboard["Dashboards<br/>[app.js]"]
  node_webclient["Web client<br/>[app.js]"]
  node_api["Action API<br/>[api.php]"]
  node_camera["Camera views<br/>[camera.js]"]
end

subgraph group_gauge["Gauge data"]
  node_gaugeadmin["Gauge management<br/>[operations.js]"]
  node_readings["Readings and history<br/>[core.php]"]
  node_usgs["USGS discovery and polling<br/>[core.php]"]
  node_rain["CoCoRaHS rainfall<br/>[rain.php]"]
end

subgraph group_events["Events and SITREPs"]
  node_events["Flood events<br/>[operations.php]"]
  node_sitrep["SITREP lifecycle<br/>[operations.php]"]
  node_reportview["Report preview and export<br/>[report.php]"]
  node_attachments["Private attachments<br/>[attachment.php]"]
  node_branding["Report branding<br/>[branding.php]"]
  node_audit["Event audit<br/>[event-audit.php]"]
end

subgraph group_ops["Operations"]
  node_worker["Scheduled worker<br/>[worker.php]"]
  node_notifications["Notifications and outbox<br/>[worker.php]"]
end

subgraph group_foundation["Application foundation"]
  node_accounts["Accounts and roles<br/>[users.php]"]
  node_sessions["Sessions<br/>[session.php]"]
  node_store[("Private SQLite data")]
end

node_operator(("Operator"))
node_usgsservice["USGS service"]
node_cocorahs["CoCoRaHS service"]
node_webhook["Webhook endpoint"]

node_operator -->|"uses"| node_webclient
node_webclient -->|"requests actions"| node_api
node_webclient -->|"refreshes"| node_dashboard
node_webclient -.->|"shows feeds"| node_camera
node_api -.->|"authenticates"| node_accounts
node_api -.->|"manages gauges"| node_gaugeadmin
node_api -.->|"records and queries"| node_readings
node_api -.->|"manages events"| node_events
node_api -.->|"saves and finalizes"| node_sitrep
node_api -.->|"configures rainfall"| node_rain
node_usgs -->|"requests data"| node_usgsservice
node_readings -->|"stores readings"| node_store
node_rain -->|"fetches reports"| node_cocorahs
node_worker -->|"polls gauges"| node_usgs
node_worker -->|"polls regions"| node_rain
node_worker -->|"evaluates alerts"| node_notifications
node_notifications -->|"delivers outbox"| node_webhook
node_sitrep -->|"renders report"| node_reportview
node_sitrep -->|"attaches images"| node_attachments
node_sitrep -.->|"uses branding"| node_branding
node_sitrep -->|"records changes"| node_audit
node_accounts -->|"validates user"| node_sessions
node_webclient -->|"signs in"| node_accounts

click node_dashboard "https://github.com/ke8vpc/river-watch/blob/main/public/app.js"
click node_webclient "https://github.com/ke8vpc/river-watch/blob/main/public/app.js"
click node_api "https://github.com/ke8vpc/river-watch/blob/main/public/api.php"
click node_camera "https://github.com/ke8vpc/river-watch/blob/main/public/camera.js"
click node_gaugeadmin "https://github.com/ke8vpc/river-watch/blob/main/public/operations.js"
click node_readings "https://github.com/ke8vpc/river-watch/blob/main/app/core.php"
click node_usgs "https://github.com/ke8vpc/river-watch/blob/main/app/core.php"
click node_rain "https://github.com/ke8vpc/river-watch/blob/main/app/rain.php"
click node_events "https://github.com/ke8vpc/river-watch/blob/main/app/operations.php"
click node_sitrep "https://github.com/ke8vpc/river-watch/blob/main/app/operations.php"
click node_reportview "https://github.com/ke8vpc/river-watch/blob/main/public/report.php"
click node_attachments "https://github.com/ke8vpc/river-watch/blob/main/public/attachment.php"
click node_branding "https://github.com/ke8vpc/river-watch/blob/main/app/branding.php"
click node_audit "https://github.com/ke8vpc/river-watch/blob/main/app/event-audit.php"
click node_accounts "https://github.com/ke8vpc/river-watch/blob/main/app/users.php"
click node_sessions "https://github.com/ke8vpc/river-watch/blob/main/app/session.php"
click node_worker "https://github.com/ke8vpc/river-watch/blob/main/app/worker.php"
click node_notifications "https://github.com/ke8vpc/river-watch/blob/main/app/worker.php"
click node_store "https://github.com/ke8vpc/river-watch/tree/main/data"

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_dashboard,node_webclient,node_api,node_camera toneBlue
class node_gaugeadmin,node_readings,node_usgs,node_rain toneAmber
class node_events,node_sitrep,node_reportview,node_attachments,node_branding,node_audit,node_webhook toneMint
class node_worker,node_notifications toneRose
class node_accounts,node_sessions,node_store,node_operator,node_usgsservice,node_cocorahs toneIndigo
```

## Components

### Web monitoring

- [Dashboards](https://github.com/ke8vpc/river-watch/blob/main/public/app.js): `public/app.js`
- [Web client](https://github.com/ke8vpc/river-watch/blob/main/public/app.js): `public/app.js`
- [Action API](https://github.com/ke8vpc/river-watch/blob/main/public/api.php): `public/api.php`
- [Camera views](https://github.com/ke8vpc/river-watch/blob/main/public/camera.js): `public/camera.js`

### Gauge data

- [Gauge management](https://github.com/ke8vpc/river-watch/blob/main/public/operations.js): `public/operations.js`
- [Readings and history](https://github.com/ke8vpc/river-watch/blob/main/app/core.php): `app/core.php`
- [USGS discovery and polling](https://github.com/ke8vpc/river-watch/blob/main/app/core.php): `app/core.php`
- [CoCoRaHS rainfall](https://github.com/ke8vpc/river-watch/blob/main/app/rain.php): `app/rain.php`

### Events and SITREPs

- [Flood events](https://github.com/ke8vpc/river-watch/blob/main/app/operations.php): `app/operations.php`
- [SITREP lifecycle](https://github.com/ke8vpc/river-watch/blob/main/app/operations.php): `app/operations.php`
- [Report preview and export](https://github.com/ke8vpc/river-watch/blob/main/public/report.php): `public/report.php`
- [Private attachments](https://github.com/ke8vpc/river-watch/blob/main/public/attachment.php): `public/attachment.php`
- [Report branding](https://github.com/ke8vpc/river-watch/blob/main/app/branding.php): `app/branding.php`
- [Event audit](https://github.com/ke8vpc/river-watch/blob/main/app/event-audit.php): `app/event-audit.php`

### Operations

- [Scheduled worker](https://github.com/ke8vpc/river-watch/blob/main/app/worker.php): `app/worker.php`
- [Notifications and outbox](https://github.com/ke8vpc/river-watch/blob/main/app/worker.php): `app/worker.php`

### Application foundation

- [Accounts and roles](https://github.com/ke8vpc/river-watch/blob/main/app/users.php): `app/users.php`
- [Sessions](https://github.com/ke8vpc/river-watch/blob/main/app/session.php): `app/session.php`
- [Private SQLite data](https://github.com/ke8vpc/river-watch/tree/main/data): `data`

### Other components

- **Operator**
- **USGS service**
- **CoCoRaHS service**
- **Webhook endpoint**

## Connections

- Operator → Web client: uses (evidence: `README.md`)
- Web client → Action API: requests actions (evidence: `public/app.js`)
- Web client → Dashboards: refreshes (evidence: `public/app.js`)
- Web client → Camera views: shows feeds
- Action API → Accounts and roles: authenticates
- Action API → Gauge management: manages gauges
- Action API → Readings and history: records and queries
- Action API → Flood events: manages events
- Action API → SITREP lifecycle: saves and finalizes
- Action API → CoCoRaHS rainfall: configures rainfall
- USGS discovery and polling → USGS service: requests data (evidence: `app/core.php`)
- Readings and history → Private SQLite data: stores readings (evidence: `app/core.php`)
- CoCoRaHS rainfall → CoCoRaHS service: fetches reports (evidence: `README.md`)
- Scheduled worker → USGS discovery and polling: polls gauges (evidence: `app/worker.php`)
- Scheduled worker → CoCoRaHS rainfall: polls regions (evidence: `app/worker.php`)
- Scheduled worker → Notifications and outbox: evaluates alerts (evidence: `app/worker.php`)
- Notifications and outbox → Webhook endpoint: delivers outbox (evidence: `app/worker.php`)
- SITREP lifecycle → Report preview and export: renders report (evidence: `README.md`)
- SITREP lifecycle → Private attachments: attaches images (evidence: `README.md`)
- SITREP lifecycle → Report branding: uses branding
- SITREP lifecycle → Event audit: records changes
- Accounts and roles → Sessions: validates user (evidence: `app/session.php`)
- Web client → Accounts and roles: signs in (evidence: `public/app.js`)
