# bh-gaur/lgtm architecture

> Architecture diagram of the GitHub repository bh-gaur/lgtm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bh-gaur/lgtm
- Repository: https://github.com/bh-gaur/lgtm

## Overview

#### Purpose and Entry Points
This repository demonstrates an instrumented two-service workload backed by PostgreSQL and a self-hosted Grafana LGTM observability stack. The Node.js service is the public gateway/UI and primary request entry point; the Python service performs downstream analytics and database work. Local orchestration begins with `docker-compose.yml`; Kubernetes deployment begins with `helm/lgtm-stack/Chart.yaml`.

#### Application Boundary: Node Gateway
The Node application serves the control UI, API routes, OpenAPI documentation, and Prometheus-compatible metrics on port 8081. It initiates downstream HTTP calls to Python and propagates W3C trace context. Instrumentation is separated so `ENABLE_OBSERVABILITY` can select active OpenTelemetry versus no-op behavior.
- `apps/node-app/app.js`
- `apps/node-app/instrumentation.js`
- `apps/node-app/Dockerfile`

#### Application Boundary: Python Analytics Service
The Flask service receives gateway requests on port 5000, handles analytics operations, and connects to PostgreSQL for query/insert work. It participates in the same distributed traces and exports telemetry when observability is enabled.
- `apps/python-app/app.py`
- `apps/python-app/requirements.txt`
- `apps/python-app/Dockerfile`

#### Business Request Flow
Client traffic reaches Node first. Node handles direct operations or calls the Python service through `PYTHON_SERVICE_URL`; Python performs SQL operations against PostgreSQL. Error-injection and compute routes create representative success, latency, and failure telemetry. Compose defines the local service network and infrastructure relationships.
- `apps/node-app/app.js`
- `apps/python-app/app.py`
- `docker-compose.yml`

#### Telemetry Collection and Signal Processing
Both applications export OTLP traces, metrics, and logs to Grafana Alloy, normally via OTLP HTTP. Alloy is the central boundary between application instrumentation and telemetry backends: it receives signals, derives RED/span metrics and exemplars, then routes traces, logs, and metrics to their respective stores.
- `alloy/config.alloy`
- `helm/lgtm-stack/templates/alloy.yaml`
- `test-telemetry/send_telemetry.py`

#### LGTM Storage and Visualization
Tempo stores traces, Loki stores logs, and Mimir stores metrics; Grafana queries all three through provisioned datasources. This enables trace/log correlation and metric exemplars linking measurements to Tempo trace IDs. Their runtime configuration is standalone for Compose and rendered through Helm for Kubernetes.
- `tempo/tempo-config.yaml`
- `loki/loki-config.yaml`
- `mimir/mimir-config.yaml`
- `grafana/provisioning/datasources/datasources.yaml`

#### Deployment Models and Infrastructure
Docker Compose is the local full-stack runtime, including PostgreSQL, apps, Alloy, and LGTM services. The Helm chart packages the same architecture as Kubernetes resources, with templates for each app and telemetry backend plus configurable persistence/storage class. PostgreSQL is an external state boundary used by Python; Loki, Mimir, and Tempo are stateful observability boundaries.
- `docker-compose.yml`
- `helm/lgtm-stack/values.yaml`
- `helm/lgtm-stack/templates/node-app.yaml`
- `helm/lgtm-stack/templates/python-app.yaml`

