# h4hash-ch/api-monitor architecture

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

- Interactive diagram: https://gitdiagram.com/h4hash-ch/api-monitor
- Repository: https://github.com/h4hash-ch/api-monitor

## Overview

API Monitor lets authenticated users configure endpoint monitors, then automatically checks them on a schedule and records results. The principal flow runs from the dashboard through the API to monitor storage; scheduled and manual checks then measure endpoint health, record checks, and apply incident transitions. Users can review check history, incidents, and historical statistics or generate PDF reports. The graph reflects the documented capabilities; some route and persistence details are based on README descriptions because source excerpts are partial.

Main entry points: [`src/routes/api.ts`](https://github.com/h4hash-ch/api-monitor/blob/main/src/routes/api.ts) (REST API), [`src/services/scheduler-service.ts`](https://github.com/h4hash-ch/api-monitor/blob/main/src/services/scheduler-service.ts) (Cron scheduler), [`src/services/notification-service.ts`](https://github.com/h4hash-ch/api-monitor/blob/main/src/services/notification-service.ts) (Incident notifications), [`src/repositories/monitor-repository.ts`](https://github.com/h4hash-ch/api-monitor/blob/main/src/repositories/monitor-repository.ts) (Monitor repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User interface"]
  node_dashboard["Dashboard<br/>[src.tsx]"]
end

subgraph group_api["API and access"]
  node_worker["Worker entry<br/>[index.ts]"]
  node_routes["REST API<br/>[api.ts]"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_rate["Rate limits<br/>[limit.ts]"]
end

subgraph group_monitoring["Monitoring and incidents"]
  node_scheduler["Cron scheduler"]
  node_engine["HTTP checks"]
  node_incidents["Incident transitions"]
  node_notifications["Incident notifications"]
end

subgraph group_insights["History and reporting"]
  node_statistics["Statistics"]
  node_cache["Statistics cache<br/>[cache.ts]"]
  node_reports["PDF reports<br/>[report-service.ts]"]
end

subgraph group_persistence["Persistence"]
  node_repository["Monitor repository"]
  node_database[("PostgreSQL data")]
end

node_user(("Monitor owner"))
node_endpoint{{"Monitored APIs"}}
node_webhook{{"Webhook destination"}}
node_email{{"Email provider"}}
node_supabaseauth{{"Supabase Auth"}}
node_cron(("Cloudflare Cron"))

node_user -->|"uses"| node_dashboard
node_dashboard -->|"authenticates"| node_supabaseauth
node_dashboard -->|"requests"| node_routes
node_routes -->|"authenticates"| node_auth
node_auth -->|"validates token"| node_supabaseauth
node_routes -->|"limits requests"| node_rate
node_routes -->|"manages monitors"| node_repository
node_repository -->|"reads and writes"| node_database
node_cron -->|"triggers"| node_worker
node_worker -->|"runs scheduled jobs"| node_scheduler
node_scheduler -->|"claims and records"| node_repository
node_scheduler -->|"checks monitors"| node_engine
node_engine -->|"sends HTTP request"| node_endpoint
node_scheduler -->|"applies transitions"| node_incidents
node_routes -->|"runs manual check"| node_engine
node_routes -->|"applies transitions"| node_incidents
node_incidents -->|"calls transition function"| node_database
node_scheduler -->|"dispatches events"| node_notifications
node_routes -->|"dispatches events"| node_notifications
node_notifications -.->|"posts event"| node_webhook
node_notifications -.->|"sends event"| node_email
node_notifications -->|"looks up owner email"| node_supabaseauth
node_routes -->|"builds statistics"| node_statistics
node_routes -->|"gets and puts"| node_cache
node_cache -->|"caches series"| node_statistics
node_statistics -->|"uses history inputs"| node_repository
node_routes -->|"generates PDF"| node_reports

click node_dashboard "https://github.com/h4hash-ch/api-monitor/blob/main/frontend/src.tsx"
click node_worker "https://github.com/h4hash-ch/api-monitor/blob/main/src/index.ts"
click node_routes "https://github.com/h4hash-ch/api-monitor/blob/main/src/routes/api.ts"
click node_auth "https://github.com/h4hash-ch/api-monitor/blob/main/src/lib/auth.ts"
click node_rate "https://github.com/h4hash-ch/api-monitor/blob/main/src/lib/limit.ts"
click node_repository "https://github.com/h4hash-ch/api-monitor/blob/main/src/repositories/monitor-repository.ts"
click node_database "https://github.com/h4hash-ch/api-monitor/blob/main/supabase/migration/0001_initial_schema.sql"
click node_scheduler "https://github.com/h4hash-ch/api-monitor/blob/main/src/services/scheduler-service.ts"
click node_engine "https://github.com/h4hash-ch/api-monitor/blob/main/src/services/monitoring-engine.ts"
click node_incidents "https://github.com/h4hash-ch/api-monitor/blob/main/src/services/incident-service.ts"
click node_notifications "https://github.com/h4hash-ch/api-monitor/blob/main/src/services/notification-service.ts"
click node_statistics "https://github.com/h4hash-ch/api-monitor/blob/main/src/services/statistics-service.ts"
click node_cache "https://github.com/h4hash-ch/api-monitor/blob/main/src/lib/cache.ts"
click node_reports "https://github.com/h4hash-ch/api-monitor/blob/main/src/services/report-service.ts"

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 toneBlue
class node_worker,node_routes,node_auth,node_rate toneAmber
class node_scheduler,node_engine,node_incidents,node_notifications,node_endpoint,node_webhook toneMint
class node_statistics,node_cache,node_reports toneRose
class node_repository,node_database,node_user,node_email,node_supabaseauth,node_cron toneIndigo
```

## Components

### User interface

- [Dashboard](https://github.com/h4hash-ch/api-monitor/blob/main/frontend/src.tsx): `frontend/src.tsx`

### API and access

- [Worker entry](https://github.com/h4hash-ch/api-monitor/blob/main/src/index.ts): `src/index.ts`
- [REST API](https://github.com/h4hash-ch/api-monitor/blob/main/src/routes/api.ts): `src/routes/api.ts`
- [Authentication](https://github.com/h4hash-ch/api-monitor/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Rate limits](https://github.com/h4hash-ch/api-monitor/blob/main/src/lib/limit.ts): `src/lib/limit.ts`

### Monitoring and incidents

- [Cron scheduler](https://github.com/h4hash-ch/api-monitor/blob/main/src/services/scheduler-service.ts): `src/services/scheduler-service.ts`
- [HTTP checks](https://github.com/h4hash-ch/api-monitor/blob/main/src/services/monitoring-engine.ts): `src/services/monitoring-engine.ts`
- [Incident transitions](https://github.com/h4hash-ch/api-monitor/blob/main/src/services/incident-service.ts): `src/services/incident-service.ts`
- [Incident notifications](https://github.com/h4hash-ch/api-monitor/blob/main/src/services/notification-service.ts): `src/services/notification-service.ts`

### History and reporting

- [Statistics](https://github.com/h4hash-ch/api-monitor/blob/main/src/services/statistics-service.ts): `src/services/statistics-service.ts`
- [Statistics cache](https://github.com/h4hash-ch/api-monitor/blob/main/src/lib/cache.ts): `src/lib/cache.ts`
- [PDF reports](https://github.com/h4hash-ch/api-monitor/blob/main/src/services/report-service.ts): `src/services/report-service.ts`

### Persistence

- [Monitor repository](https://github.com/h4hash-ch/api-monitor/blob/main/src/repositories/monitor-repository.ts): `src/repositories/monitor-repository.ts`
- [PostgreSQL data](https://github.com/h4hash-ch/api-monitor/blob/main/supabase/migration/0001_initial_schema.sql): `supabase/migration/0001_initial_schema.sql`

### Other components

- **Monitor owner**
- **Monitored APIs**
- **Webhook destination**
- **Email provider**
- **Supabase Auth**
- **Cloudflare Cron**

## Connections

- Monitor owner → Dashboard: uses
- Dashboard → Supabase Auth: authenticates
- Dashboard → REST API: requests
- REST API → Authentication: authenticates
- Authentication → Supabase Auth: validates token
- REST API → Rate limits: limits requests
- REST API → Monitor repository: manages monitors
- Monitor repository → PostgreSQL data: reads and writes
- Cloudflare Cron → Worker entry: triggers
- Worker entry → Cron scheduler: runs scheduled jobs
- Cron scheduler → Monitor repository: claims and records
- Cron scheduler → HTTP checks: checks monitors
- HTTP checks → Monitored APIs: sends HTTP request
- Cron scheduler → Incident transitions: applies transitions
- REST API → HTTP checks: runs manual check
- REST API → Incident transitions: applies transitions
- Incident transitions → PostgreSQL data: calls transition function
- Cron scheduler → Incident notifications: dispatches events
- REST API → Incident notifications: dispatches events
- Incident notifications → Webhook destination: posts event
- Incident notifications → Email provider: sends event
- Incident notifications → Supabase Auth: looks up owner email
- REST API → Statistics: builds statistics
- REST API → Statistics cache: gets and puts
- Statistics cache → Statistics: caches series
- Statistics → Monitor repository: uses history inputs
- REST API → PDF reports: generates PDF
