# nhutkhanh24520782/k8s-ai-root-cause-analysis architecture

> Architecture diagram of the GitHub repository nhutkhanh24520782/k8s-ai-root-cause-analysis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nhutkhanh24520782/k8s-ai-root-cause-analysis
- Repository: https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis

## Overview

This repository implements an incident-diagnosis system around a Kubernetes microservices application: operators generate labeled incidents, observability metrics feed model training, and a prediction API returns likely causes. The graph also includes the documented GitOps deployment and monitoring capabilities. Source excerpts confirm gateway routing, database access, and ML module dependencies; several operational integrations are represented only in the README, so those edges cite it or remain unverified.

Main entry points: [`ml/src/train.py`](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/train.py) (Model Training), [`microservices/services/api-gateway/main.py`](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/microservices/services/api-gateway/main.py) (API Gateway), [`scripts/data_collection`](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/scripts/data_collection) (Metric Collection), [`monitoring/prometheus.yml`](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/monitoring/prometheus.yml) (Prometheus)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application Services"]
  node_gateway["API Gateway<br/>[main.py]"]
  node_orders["Order Service<br/>[main.py]"]
  node_payments["Payment Service<br/>[main.py]"]
  node_orderdb[("Order Database")]
  node_paymentdb[("Payment Database")]
end

subgraph group_observability["Incident Data"]
  node_faults["Fault Injection"]
  node_collection["Metric Collection"]
  node_prometheus["Prometheus<br/>[prometheus.yml]"]
  node_grafana["Grafana Dashboards"]
  node_dataset[("Metric Dataset")]
  node_s3[("S3 Data and Artifacts")]
end

subgraph group_ml["RCA Machine Learning"]
  node_loader["Dataset Loader<br/>[data_loader.py]"]
  node_features["Feature Engineering"]
  node_training["Model Training<br/>[train.py]"]
  node_evaluation["Model Evaluation<br/>[evaluate.py]"]
  node_predictor["RCA Predictor<br/>[predict.py]"]
  node_rcaapi["Prediction API"]
  node_schemas["API Schemas<br/>[schemas.py]"]
  node_mlflow["MLflow Tracking"]
end

subgraph group_platform["Cluster Platform"]
  node_k8s["Kubernetes Workloads"]
  node_argocd["ArgoCD"]
  node_overlays["Environment Overlays"]
  node_terraform["AWS EKS Infrastructure"]
end

node_operator(("Operator"))

node_operator -.->|"sends requests"| node_gateway
node_gateway -->|"proxies requests"| node_orders
node_gateway -->|"proxies requests"| node_payments
node_orders -->|"reads and writes"| node_orderdb
node_payments -->|"reads and writes"| node_paymentdb
node_operator -->|"triggers incidents"| node_faults
node_faults -->|"labels snapshots"| node_collection
node_collection -.->|"queries metrics"| node_prometheus
node_prometheus -->|"feeds dashboards"| node_grafana
node_prometheus -->|"exports snapshots"| node_s3
node_collection -.->|"produces labeled data"| node_dataset
node_s3 -->|"provides training data"| node_loader
node_dataset -.->|"loads CSV data"| node_loader
node_loader -->|"loads dataset"| node_training
node_training -->|"computes features"| node_features
node_training -->|"evaluates models"| node_evaluation
node_training -->|"tracks experiments"| node_mlflow
node_training -.->|"stores artifacts"| node_s3
node_predictor -->|"computes features"| node_features
node_rcaapi -.->|"requests inference"| node_predictor
node_rcaapi -.->|"uses contracts"| node_schemas
node_s3 -.->|"supplies model artifacts"| node_rcaapi
node_argocd -->|"reconciles workloads"| node_k8s
node_argocd -->|"reads desired state"| node_overlays
node_terraform -.->|"provisions cluster"| node_k8s

