# bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager architecture

> Architecture diagram of the GitHub repository bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager
- Repository: https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager

## Overview

##### Project Type and Purpose
- This is a full-stack, container-based orchestration project combining:
- An API Gateway (Kong)
- A sample microservice (NestJS) exposing public & JWT-protected routes
- A reverse proxy / SSL termination layer (NGINX + Certbot)
- A complete observability stack (Prometheus, Grafana, Alertmanager, Blackbox Exporter)
- Alerting via SMTP email
- The goal is to route client traffic through NGINX → Kong → NestJS, while collecting metrics, visualizing dashboards, and sending alerts.

##### File-Structure Analysis
- Top level:
- docker-compose.yml – service orchestration
- init-letsencrypt.sh & certbot configs – SSL certificate bootstrap
- public.key & .env.example – JWT and email settings
- Service directories:
- kong/ (kong.conf, kong.yml) – gateway config
- nginx/ (nginx.conf) – reverse proxy config
- nestjs-service/ – NestJS code, Dockerfile, routes under src/public & src/protected
- prometheus/ (prometheus.yml, alert.rules.yml)
- grafana/ (provisioning dashboards & datasources)
- alertmanager/ (alertmanager.yml, routing, SMTP settings)
- blackbox/ (blackbox.yml)

##### README Insights
Client → HTTPS → NGINX → Kong → NestJS
└─/metrics→ Prometheus → Alertmanager → Email
└→ Grafana → Admin
- Lists service ports, security approach (JWT RS256), and SSL setup steps.

##### Main Components
a. Edge Layer
- Client (Browser or External Consumer)
- Domain DNS / hosts file (midominio.com)
b. Ingress / SSL Termination
- NGINX container (80/443) with Certbot hooks
c. API Gateway
- Kong container (public proxy on 8000/8443, admin on 8001/8444)
- JWT plugin configured (public vs protected routes)
d. Microservice
- NestJS service (port 3000 inside Docker)
- PublicController & ProtectedController
e. Observability
- Prometheus server scraping:
- Kong (/metrics)
- NestJS metrics if exposed
- Blackbox Exporter (9115)
- Alertmanager (9093) routing alerts via SMTP
- Grafana (3001) dashboards provisioned for Kong/Prometheus
f. External Systems
- SMTP server (e.g., Gmail)
- Certbot ACME endpoint

##### Relationships and Data Flows
Client → (HTTPS) → NGINX → (proxy_pass) → Kong → NestJS
Kong → (metrics endpoint) → Prometheus
Prometheus → Alertmanager → (email alerts) → User
Prometheus → Grafana → Administrator
Prometheus → Blackbox Exporter → target endpoints (HTTP(s) health checks)
- Docker network links implicitly connecting all containers.

##### Architectural Patterns & Principles
- Edge-Gateway-Backend separation
- Microservices behind an API Gateway
- Side-car-style observability (Prometheus + exporters)
- Declarative provisioning (Grafana dashboards via YAML)
- Infrastructure as Code (docker-compose, shell scripts)

##### Detail Checklist
- Following elements:
- Client / DNS entry
- NGINX + Certbot
- Kong (public vs admin APIs)
- NestJS microservice (public & protected endpoints)
- Prometheus & Blackbox Exporter
- Alertmanager → SMTP
- Grafana Dashboard
- Don’t overthink: break the system into as many meaningful components as possible and represent each separately.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Edge Layer
    subgraph "Edge Layer"
        direction TB
        Client["Client (Browser)"]:::request
        DNS["DNS / hosts (midominio.com)"]:::aux
    end

    %% Ingress / SSL Termination
    subgraph "Ingress / SSL Termination"
        direction TB
        NGINX["NGINX SSL Termination\n(80/443)"]:::request
        Certbot["Certbot Hook"]:::aux
    end

    %% API Gateway
    subgraph "API Gateway"
        direction TB
        Kong["Kong Gateway\n(public:8000/8443\nadmin:8001/8444)"]:::request
    end

    %% Microservice
    subgraph "Business Service"
        direction TB
        NestJS["NestJS Service\n(port 3000)"]:::request
    end

    %% Observability & Alerting
    subgraph "Observability Stack"
        direction TB
        Prometheus["Prometheus\n(port 9090)"]:::metrics
        Blackbox["Blackbox Exporter\n(9115)"]:::metrics
        Grafana["Grafana\n(port 3001)"]:::metrics
        Alertmanager["Alertmanager\n(9093)"]:::alert
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        SMTP["SMTP Server"]:::aux
        ACME["Certbot ACME Endpoint"]:::aux
    end

    %% Connections - Request Path (Green)
    Client -->|HTTPS| NGINX
    DNS -->|resolves to| NGINX
    NGINX -->|proxy_pass| Kong
    Kong -->|proxy_pass| NestJS

    %% Connections - Metrics Path (Blue)
    Kong -->|/metrics| Prometheus
    Blackbox -->|metrics scrape| Prometheus
    Prometheus -->|data| Grafana
    Prometheus -->|alerts| Alertmanager

    %% Connections - Alert Notifications (Orange)
    Alertmanager -->|email alerts| SMTP

    %% Connections - Auxiliary (Gray)
    Certbot -->|ACME challenge| ACME
    Certbot -->|updates certs| NGINX

    %% Click Events
    click NGINX "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/nginx/nginx.conf"
    click Certbot "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/init-letsencrypt.sh"
    click Kong "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/kong/kong.conf"
    click Kong "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/kong/kong.yml"
    click NestJS "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/tree/main/nestjs-service/Dockerfile"
    click NestJS "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/nestjs-service/src/main.ts"
    click NestJS "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/nestjs-service/src/app.module.ts"
    click NestJS "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/nestjs-service/src/public/public.controller.ts"
    click NestJS "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/nestjs-service/src/protected/protected.controller.ts"
    click NestJS "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/nestjs-service/package.json"
    click Prometheus "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/prometheus/prometheus.yml"
    click Prometheus "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/prometheus/alert.rules.yml"
    click Blackbox "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/blackbox/blackbox.yml"
    click Grafana "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/grafana/provisioning/datasources/prometheus.yml"
    click Grafana "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/grafana/provisioning/dashboards/dashboards.yml"
    click Grafana "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/grafana/provisioning/dashboards/kong-dashboard.json"
    click Alertmanager "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/alertmanager/alertmanager.yml"
    click Alertmanager "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/alertmanager/entrypoint.sh"
    click Alertmanager "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/tree/main/alertmanager/Dockerfile"
    click ACME "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/public.key"
    click SMSM "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/.env.example"
    click _ "https://github.com/bpabon/api-gateway-kong-grafana-prometheus-nginx-alertmanager/blob/main/docker-compose.yml"

    %% Styles
    classDef request fill:#e0ffe0,stroke:#2d7a2d,stroke-width:1px
    classDef metrics fill:#e0f0ff,stroke:#1e4f8a,stroke-width:1px
    classDef alert fill:#fff0e0,stroke:#a85a00,stroke-width:1px
    classDef aux fill:#f5f5f5,stroke:#666666,stroke-width:1px
```