Main entry points: [`apps/node-app/app.js`](https://github.com/bh-gaur/lgtm/blob/main/apps/node-app/app.js) (Node gateway), [`docker-compose.yml`](https://github.com/bh-gaur/lgtm/blob/main/docker-compose.yml) (Docker Compose), [`helm/lgtm-stack/Chart.yaml`](https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/Chart.yaml) (LGTM Helm chart), [`alloy/config.alloy`](https://github.com/bh-gaur/lgtm/blob/main/alloy/config.alloy) (Alloy signal processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Application services"]
  node_node["Node gateway<br/>Node.js service<br/>[app.js]"]
  node_node_instrumentation["Node instrumentation<br/>OpenTelemetry switch<br/>[instrumentation.js]"]
  node_python["Python analytics<br/>Flask service<br/>[app.py]"]
end

subgraph group_telemetry["Telemetry pipeline"]
  node_alloy_ingest{{"Alloy OTLP ingest<br/>telemetry gateway<br/>[config.alloy]"}}
  node_alloy_processing["Alloy signal processing<br/>RED/span metrics<br/>[config.alloy]"]
end

subgraph group_lgtm["LGTM platform"]
  node_tempo[("Tempo<br/>trace store<br/>[tempo-config.yaml]")]
  node_loki[("Loki<br/>log store<br/>[loki-config.yaml]")]
  node_mimir[("Mimir<br/>metric store<br/>[mimir-config.yaml]")]
  node_grafana["Grafana<br/>visualization<br/>[datasources.yaml]"]
end

subgraph group_deployment["Deployment models"]
  node_compose["Docker Compose<br/>local orchestrator<br/>[docker-compose.yml]"]
  node_helm_chart["LGTM Helm chart<br/>Kubernetes package<br/>[Chart.yaml]"]
  node_helm_values["Helm values<br/>deployment settings<br/>[values.yaml]"]
  node_node_manifest["Node workload<br/>Kubernetes template<br/>[node-app.yaml]"]
  node_python_manifest["Python workload<br/>Kubernetes template<br/>[python-app.yaml]"]
  node_alloy_manifest["Alloy workload<br/>Kubernetes template<br/>[alloy.yaml]"]
end

node_client(("Client<br/>traffic source"))
node_postgres[("PostgreSQL<br/>application database<br/>[docker-compose.yml]")]

node_client -->|"HTTP requests"| node_node
node_node -->|"PYTHON_SERVICE_URL"| node_python
node_python -->|"SQL queries/inserts"| node_postgres
node_node_instrumentation -.->|"instruments"| node_node
node_node -->|"OTLP signals"| node_alloy_ingest
node_python -->|"OTLP signals"| node_alloy_ingest
node_alloy_ingest -->|"signals"| node_alloy_processing
node_alloy_processing -->|"traces"| node_tempo
node_alloy_processing -->|"logs"| node_loki
node_alloy_processing -->|"metrics and exemplars"| node_mimir
node_grafana -->|"query traces"| node_tempo
node_grafana -->|"query logs"| node_loki
node_grafana -->|"query metrics"| node_mimir
node_compose -.->|"runs locally"| node_node
node_compose -.->|"runs locally"| node_python
node_compose -.->|"runs locally"| node_postgres
node_compose -.->|"runs locally"| node_alloy_ingest
node_helm_chart -.->|"configured by"| node_helm_values
node_helm_chart -.->|"renders"| node_node_manifest
node_helm_chart -.->|"renders"| node_python_manifest
node_helm_chart -.->|"renders"| node_alloy_manifest

click node_node "https://github.com/bh-gaur/lgtm/blob/main/apps/node-app/app.js"
click node_node_instrumentation "https://github.com/bh-gaur/lgtm/blob/main/apps/node-app/instrumentation.js"
click node_python "https://github.com/bh-gaur/lgtm/blob/main/apps/python-app/app.py"
click node_postgres "https://github.com/bh-gaur/lgtm/blob/main/docker-compose.yml"
click node_alloy_ingest "https://github.com/bh-gaur/lgtm/blob/main/alloy/config.alloy"
click node_alloy_processing "https://github.com/bh-gaur/lgtm/blob/main/alloy/config.alloy"
click node_tempo "https://github.com/bh-gaur/lgtm/blob/main/tempo/tempo-config.yaml"
click node_loki "https://github.com/bh-gaur/lgtm/blob/main/loki/loki-config.yaml"
click node_mimir "https://github.com/bh-gaur/lgtm/blob/main/mimir/mimir-config.yaml"
click node_grafana "https://github.com/bh-gaur/lgtm/blob/main/grafana/provisioning/datasources/datasources.yaml"
click node_compose "https://github.com/bh-gaur/lgtm/blob/main/docker-compose.yml"
click node_helm_chart "https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/Chart.yaml"
click node_helm_values "https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/values.yaml"
click node_node_manifest "https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/templates/node-app.yaml"
click node_python_manifest "https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/templates/python-app.yaml"
click node_alloy_manifest "https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/templates/alloy.yaml"

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_node,node_node_instrumentation,node_python toneBlue
class node_alloy_ingest,node_alloy_processing toneAmber
class node_tempo,node_loki,node_mimir,node_grafana toneMint
class node_compose,node_helm_chart,node_helm_values,node_node_manifest,node_python_manifest,node_alloy_manifest toneRose
class node_client,node_postgres toneNeutral
```

## Components

### Application services

- [Node gateway](https://github.com/bh-gaur/lgtm/blob/main/apps/node-app/app.js): Node.js service · Public UI, API, OpenAPI, and metrics endpoint on port 8081. · `apps/node-app/app.js`
- [Node instrumentation](https://github.com/bh-gaur/lgtm/blob/main/apps/node-app/instrumentation.js): OpenTelemetry switch · Selects active or no-op telemetry using ENABLE_OBSERVABILITY. · `apps/node-app/instrumentation.js`
- [Python analytics](https://github.com/bh-gaur/lgtm/blob/main/apps/python-app/app.py): Flask service · Analytics and database operations on port 5000. · `apps/python-app/app.py`

### Telemetry pipeline

- [Alloy OTLP ingest](https://github.com/bh-gaur/lgtm/blob/main/alloy/config.alloy): telemetry gateway · Receives application traces, metrics, and logs via OTLP HTTP. · `alloy/config.alloy`
- [Alloy signal processing](https://github.com/bh-gaur/lgtm/blob/main/alloy/config.alloy): RED/span metrics · Derives span metrics, RED metrics, and exemplars before export. · `alloy/config.alloy`

### LGTM platform

- [Tempo](https://github.com/bh-gaur/lgtm/blob/main/tempo/tempo-config.yaml): trace store · `tempo/tempo-config.yaml`
- [Loki](https://github.com/bh-gaur/lgtm/blob/main/loki/loki-config.yaml): log store · `loki/loki-config.yaml`
- [Mimir](https://github.com/bh-gaur/lgtm/blob/main/mimir/mimir-config.yaml): metric store · `mimir/mimir-config.yaml`
- [Grafana](https://github.com/bh-gaur/lgtm/blob/main/grafana/provisioning/datasources/datasources.yaml): visualization · Queries LGTM datasources for correlated telemetry. · `grafana/provisioning/datasources/datasources.yaml`

### Deployment models

- [Docker Compose](https://github.com/bh-gaur/lgtm/blob/main/docker-compose.yml): local orchestrator · Runs the local applications, database, Alloy, and LGTM stack. · `docker-compose.yml`
- [LGTM Helm chart](https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/Chart.yaml): Kubernetes package · Packages the stack with configurable persistence and storage. · `helm/lgtm-stack/Chart.yaml`
- [Helm values](https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/values.yaml): deployment settings · Configures chart services and persistence. · `helm/lgtm-stack/values.yaml`
- [Node workload](https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/templates/node-app.yaml): Kubernetes template · `helm/lgtm-stack/templates/node-app.yaml`
- [Python workload](https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/templates/python-app.yaml): Kubernetes template · `helm/lgtm-stack/templates/python-app.yaml`
- [Alloy workload](https://github.com/bh-gaur/lgtm/blob/main/helm/lgtm-stack/templates/alloy.yaml): Kubernetes template · `helm/lgtm-stack/templates/alloy.yaml`

### Other components

- **Client**: traffic source
- [PostgreSQL](https://github.com/bh-gaur/lgtm/blob/main/docker-compose.yml): application database · External state boundary for Python query and insert work. · `docker-compose.yml`

## Connections

- Client → Node gateway: HTTP requests
- Node gateway → Python analytics: PYTHON_SERVICE_URL · Propagates W3C trace context.
- Python analytics → PostgreSQL: SQL queries/inserts
- Node instrumentation → Node gateway: instruments
- Node gateway → Alloy OTLP ingest: OTLP signals
- Python analytics → Alloy OTLP ingest: OTLP signals
- Alloy OTLP ingest → Alloy signal processing: signals
- Alloy signal processing → Tempo: traces
- Alloy signal processing → Loki: logs
- Alloy signal processing → Mimir: metrics and exemplars
- Grafana → Tempo: query traces
- Grafana → Loki: query logs
- Grafana → Mimir: query metrics
- Docker Compose → Node gateway: runs locally
- Docker Compose → Python analytics: runs locally
- Docker Compose → PostgreSQL: runs locally
- Docker Compose → Alloy OTLP ingest: runs locally
- LGTM Helm chart → Helm values: configured by
- LGTM Helm chart → Node workload: renders
- LGTM Helm chart → Python workload: renders
- LGTM Helm chart → Alloy workload: renders
