# spacelift-io/prometheus-exporter architecture

> Architecture diagram of the GitHub repository spacelift-io/prometheus-exporter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/spacelift-io/prometheus-exporter
- Repository: https://github.com/spacelift-io/prometheus-exporter

## Overview

##### Project Identification
- Type & Purpose: This is a standalone exporter written in Go that collects metrics from a Spacelift account (via Spacelift’s API) and exposes them in a Prometheus-compatible format.
- Key Usage Scenarios: The binary can be run directly, within a Docker container, or deployed via Kubernetes. It performs API scrapes on Spacelift and serves metrics on a designated HTTP endpoint.

##### File Structure
- Top-Level Files:
- “main.go” and “serve_command.go” likely bootstrap the service and handle command-line parsing.
- “collector.go” is expected to implement the retrieval and conversion of data from Spacelift API into metrics.
- “logging” directory provides logging functions.
- “client” directory, along with its “session” subdirectory and “structs” subdirectory, encapsulates the networking/API client logic and data structures used when interacting with the Spacelift API.
- CI/CD and release files (from .github, .golangci.yml, .goreleaser.yaml, etc.) indicate automated testing, linting, and deployment configurations.
- “Dockerfile” and “package.json” (for dependency management or ancillary tooling) are present as well.
- Architecture Indicators: The project is built as a single statically linked Go binary but organized cleanly into multiple packages:
- A Client module handling API interactions.
- A Session module to manage authentication (API key and token abstractions).
- A Collector module to aggregate Spacelift metrics.
- A Logger module for standardized logging.
- External Dependencies: Interaction with an external Spacelift API, Prometheus for metrics collection, and deployment via Docker/Kubernetes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["CI/CD & Deployment"]:::deployment
    B["HTTP Server / Service Bootstrap"]:::internal
    C["Metrics Collector"]:::internal
    D["API Client Module"]:::internal
    E["Session Manager"]:::internal
    F["Data Structures"]:::internal
    G["Spacelift API"]:::external
    H["Prometheus Scraper"]:::external
    I["Logging Module"]:::internal

    A -->|"deploys"| B
    B -->|"triggers"| C
    C -->|"calls"| D
    D -->|"authVia"| E
    D -->|"uses"| F
    D -->|"fetchesFrom"| G
    B -->|"exposesMetrics"| H

    B -->|"logs"| I
    C -->|"logs"| I
    D -->|"logs"| I

    %% Click Events
    click D "https://github.com/spacelift-io/prometheus-exporter/tree/main/client/"
    click E "https://github.com/spacelift-io/prometheus-exporter/tree/main/client/session/"
    click F "https://github.com/spacelift-io/prometheus-exporter/tree/main/client/structs/"
    click C "https://github.com/spacelift-io/prometheus-exporter/blob/main/collector.go"
    click B "https://github.com/spacelift-io/prometheus-exporter/blob/main/main.go"
    click B "https://github.com/spacelift-io/prometheus-exporter/blob/main/serve_command.go"
    click I "https://github.com/spacelift-io/prometheus-exporter/tree/main/logging/"
    click A "https://github.com/spacelift-io/prometheus-exporter/tree/main/.github/workflows/"
    click A "https://github.com/spacelift-io/prometheus-exporter/tree/main/Dockerfile"
    click A "https://github.com/spacelift-io/prometheus-exporter/blob/main/.goreleaser.yaml"

    %% Styles
    classDef internal fill:#A7D7C5,stroke:#333,stroke-width:2px;
    classDef external fill:#FFE0B3,stroke:#333,stroke-width:2px;
    classDef deployment fill:#D0E1F9,stroke:#333,stroke-width:2px;
```
