# bhaskar-2001/aiops-anomaly-detector-for-kubernetes architecture

> Architecture diagram of the GitHub repository bhaskar-2001/aiops-anomaly-detector-for-kubernetes, 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/bhaskar-2001/aiops-anomaly-detector-for-kubernetes
- Repository: https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes

## Overview

This repository is a Kubernetes AIOps monitoring system: a sample Flask workload exposes Prometheus metrics, the detector polls those metrics and identifies deviations from clean rolling baselines, then diagnoses anomalies and sends cooldown-controlled Slack alerts. Its documented workflow also includes Prometheus/Grafana monitoring and synthetic load/leak routes for exercising detection. The detector source shows the polling, scoring, diagnosis, and alerting calls; scrape and deployment relationships come from the README, since their configuration files were not sampled.

Main entry points: [`detector/anomaly_detector.py`](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py) (Polling loop), [`sample-app/app.py`](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/sample-app/app.py) (Flask workload), [`monitoring-values.yaml`](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/monitoring-values.yaml) (Prometheus)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workload["Sample workload"]
  node_app["Flask workload<br/>[app.py]"]
  node_test_routes["Load and leak routes<br/>[app.py]"]
  node_metrics_endpoint["Metrics endpoint<br/>[app.py]"]
end

subgraph group_monitoring["Monitoring stack"]
  node_prometheus[("Prometheus")]
  node_grafana["Grafana"]
end

subgraph group_detection["Detection engine"]
  node_detector_loop["Polling loop"]
  node_prom_query["PromQL queries"]
  node_baseline["Rolling baseline"]
  node_anomaly_rules["Anomaly scoring"]
  node_diagnosis["Root-cause rules"]
end

subgraph group_notification["Alerting"]
  node_cooldown["Alert cooldown"]
  node_alert_format["Alert formatting"]
  node_slack["Slack webhook"]
end

node_operator(("Operator / traffic"))

node_operator -->|"sends traffic"| node_app
node_operator -->|"triggers tests"| node_test_routes
node_test_routes -->|"exercises workload"| node_app
node_app -->|"exposes metrics"| node_metrics_endpoint
node_prometheus -->|"scrapes"| node_metrics_endpoint
node_detector_loop -->|"queries metrics"| node_prom_query
node_prom_query -->|"reads via PromQL"| node_prometheus
node_detector_loop -->|"scores samples"| node_baseline
node_baseline -->|"flags deviations"| node_anomaly_rules
node_detector_loop -->|"diagnoses anomalies"| node_diagnosis
node_detector_loop -->|"submits alerts"| node_cooldown
node_cooldown -->|"formats eligible alerts"| node_alert_format
node_alert_format -->|"posts webhook"| node_slack
node_alert_format -->|"includes investigation link"| node_grafana

click node_app "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/sample-app/app.py"
click node_test_routes "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/sample-app/app.py"
click node_metrics_endpoint "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/sample-app/app.py"
click node_prometheus "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/monitoring-values.yaml"
click node_grafana "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/monitoring-values.yaml"
click node_detector_loop "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py"
click node_prom_query "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py"
click node_baseline "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py"
click node_anomaly_rules "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py"
click node_diagnosis "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py"
click node_cooldown "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py"
click node_alert_format "https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py"

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_app,node_test_routes,node_metrics_endpoint toneBlue
class node_prometheus,node_grafana toneAmber
class node_detector_loop,node_prom_query,node_baseline,node_anomaly_rules,node_diagnosis toneMint
class node_cooldown,node_alert_format,node_slack toneRose
class node_operator toneIndigo
```

## Components

### Sample workload

- [Flask workload](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/sample-app/app.py): `sample-app/app.py`
- [Load and leak routes](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/sample-app/app.py): `sample-app/app.py`
- [Metrics endpoint](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/sample-app/app.py): `sample-app/app.py`

### Monitoring stack

- [Prometheus](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/monitoring-values.yaml): `monitoring-values.yaml`
- [Grafana](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/monitoring-values.yaml): `monitoring-values.yaml`

### Detection engine

- [Polling loop](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py): `detector/anomaly_detector.py`
- [PromQL queries](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py): `detector/anomaly_detector.py`
- [Rolling baseline](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py): `detector/anomaly_detector.py`
- [Anomaly scoring](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py): `detector/anomaly_detector.py`
- [Root-cause rules](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py): `detector/anomaly_detector.py`

### Alerting

- [Alert cooldown](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py): `detector/anomaly_detector.py`
- [Alert formatting](https://github.com/bhaskar-2001/aiops-anomaly-detector-for-kubernetes/blob/main/detector/anomaly_detector.py): `detector/anomaly_detector.py`
- **Slack webhook**

### Other components

- **Operator / traffic**

## Connections

- Operator / traffic → Flask workload: sends traffic (evidence: `README.md`)
- Operator / traffic → Load and leak routes: triggers tests (evidence: `README.md`)
- Load and leak routes → Flask workload: exercises workload (evidence: `sample-app/app.py`)
- Flask workload → Metrics endpoint: exposes metrics (evidence: `sample-app/app.py`)
- Prometheus → Metrics endpoint: scrapes (evidence: `README.md`)
- Polling loop → PromQL queries: queries metrics (evidence: `detector/anomaly_detector.py`)
- PromQL queries → Prometheus: reads via PromQL (evidence: `detector/anomaly_detector.py`)
- Polling loop → Rolling baseline: scores samples (evidence: `detector/anomaly_detector.py`)
- Rolling baseline → Anomaly scoring: flags deviations (evidence: `detector/anomaly_detector.py`)
- Polling loop → Root-cause rules: diagnoses anomalies (evidence: `detector/anomaly_detector.py`)
- Polling loop → Alert cooldown: submits alerts (evidence: `detector/anomaly_detector.py`)
- Alert cooldown → Alert formatting: formats eligible alerts (evidence: `detector/anomaly_detector.py`)
- Alert formatting → Slack webhook: posts webhook (evidence: `detector/anomaly_detector.py`)
- Alert formatting → Grafana: includes investigation link (evidence: `detector/anomaly_detector.py`)
