# robby031/r2 architecture

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

- Interactive diagram: https://gitdiagram.com/robby031/r2
- Repository: https://github.com/robby031/r2

## Overview

This is a Go HTTP API for managing files in Cloudflare R2: the server initializes configuration and storage, then routes file operations through Gin controllers to the storage client. The API supports uploads, deletion, presigned URLs, listing, checksum verification, and usage reporting; the storage layer also enforces a capacity limit and caches reads. The cache’s interaction with storage is explicit in the excerpt; other internal S3 operations are summarized at the storage component. The README is empty, so feature coverage relies on the sampled controllers and storage code.

Main entry points: [`storage/storage.go`](https://github.com/robby031/r2/blob/main/storage/storage.go) (Storage client), [`main.go`](https://github.com/robby031/r2/blob/main/main.go) (HTTP server), [`internal/router.go`](https://github.com/robby031/r2/blob/main/internal/router.go) (Gin router), [`internal/controllers.go`](https://github.com/robby031/r2/blob/main/internal/controllers.go) (File controllers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_router["Gin router<br/>[router.go]"]
  node_controllers["File controllers<br/>[controllers.go]"]
end

subgraph group_storage["Object storage"]
  node_r2client["Storage client<br/>[storage.go]"]
  node_cache["Read cache<br/>[cache.go]"]
end

subgraph group_runtime["Runtime setup"]
  node_server["HTTP server<br/>[main.go]"]
  node_config["Environment config<br/>[config.go]"]
end

node_user(("API client"))
node_r2[("Cloudflare R2")]

node_user -->|"sends requests"| node_server
node_server -->|"loads settings"| node_config
node_server -->|"serves routes"| node_router
node_config -->|"initializes"| node_r2client
node_router -->|"dispatches"| node_controllers
node_controllers -->|"calls operations"| node_r2client
node_r2client -->|"loads and invalidates"| node_cache
node_r2client -->|"reads and writes objects"| node_r2

click node_server "https://github.com/robby031/r2/blob/main/main.go"
click node_config "https://github.com/robby031/r2/blob/main/config/config.go"
click node_router "https://github.com/robby031/r2/blob/main/internal/router.go"
click node_controllers "https://github.com/robby031/r2/blob/main/internal/controllers.go"
click node_r2client "https://github.com/robby031/r2/blob/main/storage/storage.go"
click node_cache "https://github.com/robby031/r2/blob/main/storage_cache/cache.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_router,node_controllers,node_user toneBlue
class node_r2client,node_cache,node_r2 toneAmber
class node_server,node_config toneMint
```

## Components

### HTTP API

- [Gin router](https://github.com/robby031/r2/blob/main/internal/router.go): `internal/router.go`
- [File controllers](https://github.com/robby031/r2/blob/main/internal/controllers.go): `internal/controllers.go`

### Object storage

- [Storage client](https://github.com/robby031/r2/blob/main/storage/storage.go): `storage/storage.go`
- [Read cache](https://github.com/robby031/r2/blob/main/storage_cache/cache.go): `storage_cache/cache.go`

### Runtime setup

- [HTTP server](https://github.com/robby031/r2/blob/main/main.go): `main.go`
- [Environment config](https://github.com/robby031/r2/blob/main/config/config.go): `config/config.go`

### Other components

- **API client**
- **Cloudflare R2**

## Connections

- API client → HTTP server: sends requests
- HTTP server → Environment config: loads settings (evidence: `main.go`)
- HTTP server → Gin router: serves routes (evidence: `main.go`)
- Environment config → Storage client: initializes (evidence: `config/config.go`)
- Gin router → File controllers: dispatches (evidence: `internal/controllers.go`)
- File controllers → Storage client: calls operations (evidence: `internal/controllers.go`)
- Storage client → Read cache: loads and invalidates (evidence: `storage/storage.go`)
- Storage client → Cloudflare R2: reads and writes objects (evidence: `storage/storage.go`)
