# bubunis/test-sre architecture

> Architecture diagram of the GitHub repository bubunis/test-sre, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bubunis/test-sre
- Repository: https://github.com/bubunis/test-sre

## Overview

This repository implements a token-issuance service: a calling backend submits an email and bearer JWT to the Python API, which authenticates and rate-limits the caller, checks permissions in Postgres, then requests token minting from the Go gRPC service. Go validates the request and lifetime, stores the expiring token in Redis, and returns it through the API. A Redis Stream supports asynchronous audit events. The README also documents Kubernetes deployment, security controls, and an OpenTelemetry/Grafana observability stack; some of those connections are documented rather than verified from sampled implementation.

Main entry points: [`python-service/main.py`](https://github.com/bubunis/test-sre/blob/main/python-service/main.py) (Python API), [`golang-service/main.go`](https://github.com/bubunis/test-sre/blob/main/golang-service/main.go) (Go gRPC service), [`observability/otel-collector/config.yaml`](https://github.com/bubunis/test-sre/blob/main/observability/otel-collector/config.yaml) (OTel collector), [`observability/grafana/provisioning/dashboards/dashboards.yaml`](https://github.com/bubunis/test-sre/blob/main/observability/grafana/provisioning/dashboards/dashboards.yaml) (Grafana dashboards)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_request["Request API"]
  node_api["Python API<br/>[main.py]"]
  node_auth["JWT verification<br/>[auth.py]"]
  node_limiter["Caller rate limit<br/>[ratelimit.py]"]
  node_dbpool["Postgres pool<br/>[db_pool.py]"]
end

subgraph group_mint["Token Issuance"]
  node_grpc["Go gRPC service<br/>[main.go]"]
  node_policy["Token input policy<br/>[email.go]"]
  node_ttl["Lifetime policy<br/>[ttl.go]"]
  node_eventworker["Audit event worker<br/>[queue.go]"]
end

subgraph group_state["Persistence"]
  node_postgres[("Permissions database<br/>[init.sql]")]
  node_redis[("Token and event store<br/>[main.go]")]
end

subgraph group_observe["Observability"]
  node_collector["OTel collector<br/>[config.yaml]"]
  node_tempo[("Trace storage<br/>[tempo.yaml]")]
  node_loki[("Log storage<br/>[loki.yaml]")]
  node_prometheus["Metrics collection<br/>[prometheus.yml]"]
  node_grafana["Grafana dashboards<br/>[dashboards.yaml]"]
end

node_caller(("Calling service"))

node_caller -->|"requests token"| node_api
node_api -->|"verifies caller"| node_auth
node_api -->|"checks quota"| node_limiter
node_api -->|"queries permissions"| node_dbpool
node_dbpool -->|"reads permissions"| node_postgres
node_api -->|"requests mint"| node_grpc
node_grpc -->|"validates email"| node_policy
node_grpc -->|"checks lifetime"| node_ttl
node_grpc -->|"stores token"| node_redis
node_grpc -->|"enqueues audit"| node_eventworker
node_eventworker -->|"reads and acknowledges"| node_redis
node_api -->|"exports telemetry"| node_collector
node_grpc -->|"exports telemetry"| node_collector
node_collector -->|"sends traces"| node_tempo
node_collector -->|"sends logs"| node_loki
node_prometheus -->|"scrapes metrics"| node_api
node_prometheus -->|"scrapes metrics"| node_grpc
node_grafana -->|"shows metrics"| node_prometheus
node_grafana -->|"shows traces"| node_tempo
node_grafana -->|"shows logs"| node_loki

click node_api "https://github.com/bubunis/test-sre/blob/main/python-service/main.py"
click node_auth "https://github.com/bubunis/test-sre/blob/main/python-service/auth.py"
click node_limiter "https://github.com/bubunis/test-sre/blob/main/python-service/ratelimit.py"
click node_dbpool "https://github.com/bubunis/test-sre/blob/main/python-service/db_pool.py"
click node_postgres "https://github.com/bubunis/test-sre/blob/main/database/init.sql"
click node_grpc "https://github.com/bubunis/test-sre/blob/main/golang-service/main.go"
click node_policy "https://github.com/bubunis/test-sre/blob/main/golang-service/internal/tokenpolicy/email.go"
click node_ttl "https://github.com/bubunis/test-sre/blob/main/golang-service/internal/tokenpolicy/ttl.go"
click node_redis "https://github.com/bubunis/test-sre/blob/main/golang-service/main.go"
click node_eventworker "https://github.com/bubunis/test-sre/blob/main/golang-service/queue.go"
click node_collector "https://github.com/bubunis/test-sre/blob/main/observability/otel-collector/config.yaml"
click node_tempo "https://github.com/bubunis/test-sre/blob/main/observability/tempo/tempo.yaml"
click node_loki "https://github.com/bubunis/test-sre/blob/main/observability/loki/loki.yaml"
click node_prometheus "https://github.com/bubunis/test-sre/blob/main/observability/prometheus/prometheus.yml"
click node_grafana "https://github.com/bubunis/test-sre/blob/main/observability/grafana/provisioning/dashboards/dashboards.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_api,node_auth,node_limiter,node_dbpool toneBlue
class node_grpc,node_policy,node_ttl,node_eventworker toneAmber
class node_postgres,node_redis toneMint
class node_collector,node_tempo,node_loki,node_prometheus,node_grafana toneRose
class node_caller toneIndigo
```

## Components

### Request API

- [Python API](https://github.com/bubunis/test-sre/blob/main/python-service/main.py): `python-service/main.py`
- [JWT verification](https://github.com/bubunis/test-sre/blob/main/python-service/auth.py): `python-service/auth.py`
- [Caller rate limit](https://github.com/bubunis/test-sre/blob/main/python-service/ratelimit.py): `python-service/ratelimit.py`
- [Postgres pool](https://github.com/bubunis/test-sre/blob/main/python-service/db_pool.py): `python-service/db_pool.py`

### Token Issuance

- [Go gRPC service](https://github.com/bubunis/test-sre/blob/main/golang-service/main.go): `golang-service/main.go`
- [Token input policy](https://github.com/bubunis/test-sre/blob/main/golang-service/internal/tokenpolicy/email.go): `golang-service/internal/tokenpolicy/email.go`
- [Lifetime policy](https://github.com/bubunis/test-sre/blob/main/golang-service/internal/tokenpolicy/ttl.go): `golang-service/internal/tokenpolicy/ttl.go`
- [Audit event worker](https://github.com/bubunis/test-sre/blob/main/golang-service/queue.go): `golang-service/queue.go`

### Persistence

- [Permissions database](https://github.com/bubunis/test-sre/blob/main/database/init.sql): `database/init.sql`
- [Token and event store](https://github.com/bubunis/test-sre/blob/main/golang-service/main.go): `golang-service/main.go`

### Observability

- [OTel collector](https://github.com/bubunis/test-sre/blob/main/observability/otel-collector/config.yaml): `observability/otel-collector/config.yaml`
- [Trace storage](https://github.com/bubunis/test-sre/blob/main/observability/tempo/tempo.yaml): `observability/tempo/tempo.yaml`
- [Log storage](https://github.com/bubunis/test-sre/blob/main/observability/loki/loki.yaml): `observability/loki/loki.yaml`
- [Metrics collection](https://github.com/bubunis/test-sre/blob/main/observability/prometheus/prometheus.yml): `observability/prometheus/prometheus.yml`
- [Grafana dashboards](https://github.com/bubunis/test-sre/blob/main/observability/grafana/provisioning/dashboards/dashboards.yaml): `observability/grafana/provisioning/dashboards/dashboards.yaml`

### Other components

- **Calling service**

## Connections

- Calling service → Python API: requests token (evidence: `README.md`)
- Python API → JWT verification: verifies caller (evidence: `python-service/main.py`)
- Python API → Caller rate limit: checks quota (evidence: `python-service/main.py`)
- Python API → Postgres pool: queries permissions (evidence: `python-service/main.py`)
- Postgres pool → Permissions database: reads permissions (evidence: `README.md`)
- Python API → Go gRPC service: requests mint (evidence: `README.md`)
- Go gRPC service → Token input policy: validates email (evidence: `golang-service/main.go`)
- Go gRPC service → Lifetime policy: checks lifetime (evidence: `golang-service/main.go`)
- Go gRPC service → Token and event store: stores token (evidence: `golang-service/main.go`)
- Go gRPC service → Audit event worker: enqueues audit (evidence: `golang-service/main.go`)
- Audit event worker → Token and event store: reads and acknowledges (evidence: `golang-service/queue.go`)
- Python API → OTel collector: exports telemetry (evidence: `README.md`)
- Go gRPC service → OTel collector: exports telemetry (evidence: `README.md`)
- OTel collector → Trace storage: sends traces (evidence: `README.md`)
- OTel collector → Log storage: sends logs (evidence: `README.md`)
- Metrics collection → Python API: scrapes metrics (evidence: `README.md`)
- Metrics collection → Go gRPC service: scrapes metrics (evidence: `README.md`)
- Grafana dashboards → Metrics collection: shows metrics (evidence: `README.md`)
- Grafana dashboards → Trace storage: shows traces (evidence: `README.md`)
- Grafana dashboards → Log storage: shows logs (evidence: `README.md`)
