# temporalio/samples-go architecture

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

- Interactive diagram: https://gitdiagram.com/temporalio/samples-go
- Repository: https://github.com/temporalio/samples-go

## Overview

##### Project type and purpose
- This is neither a monolithic web app nor a mobile project, but a **collection of sample Workflow applications** demonstrating the capabilities of the **Temporal Server** via the **Temporal Go SDK**.
- Each subdirectory under the root (e.g., `helloworld`, `expense`, `child-workflow`, etc.) is an independent sample illustrating one feature or pattern (Activity retries, child Workflows, signals, queries, DataConverters, interceptors, cron/schedules, sessions, context propagation, OpenTelemetry, etc.).

##### File structure
- Top-level files & dirs:
- `.github/`, `.gitignore`, `Makefile`, `docker-compose.yml`, `go.mod` – build and CI/CD configuration
- `README.md` – high-level repo overview and sample index
- dozens of sample directories, each with the same three-tier pattern:
- `<sample>/starter/` – the **client** process that starts Workflows, sends signals/queries/updates or cancels
- `<sample>/worker/` – the **worker** process that polls the Temporal Server task queue, executes Workflow logic & Activities
- sample-specific Go files (`workflow.go`, `activities.go`, `data_converter.go`, `interceptor.go`, etc.) and tests
- Shared components: some samples run a dedicated **Codec Server** (e.g., `codec-server`) to offload payload encoding/decoding, or embed OIDC/mTLS logic for authentication.

##### Insights from README
- The repo runs against a **Temporal Server** (local via `docker-compose` or remote), which itself has a frontend, matching, history, and worker services backed by a persistence database (MySQL/Cassandra).
- Each sample shows a distinct SDK feature or architectural pattern (async completion, cron vs. schedule, saga, polling, dynamic Workflows, Nexus cross-namespace calls, etc.).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Temporal Server Cluster
    subgraph "Temporal Server Cluster"
        direction TB
        FE["Frontend API"]:::server
        MA["Matching Service"]:::server
        HI["History Service"]:::server
        WS["Worker Service"]:::server
        DB[(Persistence DB)]:::db
        FE --> DB
        MA --> DB
        HI --> DB
        WS --> DB
    end

    %% Sample Applications
    subgraph "Sample Applications"
        direction TB
        subgraph "Expense Sample"
            direction TB
            ES["Expense Starter"]:::client
            EW["Expense Worker"]:::worker
            ES -->|StartWorkflow / Signal / Query| FE
            EW -->|Poll Task Queue| MA
            EW -->|Report Results / Heartbeat| FE
        end
    end

    %% UI Client Example
    subgraph "UI Client Example"
        direction TB
        UI["Expense UI"]:::client
        UI -->|gRPC StartWorkflow| ES
    end

    %% DataConverter & Codec Servers
    subgraph "DataConverter Services"
        direction TB
        CS1["Codec Server"]:::external
        CS2["Snappy Codec Server"]:::external
        CS3["Encryption Codec Server"]:::external
        CS1 -->|REST/gRPC| EW
        CS2 -->|REST/gRPC| EW
        CS3 -->|REST/gRPC| EW
    end

    %% Security Samples
    subgraph "Security Samples"
        direction TB
        OIDC["OIDC / Key Service"]:::cloud
        SI["Security Interceptor"]:::interceptor
        OIDC -->|mTLS Auth| ES
        OIDC -->|mTLS Auth| EW
        SI -->|Intercept Workflows| EW
    end

    %% Shared Cross-Cutting Concerns
    subgraph "Cross-Cutting Libraries"
        direction TB
        DC["DataConverter Impl"]:::lib
        LI["Logging Interceptor"]:::interceptor
        CP["Context Propagator"]:::lib
        TR["Tracing Setup"]:::lib
        OM["OpenTelemetry Setup"]:::lib
        PM["Prometheus Metrics"]:::lib
        DC --> EW
        LI --> EW
        CP --> EW
        TR --> EW
        OM --> EW
        PM --> EW
    end

    classDef server fill:#FFDD99,stroke:#333,stroke-width:1px;
    classDef client fill:#99CCFF,stroke:#333,stroke-width:1px;
    classDef worker fill:#99FF99,stroke:#333,stroke-width:1px,shape:roundrectangle;
    classDef db fill:#CCCCCC,stroke:#333,stroke-width:1px,shape:cylinder;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px;
    classDef cloud fill:#E0E0E0,stroke:#333,stroke-width:1px,shape:cloud;
    classDef interceptor fill:#FFCCFF,stroke:#333,stroke-width:1px;
    classDef lib fill:#FFE5CC,stroke:#333,stroke-width:1px;

    %% Click Events
    click ES "https://github.com/temporalio/samples-go/blob/main/expense/starter/main.go"
    click EW "https://github.com/temporalio/samples-go/blob/main/expense/worker/main.go"
    click UI "https://github.com/temporalio/samples-go/blob/main/expense/ui/main.go"
    click CS1 "https://github.com/temporalio/samples-go/blob/main/codec-server/codec-server/main.go"
    click CS2 "https://github.com/temporalio/samples-go/blob/main/snappycompress/codec-server/main.go"
    click CS3 "https://github.com/temporalio/samples-go/blob/main/encryption/codec-server/main.go"
    click OIDC "https://github.com/temporalio/samples-go/blob/main/serverjwtauth/key/main.go"
    click SI "https://github.com/temporalio/samples-go/blob/main/workflow-security-interceptor/interceptor.go"
    click DC "https://github.com/temporalio/samples-go/blob/main/pso/dataconverter.go"
    click LI "https://github.com/temporalio/samples-go/blob/main/logger-interceptor/interceptor.go"
    click CP "https://github.com/temporalio/samples-go/blob/main/ctxpropagation/propagator.go"
    click TR "https://github.com/temporalio/samples-go/blob/main/ctxpropagation/tracer.go"
    click OM "https://github.com/temporalio/samples-go/blob/main/opentelemetry/opentelemetry_setup.go"
    click PM "https://github.com/temporalio/samples-go/blob/main/metrics/metrics.go"
```
