# ilyabrin/disk architecture

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

- Interactive diagram: https://gitdiagram.com/ilyabrin/disk
- Repository: https://github.com/ilyabrin/disk

## Overview

##### Main Components
- User Application
– Your Go program that imports “github.com/ilyabrin/disk” and calls its methods (e.g., DiskInfo).
- Disk Library (“ilyabrin/disk” package)
– Client Constructor (client.go)
– HTTP Transport & Authentication (embedded in client.go/helpers.go)
– API Operations (operations.go)
– Resource Type Definitions (types.go, resources.go)
– Utility Helpers & Error Handling (helpers.go, trash.go, public.go, etc.)
– Test Suites ( *_test.go )
- External Service
– Yandex.Disk REST API endpoints (https://cloud-api.yandex.net)

##### Relationships & Data Flows
- The User Application calls the Disk client’s public methods (e.g., client.New(), client.DiskInfo(ctx)).
- Client constructs an HTTP request, injecting the YANDEX_DISK_ACCESS_TOKEN in headers.
- HTTP Transport sends requests to Yandex.Disk REST API.
- Yandex API returns JSON, which the library’s types + helpers unmarshal into Go structs.
- Library returns typed results or errors back to the User Application.

##### Architectural Patterns & Design Principles
- Modular Package Layout
– Separation of concerns: construction (client.go), operations (operations.go), types (types.go), helpers (helpers.go).
- Dependency Injection for HTTP client (allows custom HTTP.Client or mock transport in tests).
- Clear public vs. private API: exported functions/types vs. internal helpers.
- Table-driven tests covering each module.

##### Relevant Technologies & Frameworks
- Language: Go
- HTTP: net/http
- JSON: encoding/json
- Testing: testing package + possibly testify
- CI/CD: GitHub Actions, CodeQL, Dependabot

##### Putting It All Together
– Within the Library column, subdivide into:
- Client & Auth
- Operations
- Types & Resources
- Helpers & Error Handling
- Tests (optional, maybe as a separate cluster)
1. New() → HTTP client setup
2. DiskInfo(ctx) → operations.go → buildRequest()
3. HTTP transport → Yandex.Disk API
4. JSON response → unmarshal → Go struct
5. Return to caller or error

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layer 1: User Application
    subgraph "Layer 1: User Application"
        UA["User Application"]:::app
    end

    %% Layer 2: ilyabrin/disk Library
    subgraph "Layer 2: ilyabrin/disk Library"
        subgraph "Public API Entrypoint"
            PA["Public API Entrypoint\n(disk.go)"]:::lib
        end
        subgraph "Client & Auth"
            CC["Client Constructor\n(client.go)"]:::lib
            HT["HTTP Transport & Authentication\n(helpers.go)"]:::lib
        end
        subgraph "API Operations"
            OP["API Operations\n(operations.go)"]:::lib
        end
        subgraph "Types & Resources"
            TY["Resource Type Definitions\n(types.go, resources.go)"]:::lib
        end
        subgraph "Helpers & Error Handling"
            HE["Utility Helpers & Error Handling\n(helpers.go, trash.go, public.go)"]:::lib
        end
        subgraph "Test Suites"
            T1["client_test.go"]:::test
            T2["disk_test.go"]:::test
            T3["helpers_test.go"]:::test
            T4["public_test.go"]:::test
            T5["resources_test.go"]:::test
        end
    end

    %% Layer 3: External Service
    subgraph "Layer 3: External Service"
        EA["Yandex.Disk REST API\n(cloud-api.yandex.net)"]:::external
    end

    %% Connections
    UA -->|"New() / DiskInfo(ctx)"| PA
    PA -->|"constructs client"| CC
    CC -->|"injects auth"| HT
    PA -->|"calls operations"| OP
    OP -->|"buildRequest()"| HT
    HT -->|"HTTP Request\nAuthorization Token"| EA
    EA -->|"JSON Response"| HT
    HT -->|"unmarshal JSON"| TY
    TY -->|"returns structs"| PA
    PA -->|"returns result / error"| UA
    HT -.->|"network/json error"| HE
    HE -.->|"error return"| UA

    %% Click Events
    click CC "https://github.com/ilyabrin/disk/blob/release/client.go"
    click HT "https://github.com/ilyabrin/disk/blob/release/helpers.go"
    click OP "https://github.com/ilyabrin/disk/blob/release/operations.go"
    click TY "https://github.com/ilyabrin/disk/blob/release/types.go"
    click TY "https://github.com/ilyabrin/disk/blob/release/resources.go"
    click HE "https://github.com/ilyabrin/disk/blob/release/helpers.go"
    click HE "https://github.com/ilyabrin/disk/blob/release/trash.go"
    click HE "https://github.com/ilyabrin/disk/blob/release/public.go"
    click PA "https://github.com/ilyabrin/disk/blob/release/disk.go"
    click T1 "https://github.com/ilyabrin/disk/blob/release/client_test.go"
    click T2 "https://github.com/ilyabrin/disk/blob/release/disk_test.go"
    click T3 "https://github.com/ilyabrin/disk/blob/release/helpers_test.go"
    click T4 "https://github.com/ilyabrin/disk/blob/release/public_test.go"
    click T5 "https://github.com/ilyabrin/disk/blob/release/resources_test.go"
    click CI1 "https://github.com/ilyabrin/disk/blob/release/.github/workflows/codeql.yml"
    click CI2 "https://github.com/ilyabrin/disk/blob/release/.github/workflows/test.yml"
    click DM1 "https://github.com/ilyabrin/disk/blob/release/go.mod"
    click DM2 "https://github.com/ilyabrin/disk/blob/release/go.sum"

    %% Styles
    classDef app fill:#e0f7e9,stroke:#2e7d32,color:#2e7d32
    classDef lib fill:#e3f2fd,stroke:#1565c0,color:#1565c0
    classDef external fill:#ffebee,stroke:#c62828,color:#c62828
    classDef test fill:#f3e5f5,stroke:#6a1b9a,color:#6a1b9a
```
