# rejohnst/promclient architecture

> Architecture diagram of the GitHub repository rejohnst/promclient, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rejohnst/promclient
- Repository: https://github.com/rejohnst/promclient

## Overview

##### Project type and purpose
- This is an open-source, command-line interface (CLI) tool (“promclient”) written in Go.
- Its sole purpose is to query and display various aspects of a Prometheus server via its HTTP API: alerts, metrics metadata, active rule status, target health, runtime configuration, and arbitrary PromQL queries.

##### File structure
- Top‐level files:
- main.go → CLI entry point (flag parsing, command dispatch)
- go.mod / go.sum / Makefile → dependency and build config
- README.md / LICENSE / .gitignore → documentation and housekeeping
- internal/ directory: each subdirectory implements one command’s logic:
- internal/alerts
- internal/metrics
- internal/query
- internal/rules
- internal/runtime
- internal/targets
- Each module contains one Go source file (e.g., alerts.go) exposing a function that:
- Builds the appropriate HTTP request
- Parses the JSON response
- Applies filters (e.g. severity, active/down, CSV output)
- Formats and prints to stdout

##### Key insights from README
- Lists six top‐level commands (alerts, metrics, query, rules, runtime, targets) each mapping 1:1 to internal subpackages.
- Common flags (–promurl, –promip, –timeout, –insecure, –verbose) are parsed centrally in main.go.
- Behavior: synchronous HTTP GET calls to Prometheus REST endpoints, then CLI output.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    User(("User (Shell)")):::user

    %% CLI Core
    FlagParser["Flag Parser"]:::cli
    Dispatcher["Command Dispatcher"]:::cli
    HTTPClient["Shared HTTP Client"]:::client

    %% Internal Modules
    subgraph "Internal Modules"
        Alerts["Alerts Module"]:::module
        Targets["Targets Module"]:::module
        Metrics["Metrics Module"]:::module
        Rules["Rules Module"]:::module
        Runtime["Runtime Module"]:::module
        Query["Query Module"]:::module
    end

    %% External Systems and Output
    Prometheus(("Prometheus Server")):::external
    Output["Stdout / Output"]:::output

    %% Connections
    User --> FlagParser
    FlagParser --> Dispatcher
    Dispatcher --> Alerts
    Dispatcher --> Targets
    Dispatcher --> Metrics
    Dispatcher --> Rules
    Dispatcher --> Runtime
    Dispatcher --> Query

    Alerts --> HTTPClient
    Targets --> HTTPClient
    Metrics --> HTTPClient
    Rules --> HTTPClient
    Runtime --> HTTPClient
    Query --> HTTPClient

    HTTPClient -->|"GET /api/v1/..."| Prometheus
    Prometheus -->|"JSON response"| HTTPClient

    HTTPClient --> Alerts
    Alerts -->|"Formatted Output"| Output
    Targets -->|"Formatted Output"| Output
    Metrics -->|"Formatted Output"| Output
    Rules -->|"Formatted Output"| Output
    Runtime -->|"Formatted Output"| Output
    Query -->|"Formatted Output"| Output

    %% Click Events
    click FlagParser "https://github.com/rejohnst/promclient/blob/main/main.go"
    click Dispatcher "https://github.com/rejohnst/promclient/blob/main/main.go"
    click HTTPClient "https://github.com/rejohnst/promclient/blob/main/main.go"
    click Alerts "https://github.com/rejohnst/promclient/blob/main/internal/alerts/alerts.go"
    click Targets "https://github.com/rejohnst/promclient/blob/main/internal/targets/targets.go"
    click Metrics "https://github.com/rejohnst/promclient/blob/main/internal/metrics/metrics.go"
    click Rules "https://github.com/rejohnst/promclient/blob/main/internal/rules/rules.go"
    click Runtime "https://github.com/rejohnst/promclient/blob/main/internal/runtime/runtime.go"
    click Query "https://github.com/rejohnst/promclient/blob/main/internal/query/query.go"

    %% Styles
    classDef user fill:#ADD8E6,stroke:#000
    classDef cli fill:#90EE90,stroke:#000
    classDef client fill:#98FB98,stroke:#000
    classDef module fill:#FFFF99,stroke:#000
    classDef external fill:#D3D3D3,stroke:#000
    classDef output fill:#F0F0F0,stroke:#000
```
