# infrastructure-as-code/docker-hello-world architecture

> Architecture diagram of the GitHub repository infrastructure-as-code/docker-hello-world, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/infrastructure-as-code/docker-hello-world
- Repository: https://github.com/infrastructure-as-code/docker-hello-world

## Overview

##### Project type and purpose
- This is a tiny Go-based microservice packaged as a Docker container.
- It exposes three HTTP endpoints:
- `/` serving “Hello, World!”
- `/metrics` serving Prometheus metrics
- `/health` for health checks
- CI/CD pipelines build and publish the container image to GitHub Container Registry and Docker Hub.

##### File structure
- Top-level Go service files:
- `hello_world.go` – server implementation
- `hello_world_test.go` – unit tests
- Build/config files:
- `Dockerfile` – container build instructions
- `Makefile` (optional) – local build shortcuts
- GitHub Actions workflows in `.github/workflows` (`dockerhub.yml`, `ghcr.yml`)
- Dependency management: `go.mod`, `go.sum`
- Metadata: `README.md`, `LICENSE`, `.gitignore`, `.gitattributes`

##### Extract insights from README
- Clearly states supported endpoints and metrics integration.
- Describes how images are built and where they’re pushed.
- Shows usage examples for running the container and scraping metrics.

##### Main components
a. Source Code Repository
- GitHub repo containing Go code and CI definitions.
b. Continuous Integration/Delivery
- GitHub Actions pipelines that:
1. Run tests (`hello_world_test.go`)
2. Build the Go binary
3. Build and tag Docker images
4. Push to GHCR and Docker Hub
c. Container Image Registries
- GitHub Container Registry (`ghcr.io/infrastructure-as-code/hello-world`)
- Docker Hub (`infrastructureascode/hello-world`)
d. Container Runtime / Deployment
- Docker daemon or orchestrator (Kubernetes, ECS, etc.) pulling and running the image
e. HTTP Clients
- User agents or tools (curl, browsers, services) invoking `/`, `/health`
f. Prometheus Server
- Scrapes `/metrics` endpoint on a regular interval

##### Relationships and interactions
- Source Code → GitHub Actions: code push triggers CI
- CI → Registries: successful builds produce and push images
- Container Runtime → Registry: pulls the latest image
- Clients → Container: send HTTP requests
- Prometheus → Container `/metrics`: pulls metrics data

##### Architectural patterns and design principles
- Single-responsibility microservice: one container, three simple endpoints
- Infrastructure as Code: Dockerfile and workflows declared in repo
- Observability built in via Prometheus instrumentation
- Immutable artifacts: every build produces a versioned Docker image

##### Detail without over-splitting
- You don’t need dozens of microservices here; focus on the six core elements above.
- If desired, annotate technologies next to each:
- GitHub Actions (YAML workflows)
- Dockerfile / Docker engine
- Go 1.x runtime
- Prometheus v2.x

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Development Pipeline
    subgraph "Development Pipeline" 
        direction TB
        Repo["Source Code Repository"]:::dev
        subgraph "Repository Files"
            direction TB
            ServiceCode["Go Service Implementation"]:::dev
            UnitTests["Unit Tests"]:::dev
            DockerfileNode["Dockerfile"]:::dev
            MakefileNode["Makefile"]:::dev
            GoMod["go.mod"]:::dev
            GoSum["go.sum"]:::dev
            Docs["README.md"]:::dev
            License["LICENSE"]:::dev
            Gitignore[".gitignore"]:::dev
            Gitattributes[".gitattributes"]:::dev
        end
        subgraph "CI/CD Workflows"
            direction TB
            DockerHubWF["Docker Hub Workflow"]:::dev
            GHCRWF["GHCR Workflow"]:::dev
        end
    end

    %% Container Registries
    subgraph "Container Registries"
        direction TB
        DockerHub["Docker Hub"]:::dev
        GHCR["GitHub Container Registry"]:::dev
    end

    %% Runtime
    subgraph "Container Runtime"
        direction TB
        Host["Container Host\n(Docker/Kubernetes)"]:::runtime
        Service["Hello-World Service Container\n(Go 1.x)"]:::runtime
    end

    %% Consumers
    subgraph "Consumers"
        direction TB
        Clients["HTTP Clients\n(curl, browsers)"]:::cons
        Prometheus["Prometheus Server v2.x"]:::cons
    end

    %% Connections
    Repo -->|"contains files"| ServiceCode
    Repo --> ServiceCode
    Repo --> UnitTests
    Repo --> DockerfileNode
    Repo --> MakefileNode
    Repo --> GoMod
    Repo --> GoSum
    Repo --> Docs
    Repo --> License
    Repo --> Gitignore
    Repo --> Gitattributes

    Repo -->|"push code"| DockerHubWF
    Repo -->|"push code"| GHCRWF

    DockerHubWF -->|"build & push image"| DockerHub
    GHCRWF -->|"build & push image"| GHCR

    Host -->|"pull image"| DockerHub
    Host -->|"pull image"| GHCR
    Host -->|"runs container"| Service

    Clients -->|"HTTP GET /, /health"| Service
    Prometheus -->|"scrape /metrics"| Service

    %% Click Events
    click Repo "https://github.com/infrastructure-as-code/docker-hello-world/tree/master//"
    click ServiceCode "https://github.com/infrastructure-as-code/docker-hello-world/blob/master/hello_world.go"
    click UnitTests "https://github.com/infrastructure-as-code/docker-hello-world/blob/master/hello_world_test.go"
    click DockerfileNode "https://github.com/infrastructure-as-code/docker-hello-world/tree/master/Dockerfile"
    click MakefileNode "https://github.com/infrastructure-as-code/docker-hello-world/tree/master/Makefile"
    click GoMod "https://github.com/infrastructure-as-code/docker-hello-world/blob/master/go.mod"
    click GoSum "https://github.com/infrastructure-as-code/docker-hello-world/blob/master/go.sum"
    click Docs "https://github.com/infrastructure-as-code/docker-hello-world/blob/master/README.md"
    click License "https://github.com/infrastructure-as-code/docker-hello-world/tree/master/LICENSE"
    click Gitignore "https://github.com/infrastructure-as-code/docker-hello-world/blob/master/.gitignore"
    click Gitattributes "https://github.com/infrastructure-as-code/docker-hello-world/blob/master/.gitattributes"
    click DockerHubWF "https://github.com/infrastructure-as-code/docker-hello-world/blob/master/.github/workflows/dockerhub.yml"
    click GHCRWF "https://github.com/infrastructure-as-code/docker-hello-world/blob/master/.github/workflows/ghcr.yml"

    %% Styles
    classDef dev fill:#D0E6FF,stroke:#0B69B1,stroke-width:1px
    classDef runtime fill:#D8F5D3,stroke:#2E8B57,stroke-width:1px
    classDef cons fill:#FFE3B8,stroke:#D9822B,stroke-width:1px
    classDef reg fill:#CDE7FF,stroke:#0B69B1,stroke-width:1px
```
