# dilermando-lima/springboot-grafana-prometheus-loki architecture

> Architecture diagram of the GitHub repository dilermando-lima/springboot-grafana-prometheus-loki, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dilermando-lima/springboot-grafana-prometheus-loki
- Repository: https://github.com/dilermando-lima/springboot-grafana-prometheus-loki

## Overview

##### Project Type and Purpose
- This is a multi-module Java Spring Boot setup demonstrating how to monitor logs and metrics across separate REST applications.
- It uses three independently deployable services (“api-1”, “api-2”, “runner-1”) plus a Docker-Compose observability stack (Prometheus, Loki, Grafana).

##### File Structure
- Top-level modules:
- api-1/ (Spring Boot microservice #1)
- api-2/ (Spring Boot microservice #2)
- runner-1/ (Spring Boot client or orchestrator that invokes APIs)
- docker/: contains Prometheus, Loki, and Grafana configuration and compose file.
- Shared Gradle build at the root orchestrates all sub-projects.

##### Extract Key Architectural Insights from README
- Each Spring Boot app exposes REST endpoints and Spring Actuator metrics.
- Docker Compose runs three observability services:
- Prometheus scrapes metrics from each Spring Boot app.
- Loki collects logs from the Spring Boot apps.
- Grafana visualizes both metrics (from Prometheus) and logs (from Loki).

##### Main Components
a. Spring Boot Services (api-1, api-2, runner-1)
- Each is a separate JVM process/container.
- Exposes HTTP endpoints and Actuator `/metrics` and `/log` endpoints.
b. Docker-Compose Observability Stack
- Prometheus
- Loki
- Grafana
c. External Users / Clients
- A developer or test harness interacting with runner-1 (and possibly directly with api-1/api-2).

##### Relationships & Data Flows
- External User → HTTP → runner-1
- runner-1 → HTTP → api-1 and api-2
- Each Spring Boot app → HTTP (Actuator scraping) → Prometheus
- Each Spring Boot app → Log shipping (via Docker driver or sidecar) → Loki
- Grafana → Queries → Prometheus & Loki → Displays dashboards

##### Architectural Patterns & Design Principles
- Microservices pattern: each API as an independent service.
- Observability pipeline pattern: instrumentation (Actuator) → metric/log collector → storage → visualization.
- Separation of concerns: business logic vs. monitoring infrastructure.

##### Technologies & Frameworks
- Java Spring Boot with Spring Actuator
- Gradle multi-module build
- Docker Compose
- prometheus.yml
- loki config
- grafana
- Grafana dashboards (e.g. template 4701 for JVM/HTTP metrics)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actor
    User["External User/Test Harness"]:::external

    %% Codebase Layer
    subgraph "Codebase"  
        direction TB
        RootBuild["build.gradle"]  
        Settings["settings.gradle"]  
        README["README.md"]  
        Gitignore[".gitignore"]  
        subgraph "api-1 (REST + Actuator)"  
            direction TB
            API1App["App.java"]:::spring  
            API1Controller["Controller.java"]:::spring  
            API1ConfigApp["application.properties"]  
            API1ConfigLog["logback-spring.xml"]  
        end  
        subgraph "api-2 (REST + Actuator)"  
            direction TB
            API2App["App.java"]:::spring  
            API2Controller["Controller.java"]:::spring  
            API2ConfigApp["application.properties"]  
            API2ConfigLog["logback-spring.xml"]  
        end  
        subgraph "runner-1 (Orchestrator + Actuator)"  
            direction TB
            RunnerApp["App.java"]:::spring  
            RunnerBuild["build.gradle"]  
        end  
    end

    %% Runtime Services
    RunnerService["runner-1 Service"]:::spring
    API1Service["api-1 Service"]:::spring
    API2Service["api-2 Service"]:::spring

    %% Monitoring Stack
    subgraph "Monitoring"  
        direction TB
        Prometheus["Prometheus"]:::monitoring
        Loki["Loki"]:::monitoring
        Grafana["Grafana"]:::monitoring
    end

    %% Interactions
    User -->|"HTTP 8080"| RunnerService
    RunnerService -->|"HTTP 8081/call api-1"| API1Service
    RunnerService -->|"HTTP 8082/call api-2"| API2Service

    API1Service -->|"metrics /actuator/prometheus"| Prometheus
    API2Service -->|"metrics /actuator/prometheus"| Prometheus
    RunnerService -->|"metrics /actuator/prometheus"| Prometheus

    API1Service -.->|"logs via Docker"| Loki
    API2Service -.->|"logs via Docker"| Loki
    RunnerService -.->|"logs via Docker"| Loki

    Grafana -->|"query metrics"| Prometheus
    Grafana -->|"query logs"| Loki

    %% Build associations
    RootBuild --> API1App
    RootBuild --> API2App
    RootBuild --> RunnerApp
    Settings --> API1App
    Settings --> API2App
    Settings --> RunnerApp

    %% Click Events
    click API1App "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/api-1/src/api1/App.java"
    click API1Controller "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/api-1/src/api1/Controller.java"
    click API1ConfigApp "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/api-1/src-r/application.properties"
    click API1ConfigLog "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/api-1/src-r/logback-spring.xml"
    click API2App "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/api-2/src/api2/App.java"
    click API2Controller "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/api-2/src/api2/Controller.java"
    click API2ConfigApp "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/api-2/src-r/application.properties"
    click API2ConfigLog "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/api-2/src-r/logback-spring.xml"
    click RunnerApp "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/runner-1/src/runner1/App.java"
    click RunnerBuild "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/runner-1/build.gradle"
    click RootBuild "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/build.gradle"
    click Settings "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/settings.gradle"
    click Compose "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/docker/docker-compose.yml"
    click PromConf "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/docker/prometheus.yml"
    click README "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/README.md"
    click Gitignore "https://github.com/dilermando-lima/springboot-grafana-prometheus-loki/blob/main/.gitignore"

    %% Styles
    classDef spring fill:#87CEFA,stroke:#000,stroke-width:1px
    classDef monitoring fill:#98FB98,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
