# vmvarela/oras-state architecture

> Architecture diagram of the GitHub repository vmvarela/oras-state, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vmvarela/oras-state
- Repository: https://github.com/vmvarela/oras-state

## Overview

oras-state is a Go library that lets Terraform/OpenTofu adapters store and manage workspace state in OCI registries. The main workflow is to create a configured client, read or publish a workspace’s state, and optionally coordinate updates with cooperative locks; publication can also maintain version history. Separate capabilities cover workspace discovery and deletion, repository copying, and registry cleanup. The excerpts show client construction, state publication, workspace checks, history reads, copying, and cleanup logic; unsampled client methods are grouped by responsibility rather than assumed call flow.

Main entry points: [`auth.go`](https://github.com/vmvarela/oras-state/blob/master/auth.go) (Client setup), [`client.go`](https://github.com/vmvarela/oras-state/blob/master/client.go) (Current state I/O), [`history.go`](https://github.com/vmvarela/oras-state/blob/master/history.go) (Version history), [`copy.go`](https://github.com/vmvarela/oras-state/blob/master/copy.go) (Repository copy)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client and workspaces"]
  node_client["Client setup<br/>[auth.go]"]
  node_workspace["Workspace validation<br/>[workspace.go]"]
  node_legacy["Legacy layout<br/>[legacy_layout.go]"]
end

subgraph group_state["State and history"]
  node_stateio["Current state I/O<br/>[client.go]"]
  node_locks["Workspace locks<br/>[client.go]"]
  node_history["Version history<br/>[history.go]"]
end

subgraph group_maintenance["Repository maintenance"]
  node_delete["Workspace deletion<br/>[client.go]"]
  node_copy["Repository copy<br/>[copy.go]"]
  node_purge["Registry purge<br/>[purge.go]"]
end

subgraph group_registry["Registry integrations"]
  node_ghcr["GHCR deletion fallback<br/>[ghcr.go]"]
end

node_adapter(("Go adapter"))
node_oci[("OCI registry")]
node_github["GitHub Packages API"]

node_adapter -->|"creates client"| node_client
node_client -->|"configures access"| node_oci
node_adapter -->|"reads or writes"| node_stateio
node_stateio -->|"checks workspace"| node_workspace
node_adapter -->|"coordinates updates"| node_locks
node_adapter -->|"reads versions"| node_history
node_history -->|"checks workspace"| node_workspace
node_adapter -->|"deletes workspace"| node_delete
node_adapter -->|"copies repository"| node_copy
node_copy -->|"copies artifacts"| node_oci
node_adapter -->|"purges artifacts"| node_purge
node_purge -->|"inventories artifacts"| node_oci
node_ghcr -->|"deletes versions"| node_github
node_delete -->|"uses fallback"| node_ghcr
node_legacy -->|"resolves legacy tags"| node_oci

click node_client "https://github.com/vmvarela/oras-state/blob/master/auth.go"
click node_workspace "https://github.com/vmvarela/oras-state/blob/master/workspace.go"
click node_legacy "https://github.com/vmvarela/oras-state/blob/master/legacy_layout.go"
click node_stateio "https://github.com/vmvarela/oras-state/blob/master/client.go"
click node_locks "https://github.com/vmvarela/oras-state/blob/master/client.go"
click node_history "https://github.com/vmvarela/oras-state/blob/master/history.go"
click node_delete "https://github.com/vmvarela/oras-state/blob/master/client.go"
click node_copy "https://github.com/vmvarela/oras-state/blob/master/copy.go"
click node_purge "https://github.com/vmvarela/oras-state/blob/master/purge.go"
click node_ghcr "https://github.com/vmvarela/oras-state/blob/master/ghcr.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client,node_workspace,node_legacy toneBlue
class node_stateio,node_locks,node_history,node_oci toneAmber
class node_delete,node_copy,node_purge,node_github toneMint
class node_ghcr toneRose
class node_adapter toneIndigo
```

## Components

### Client and workspaces

- [Client setup](https://github.com/vmvarela/oras-state/blob/master/auth.go): `auth.go`
- [Workspace validation](https://github.com/vmvarela/oras-state/blob/master/workspace.go): `workspace.go`
- [Legacy layout](https://github.com/vmvarela/oras-state/blob/master/legacy_layout.go): `legacy_layout.go`

### State and history

- [Current state I/O](https://github.com/vmvarela/oras-state/blob/master/client.go): `client.go`
- [Workspace locks](https://github.com/vmvarela/oras-state/blob/master/client.go): `client.go`
- [Version history](https://github.com/vmvarela/oras-state/blob/master/history.go): `history.go`

### Repository maintenance

- [Workspace deletion](https://github.com/vmvarela/oras-state/blob/master/client.go): `client.go`
- [Repository copy](https://github.com/vmvarela/oras-state/blob/master/copy.go): `copy.go`
- [Registry purge](https://github.com/vmvarela/oras-state/blob/master/purge.go): `purge.go`

### Registry integrations

- [GHCR deletion fallback](https://github.com/vmvarela/oras-state/blob/master/ghcr.go): `ghcr.go`

### Other components

- **Go adapter**
- **OCI registry**
- **GitHub Packages API**

## Connections

- Go adapter → Client setup: creates client (evidence: `auth.go`)
- Client setup → OCI registry: configures access (evidence: `auth.go`)
- Go adapter → Current state I/O: reads or writes (evidence: `README.md`)
- Current state I/O → Workspace validation: checks workspace (evidence: `client.go`)
- Go adapter → Workspace locks: coordinates updates (evidence: `README.md`)
- Go adapter → Version history: reads versions (evidence: `README.md`)
- Version history → Workspace validation: checks workspace (evidence: `history.go`)
- Go adapter → Workspace deletion: deletes workspace (evidence: `README.md`)
- Go adapter → Repository copy: copies repository (evidence: `copy.go`)
- Repository copy → OCI registry: copies artifacts (evidence: `copy.go`)
- Go adapter → Registry purge: purges artifacts (evidence: `purge.go`)
- Registry purge → OCI registry: inventories artifacts (evidence: `purge.go`)
- GHCR deletion fallback → GitHub Packages API: deletes versions (evidence: `ghcr.go`)
- Workspace deletion → GHCR deletion fallback: uses fallback (evidence: `client.go`)
- Legacy layout → OCI registry: resolves legacy tags (evidence: `legacy_layout.go`)
