# lotusirous/go-concurrency-patterns architecture

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

- Interactive diagram: https://gitdiagram.com/lotusirous/go-concurrency-patterns
- Repository: https://github.com/lotusirous/go-concurrency-patterns

## Overview

##### Project Components
- Repository Root: Represent the overall repository as the central container ("Go Concurrency Patterns").
- Individual Pattern Examples: Each numbered directory (for instance, “1-boring”, “2-chan”, “3-generator”, etc.) should be depicted as its own component/module. For patterns that have both client and server files (like “16-context”), show the internal split (client, server, and main) to emphasize their roles.
- Shared Dependencies: Although not explicit beyond using Go’s standard libraries, you might include a node for the Go runtime / standard library to indicate that all examples rely on Go’s concurrency primitives (goroutines, channels, context, etc.).

##### Grouping and Categorizing
- By Complexity/Type (optional): Consider clustering examples into “Basic Patterns” (1-boring, 2-chan, 3-generator, etc.), “Pattern Compositions” (4-fanin, 5-restore-sequence, 6-select-timeout, etc.), and “Advanced Patterns” (13-adv-pingpong, 14-adv-subscription, 15-bounded-parallelism, 16-context, 17-ring-buffer-channel, 18-worker-pool, etc.). This helps to quickly see which examples build upon simpler patterns versus those that demonstrate more complex scenarios.

##### Architectural Patterns and Design Principles
- That each directory is focused on a particular concurrency model or pattern (e.g., “fan in/fan out”, “worker pool”, “context cancellation”, etc.).
- That the examples are designed to demonstrate how data flows between goroutines and channels, along with proper signal handling and cancellation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    repository["Go Concurrency Patterns"]:::repository

    subgraph "Basic Patterns"
        B1["1-boring: Basic Concurrency Example “Boring”"]:::basic
        B2["2-chan: Basic Channel Communication"]:::basic
        B3["3-generator: Generator Pattern"]:::basic
        B7["7-quit-signal: Quit Signal Mechanism"]:::basic
        B8["8-daisy-chan: Daisy Chain Channel Communication"]:::basic
    end

    subgraph "Pattern Compositions"
        P1["4-fanin: Fan-in Pattern"]:::compositions
        P2["5-restore-sequence: Sequence Restoration"]:::compositions
        P3["6-select-timeout: Select with Timeout"]:::compositions
    end

    subgraph "Google Examples"
        G1["9-google1.0: Google Example V1-Basic"]:::google
        G2["10-google2.0: Google Example V2-EvolvingPattern"]:::google
        G3["11-google2.1: Google Example V2.1-IntermediateUpdate"]:::google
        G4["12-google3.0: Google Example V3-Advanced"]:::google
    end

    subgraph "Advanced Patterns"
        A1["13-adv-pingpong: Advanced Pingpong Pattern"]:::advanced
        A2["14-adv-subscription: Advanced Subscription Model"]:::advanced
        A3["15-bounded-parallelism: Bounded Parallelism"]:::advanced
        A4["16-context: Context Pattern"]:::advanced
        A5["17-ring-buffer-channel: Ring Buffer with Channel"]:::advanced
        A6["18-worker-pool: Worker Pool Pattern"]:::advanced
    end

    subgraph "16-context Components"
        A4a["Client (HTTP Client)"]:::advanced
        A4b["Server (HTTP Server)"]:::advanced
        A4c["Main Controller"]:::advanced
    end

    SD["Go Runtime / Standard Library"]:::shared

    %% Connections from Repository to Groups
    repository --> B1
    repository --> P1
    repository --> G1
    repository --> A1
    repository --> SD

    %% Google Examples Progression
    G1 --> G2
    G2 --> G3
    G3 --> G4

    %% 16-context relationships
    A4 -->|"includes"| A4a
    A4 -->|"includes"| A4b
    A4 -->|"includes"| A4c
    A4a -->|"HTTPRequest"| A4b

    %% Classes
    classDef repository fill:#f9e79f,stroke:#f39c12,stroke-width:2px,color:#000;
    classDef basic fill:#a9dfbf,stroke:#1abc9c,stroke-width:2px,color:#000;
    classDef compositions fill:#aed6f1,stroke:#3498db,stroke-width:2px,color:#000;
    classDef google fill:#fad7a0,stroke:#f39c12,stroke-width:2px,color:#000;
    classDef advanced fill:#d7bde2,stroke:#8e44ad,stroke-width:2px,color:#000;
    classDef shared fill:#d5f5e3,stroke:#27ae60,stroke-width:2px,color:#000;

    %% Click Events
    click repository "https://github.com/lotusirous/go-concurrency-patterns/tree/main/Repository Root"
    click B1 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/1-boring/main.go"
    click B2 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/2-chan/main.go"
    click B3 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/3-generator/main.go"
    click B7 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/7-quit-signal/main.go"
    click B8 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/8-daisy-chan/main.go"
    click P1 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/4-fanin/main.go"
    click P2 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/5-restore-sequence/main.go"
    click P3 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/6-select-timeout/main.go"
    click G1 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/9-google1.0/main.go"
    click G2 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/10-google2.0/main.go"
    click G3 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/11-google2.1/main.go"
    click G4 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/12-google3.0/main.go"
    click A1 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/13-adv-pingpong/main.go"
    click A2 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/14-adv-subscription/main.go"
    click A3 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/15-bounded-parallelism/main.go"
    click A4 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/16-context/main.go"
    click A4a "https://github.com/lotusirous/go-concurrency-patterns/blob/main/16-context/client.go"
    click A4b "https://github.com/lotusirous/go-concurrency-patterns/blob/main/16-context/server.go"
    click A4c "https://github.com/lotusirous/go-concurrency-patterns/blob/main/16-context/main.go"
    click A5 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/17-ring-buffer-channel/main.go"
    click A6 "https://github.com/lotusirous/go-concurrency-patterns/blob/main/18-worker-pool/main.go"
```
