# tape4/spring-cicd-template architecture

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

- Interactive diagram: https://gitdiagram.com/tape4/spring-cicd-template
- Repository: https://github.com/tape4/spring-cicd-template

## Overview

1. Nginx – acting as the front door for HTTP requests and managing load balancing and routing between multiple Spring Application instances.
2. Spring Boot Applications – running as two separate instances to support a zero-downtime deployment via rolling updates.
##### Storage and Cache – comprising MariaDB (for persistent data) and Redis (for caching).
4. Monitoring and Logging – which includes Prometheus (recording metrics), Grafana (displaying dashboards), and Loki (handling log aggregation).

The project also contains dedicated directories and scripts to manage infrastructure (such as launching or shutting down services and executing rolling updates).

##### Main Components
- Frontend Gateway: Represented by Nginx (including an additional Nginx-status component for monitoring).
- Backend Services: Include MariaDB and Redis as the system’s data persistence and caching backend.
- External User: Indicate an external “User” node showing the entry point of HTTP requests into the system.

##### Relationships and Data Flows
- How the Spring Boot application(s) emit metrics or log data to Prometheus and Loki, which in turn feed into Grafana for visualization.
- Additional interactions where the Spring applications query or update data in MariaDB and use Redis for caching.

##### Architectural Patterns and Design Principles
- Zero-Downtime Deployment: Show how the two instances of the Spring application allow for rollback and smooth transitions during rolling updates.

##### Technologies and Frameworks
- Spring Boot for the application services.
- MariaDB and Redis for backend storage.
- Docker Compose for container orchestration.
- Nginx for load balancing and reverse proxy.
- Prometheus, Grafana, and Loki for monitoring and logging.

##### Overall Detailed Approach
- Within the AWS EC2 boundary, segregate the four layers:
- Layer 1: Nginx (plus status endpoints).
- Layer 2: Spring Boot Applications where at least two instances are depicted with state annotations.
- Layer 3: Monitoring which aggregates data from Prometheus, Grafana, and Loki.
- Layer 4: Backend services (MariaDB and Redis).

## Diagram (Mermaid)

```mermaid
flowchart TD
    USER("User"):::external

    subgraph "AWS EC2 Deployment"
        %% Frontend Layer: Nginx
        subgraph "Frontend Gateway"
            NG("Nginx"):::frontend
        end

        %% Application Layer: Spring Boot Applications
        subgraph "Application Layer"
            SPA1("Spring App #1 (Running)"):::app
            SPA2("Spring App #2 (Idle/Updating)"):::app
        end

        %% Monitoring and Logging Layer
        subgraph "Monitoring and Logging"
            PROM("Prometheus"):::monitor
            GRAF("Grafana"):::monitor
            LOKI("Loki"):::monitor

            subgraph "Grafana Config"
                DASH_MAIN("Main Dashboard"):::config
                DASH_SPRING("Spring Boot Board"):::config
                DATASOURCES("Datasources Config"):::config
                PROM_CONFIG("Prometheus Config"):::config
            end
        end

        %% Backend Services Layer
        subgraph "Backend Services"
            MARI("MariaDB"):::backend
            REDIS("Redis"):::backend
        end

        %% Infrastructure Management: Scripts and Rolling Update Procedures
        subgraph "Infrastructure Management"
            subgraph "Management Scripts"
                NG_LAUNCH("NGINX Launch Script"):::management
                NG_SHUTDOWN("NGINX Shutdown Script"):::management
                PLG_LAUNCH("PLG Launch Script"):::management
                PLG_SHUTDOWN("PLG Shutdown Script"):::management
                ALL_INFRA_LAUNCH("All Infra Launch Script"):::management
                ALL_INFRA_SHUTDOWN("All Infra Shutdown Script"):::management
            end
            subgraph "Rolling Update Procedures"
                PULL("Pull Latest Images"):::management
                ROLL_UPDATE("Rolling Update Script"):::management
            end
        end
    end

    %% Data Flows
    USER -->|"HTTP_Request"| NG
    NG -->|"Route:/"| SPA1
    NG -->|"Route:/"| SPA2

    SPA1 -->|"DataQuery"| MARI
    SPA2 -->|"DataQuery"| MARI
    SPA1 -->|"Cache"| REDIS
    SPA2 -->|"Cache"| REDIS

    SPA1 -->|"Metrics"| PROM
    SPA2 -->|"Metrics"| PROM
    SPA1 -->|"Logs"| LOKI
    SPA2 -->|"Logs"| LOKI

    PROM -->|"MetricsFeed"| GRAF
    LOKI -->|"LogFeed"| GRAF

    %% Rolling Update triggers update of Application
    ROLL_UPDATE ---|"TriggersUpdate"| SPA2

    %% Click Events for Component Mapping
    click NG "https://github.com/tape4/spring-cicd-template/tree/main/nginx"
    click NG_LAUNCH "https://github.com/tape4/spring-cicd-template/blob/main/scripts/nginx-launch.sh"
    click NG_SHUTDOWN "https://github.com/tape4/spring-cicd-template/blob/main/scripts/nginx-shutdown.sh"
    click GRAF "https://github.com/tape4/spring-cicd-template/tree/main/grafana"
    click DASH_MAIN "https://github.com/tape4/spring-cicd-template/blob/main/grafana/dashboards/main.yaml"
    click DASH_SPRING "https://github.com/tape4/spring-cicd-template/blob/main/grafana/dashboards/spring-boot-board.json"
    click DATASOURCES "https://github.com/tape4/spring-cicd-template/blob/main/grafana/datasources/datasources.yaml"
    click PROM_CONFIG "https://github.com/tape4/spring-cicd-template/blob/main/grafana/prometheus-config.yml"
    click PLG_LAUNCH "https://github.com/tape4/spring-cicd-template/blob/main/scripts/plg-launch.sh"
    click PLG_SHUTDOWN "https://github.com/tape4/spring-cicd-template/blob/main/scripts/plg-shutdown.sh"
    click ALL_INFRA_LAUNCH "https://github.com/tape4/spring-cicd-template/blob/main/scripts/all-infra-launch.sh"
    click ALL_INFRA_SHUTDOWN "https://github.com/tape4/spring-cicd-template/blob/main/scripts/all-infra-shutdown.sh"
    click PULL "https://github.com/tape4/spring-cicd-template/blob/main/rolling_update/pull-latest-images.sh"
    click ROLL_UPDATE "https://github.com/tape4/spring-cicd-template/blob/main/rolling_update/rolling-update.sh"
    click MARI "https://github.com/tape4/spring-cicd-template/tree/main/storage"

    %% Styles
    classDef external fill:#b3e5fc,stroke:#0288d1,stroke-width:2px;
    classDef frontend fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef app fill:#f8bbd0,stroke:#880e4f,stroke-width:2px;
    classDef monitor fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
    classDef backend fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
    classDef management fill:#d1c4e9,stroke:#5e35b1,stroke-width:2px;
    classDef config fill:#dcedc8,stroke:#33691e,stroke-width:2px;
```
