# google/go-containerregistry architecture

> Architecture diagram of the GitHub repository google/go-containerregistry, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google/go-containerregistry
- Repository: https://github.com/google/go-containerregistry

## Overview

##### Main Components

- v1.Image Interface
- v1.Layer Interface
- v1.ImageIndex Interface
- Registry Interaction Layer

b. Source Components (Left Side):
- Remote Sources
- Tarball Sources
- Daemon Sources
- Layout Sources
- Random Sources

c. Sink Components (Right Side):
- Remote Write
- Tarball Write
- Daemon Write
- Layout Write

d. Supporting Systems (Bottom):
- Authentication (authn package)
- Transport Layer
- Mutation System
- Partial Implementation Support

##### Relationships and Data Flow

- Bidirectional flow between core components and registry
- Source flows into core components
- Core components flow to sinks
- Authentication and transport supporting all remote operations
- Mutation operations working on core components

##### Specific Implementation Details

Create subdivisions showing:
- Authentication Methods (Basic, Bearer, K8s)
- Transport Layer Components
- Mutation Operations
- Compression Support

##### Tools Integration

How tools connect:
- Crane
- GCrane
- KRane
- K8schain

**[Sources] -> [Core Components] -> [Sinks]**
- ^

- [Supporting Infrastructure]
- ^

- [Tools & Utilities]

Key Elements to Emphasize:

##### Immutable View Pattern
- How immutable resources flow through the system
- Functional mutations creating new views

##### Registry Interaction
- Detail the transport and authentication layers
- How different registry types are supported

##### Implementation Details
- Packages like v1/mutate, v1/partial
- Compression and streaming capabilities
- Where caching occurs

Additional Guidelines:

##### Public vs internal components clearly

This design will help developers understand both the high-level architecture and the detailed interactions between components, making it easier to maintain and extend the system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Core Components
    subgraph Core["Core Components"]
        Image["v1.Image Interface"]:::core
        Layer["v1.Layer Interface"]:::core
        ImageIndex["v1.ImageIndex Interface"]:::core
        Registry["Registry Interaction"]:::core
    end

    %% Source Components
    subgraph Sources["Source Components"]
        direction TB
        Remote["Remote Sources"]:::source
        Tarball["Tarball Sources"]:::source
        Daemon["Daemon Sources"]:::source
        Layout["Layout Sources"]:::source
        Random["Random Sources"]:::source
    end

    %% Sink Components
    subgraph Sinks["Sink Components"]
        direction TB
        RemoteWrite["Remote Write"]:::sink
        TarballWrite["Tarball Write"]:::sink
        DaemonWrite["Daemon Write"]:::sink
        LayoutWrite["Layout Write"]:::sink
    end

    %% Supporting Systems
    subgraph Support["Supporting Infrastructure"]
        direction TB
        subgraph Auth["Authentication"]
            BasicAuth["Basic Auth"]:::auth
            BearerAuth["Bearer Auth"]:::auth
            K8sAuth["Kubernetes Auth"]:::auth
            GoogleAuth["Google Auth"]:::auth
        end

        subgraph Transport["Transport Layer"]
            BasicTransport["Basic Transport"]:::transport
            BearerTransport["Bearer Transport"]:::transport
            ErrorHandling["Error Handling"]:::transport
        end

        subgraph Mutations["Mutation System"]
            ImageMutations["Image Mutations"]:::mutation
            IndexMutations["Index Mutations"]:::mutation
            RebaseOps["Rebase Operations"]:::mutation
        end

        subgraph Partial["Partial Implementation"]
            Compressed["Compressed Support"]:::partial
            Uncompressed["Uncompressed Support"]:::partial
        end
    end

    %% Tools Integration
    subgraph Tools["Tools & Utilities"]
        Crane["Crane"]:::tool
        GCrane["GCrane"]:::tool
        KRane["KRane"]:::tool
        K8schain["K8schain"]:::tool
    end

    %% Relationships
    Sources --> Core
    Core --> Sinks
    Auth --> Registry
    Transport --> Registry
    Mutations --> Core
    Partial --> Core
    Tools --> Core

    %% Styling
    classDef core fill:#a2d2ff
    classDef source fill:#98f5e1
    classDef sink fill:#ffb4a2
    classDef auth fill:#ffea00
    classDef transport fill:#e9ff70
    classDef mutation fill:#d8bbff
    classDef partial fill:#ffd6ff
    classDef tool fill:#b5e48c

    %% Click Events
    click Image "https://github.com/google/go-containerregistry/blob/main/pkg/v1/image.go"
    click Layer "https://github.com/google/go-containerregistry/blob/main/pkg/v1/layer.go"
    click ImageIndex "https://github.com/google/go-containerregistry/blob/main/pkg/v1/index.go"
    click Remote "https://github.com/google/go-containerregistry/tree/main/pkg/v1/remote/"
    click Tarball "https://github.com/google/go-containerregistry/tree/main/pkg/v1/tarball/"
    click Daemon "https://github.com/google/go-containerregistry/tree/main/pkg/v1/daemon/"
    click Layout "https://github.com/google/go-containerregistry/tree/main/pkg/v1/layout/"
    click Random "https://github.com/google/go-containerregistry/tree/main/pkg/v1/random/"
    click BasicAuth "https://github.com/google/go-containerregistry/blob/main/pkg/authn/basic.go"
    click BearerAuth "https://github.com/google/go-containerregistry/blob/main/pkg/authn/bearer.go"
    click K8sAuth "https://github.com/google/go-containerregistry/tree/main/pkg/authn/kubernetes/"
    click GoogleAuth "https://github.com/google/go-containerregistry/tree/main/pkg/v1/google/"
    click BasicTransport "https://github.com/google/go-containerregistry/blob/main/pkg/v1/remote/transport/basic.go"
    click BearerTransport "https://github.com/google/go-containerregistry/blob/main/pkg/v1/remote/transport/bearer.go"
    click ErrorHandling "https://github.com/google/go-containerregistry/blob/main/pkg/v1/remote/transport/error.go"
    click ImageMutations "https://github.com/google/go-containerregistry/blob/main/pkg/v1/mutate/image.go"
    click IndexMutations "https://github.com/google/go-containerregistry/blob/main/pkg/v1/mutate/index.go"
    click RebaseOps "https://github.com/google/go-containerregistry/blob/main/pkg/v1/mutate/rebase.go"
    click Compressed "https://github.com/google/go-containerregistry/blob/main/pkg/v1/partial/compressed.go"
    click Uncompressed "https://github.com/google/go-containerregistry/blob/main/pkg/v1/partial/uncompressed.go"
    click Registry "https://github.com/google/go-containerregistry/tree/main/pkg/registry/"
```