click node_gateway "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/microservices/services/api-gateway/main.py"
click node_orders "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/microservices/services/order-service/main.py"
click node_payments "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/microservices/services/payment-service/main.py"
click node_orderdb "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/kubernetes/postgres/order_db"
click node_paymentdb "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/kubernetes/postgres/payment_db"
click node_faults "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/scripts/fault_injection"
click node_collection "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/scripts/data_collection"
click node_prometheus "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/monitoring/prometheus.yml"
click node_grafana "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/monitoring/grafana-dashboards"
click node_dataset "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/ml/data"
click node_loader "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/data_loader.py"
click node_features "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/feature_engineering.py"
click node_training "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/train.py"
click node_evaluation "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/evaluate.py"
click node_predictor "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/predict.py"
click node_rcaapi "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/rca-api"
click node_schemas "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/rca-api/schemas.py"
click node_k8s "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/kubernetes/base"
click node_argocd "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/argocd/apps"
click node_overlays "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/kubernetes/overlays"
click node_terraform "https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/terraform"

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_gateway,node_orders,node_payments,node_orderdb,node_paymentdb toneBlue
class node_faults,node_collection,node_prometheus,node_grafana,node_dataset,node_s3 toneAmber
class node_loader,node_features,node_training,node_evaluation,node_predictor,node_rcaapi,node_schemas,node_mlflow toneMint
class node_k8s,node_argocd,node_overlays,node_terraform toneRose
class node_operator toneIndigo
```

## Components

### Application Services

- [API Gateway](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/microservices/services/api-gateway/main.py): `microservices/services/api-gateway/main.py`
- [Order Service](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/microservices/services/order-service/main.py): `microservices/services/order-service/main.py`
- [Payment Service](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/microservices/services/payment-service/main.py): `microservices/services/payment-service/main.py`
- [Order Database](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/kubernetes/postgres/order_db): `kubernetes/postgres/order_db`
- [Payment Database](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/kubernetes/postgres/payment_db): `kubernetes/postgres/payment_db`

### Incident Data

- [Fault Injection](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/scripts/fault_injection): `scripts/fault_injection`
- [Metric Collection](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/scripts/data_collection): `scripts/data_collection`
- [Prometheus](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/monitoring/prometheus.yml): `monitoring/prometheus.yml`
- [Grafana Dashboards](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/monitoring/grafana-dashboards): `monitoring/grafana-dashboards`
- [Metric Dataset](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/ml/data): `ml/data`
- **S3 Data and Artifacts**

### RCA Machine Learning

- [Dataset Loader](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/data_loader.py): `ml/src/data_loader.py`
- [Feature Engineering](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/feature_engineering.py): `ml/src/feature_engineering.py`
- [Model Training](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/train.py): `ml/src/train.py`
- [Model Evaluation](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/evaluate.py): `ml/src/evaluate.py`
- [RCA Predictor](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/ml/src/predict.py): `ml/src/predict.py`
- [Prediction API](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/rca-api): `rca-api`
- [API Schemas](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/blob/main/rca-api/schemas.py): `rca-api/schemas.py`
- **MLflow Tracking**

### Cluster Platform

- [Kubernetes Workloads](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/kubernetes/base): `kubernetes/base`
- [ArgoCD](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/argocd/apps): `argocd/apps`
- [Environment Overlays](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/kubernetes/overlays): `kubernetes/overlays`
- [AWS EKS Infrastructure](https://github.com/nhutkhanh24520782/k8s-ai-root-cause-analysis/tree/main/terraform): `terraform`

### Other components

- **Operator**

## Connections

- Operator → API Gateway: sends requests (evidence: `README.md`)
- API Gateway → Order Service: proxies requests (evidence: `microservices/services/api-gateway/main.py`)
- API Gateway → Payment Service: proxies requests (evidence: `microservices/services/api-gateway/main.py`)
- Order Service → Order Database: reads and writes (evidence: `microservices/services/order-service/main.py`)
- Payment Service → Payment Database: reads and writes (evidence: `microservices/services/payment-service/main.py`)
- Operator → Fault Injection: triggers incidents (evidence: `README.md`)
- Fault Injection → Metric Collection: labels snapshots (evidence: `scripts/fault_injection/run_collection_cycle.py`)
- Metric Collection → Prometheus: queries metrics
- Prometheus → Grafana Dashboards: feeds dashboards (evidence: `README.md`)
- Prometheus → S3 Data and Artifacts: exports snapshots (evidence: `README.md`)
- Metric Collection → Metric Dataset: produces labeled data
- S3 Data and Artifacts → Dataset Loader: provides training data (evidence: `README.md`)
- Metric Dataset → Dataset Loader: loads CSV data
- Dataset Loader → Model Training: loads dataset (evidence: `ml/src/train.py`)
- Model Training → Feature Engineering: computes features (evidence: `ml/src/train.py`)
- Model Training → Model Evaluation: evaluates models (evidence: `ml/src/train.py`)
- Model Training → MLflow Tracking: tracks experiments (evidence: `README.md`)
- Model Training → S3 Data and Artifacts: stores artifacts
- RCA Predictor → Feature Engineering: computes features (evidence: `ml/src/predict.py`)
- Prediction API → RCA Predictor: requests inference
- Prediction API → API Schemas: uses contracts
- S3 Data and Artifacts → Prediction API: supplies model artifacts
- ArgoCD → Kubernetes Workloads: reconciles workloads (evidence: `README.md`)
- ArgoCD → Environment Overlays: reads desired state (evidence: `README.md`)
- AWS EKS Infrastructure → Kubernetes Workloads: provisions cluster
