# azure/azurestor architecture

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

- Interactive diagram: https://gitdiagram.com/azure/azurestor
- Repository: https://github.com/azure/azurestor

## Overview

##### Main Components
- Client Interface: Includes S3 method implementations for managing storage objects (files, blobs, etc.) and for performing file transfers.
- Admin Interface: Built on top of AzureRMR with R6 classes; this part manages storage account creation, deletion, key management, and SAS token generation.
- Storage Endpoints: The central abstraction provided by the “storage_endpoint” function which determines the type of storage (blob, file, or ADLS) and handles authentication (access key, SAS, AAD token).
- Transfer Utilities: Components for uploading and downloading files, including support for parallel transfers, file format helpers (CSV, RDS, etc.), connection-based transfers, and integration with AzCopy.
- Authentication & Authorization: Modules that support multiple authentication mechanisms (access keys, SAS, OAuth tokens/AAD tokens). This includes integration with AzureRMR and AzureAuth in case of AAD tokens.
- External Dependencies: Integration with external components like the AzCopy utility (for high-performance file transfers) and the AzureRMR package.

##### Relationships and Interactions
- The admin side interacts with the Azure Resource Manager via AzureRMR. This module is responsible for creating, listing, and deleting storage accounts along with retrieving authentication keys and SAS tokens.
- The endpoints for blob, file, and ADLS storage should be displayed as separate components (or as subcomponents under a “Storage Endpoints” node) that share similar interfaces but differ in authentication method and supported operations.

##### Architectural Patterns / Design Principles
- Modular Design: Different R scripts (found in the “R” directory) encapsulate different functionalities (e.g., azcopy support, lease management, generic transfer utilities). Represent these modules as distinct nodes or layers.

##### Technologies, Frameworks, and Libraries
- Specify that this is an R package using S3/S4 methods and R6 classes.
- AzureRMR for resource management and AzureAuth for authentication.
- AzCopy as an external command-line utility that is invoked from within the package’s functions.
- Use of parallel processing (via background process pools) for file transfers.

##### Design
- Descriptive notes where necessary (for example: “Handles both SAS and AAD token-based authentication” or “Utilizes parallel transfers for efficiency”).

##### Additional Elements
- Don’t forget to indicate test components (the “tests” directory) and documentation (the “man” and “vignettes” folders), which reflect a well-documented, testable system design. While these might not be central to runtime architecture, they emphasize the project’s organization.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Interface"
        direction TB
        ClientBlob("Blob Client Functions"):::client
        ClientFile("File Client Functions"):::client
        ClientGenerics("Client Generics"):::client
        ClientBlobDoc("Blob Documentation"):::doc
        ClientFileDoc("File Documentation"):::doc
        ClientFileTransferDoc("FileTransfer Documentation"):::doc
    end

    subgraph "Admin Interface"
        direction TB
        AdminAzureStor("AzureStor Admin Function"):::admin
        AdminCreateDoc("CreateStorageAccount Documentation"):::doc
        AdminDeleteDoc("DeleteStorageAccount Documentation"):::doc
        AdminGetDoc("GetStorageAccount Documentation"):::doc
    end

    subgraph "Storage Endpoints"
        direction TB
        EndpointFunction("Storage Endpoint Function"):::endpoint
        EndpointDocs("StorageEndpoint Documentation"):::doc
    end

    subgraph "Transfer Utilities"
        direction TB
        TU_Azcopy("AzCopy Transfer Function"):::transfer
        TU_BlobTransfer("Blob Transfer Internal"):::transfer
        TU_BlobUpload("Blob Upload Internal"):::transfer
        TU_FileTransfer("File Transfer Internal"):::transfer
        TU_TransferUtils("Transfer Utils"):::transfer
        TU_FormatUtils("TransferFormat Utils"):::transfer
        TU_DownloadDest("Download Destination"):::transfer
        TU_AzcopyDoc("AzCopy Documentation"):::doc
        TU_FileTransferDoc("FileTransfer Documentation"):::doc
    end

    subgraph "Authentication & Authorization"
        direction TB
        Auth_AzcopyAuth("AzCopy Auth"):::auth
        Auth_SAS("SAS Functions"):::auth
        Auth_SignRequest("Sign Request"):::auth
        Auth_SASDoc("SAS Documentation"):::auth
        Auth_SignRequestDoc("SignRequest Documentation"):::auth
    end

    subgraph "External Dependencies"
        direction TB
        External_AzCopy("AzCopy Utility"):::external
        External_AzureRMR("AzureRMR Integration"):::external
    end

    subgraph "Supporting Components"
        direction TB
        Docs("Documentation (man & vignettes)"):::doc
        Tests("Tests"):::test
    end

    %% Connections
    ClientBlob -->|"calls"| EndpointFunction
    ClientFile -->|"calls"| EndpointFunction
    ClientGenerics -->|"calls"| EndpointFunction
    ClientGenerics -->|"authUses"| Auth_SAS

    EndpointFunction -->|"triggers"| TU_BlobTransfer
    EndpointFunction -->|"triggers"| TU_FileTransfer

    TU_Azcopy -->|"invokes"| External_AzCopy
    TU_Azcopy -->|"requires"| Auth_SAS

    AdminAzureStor -->|"manages"| External_AzureRMR
    AdminAzureStor -->|"uses"| EndpointFunction

    %% Supporting links
    Docs --- Tests
    Docs --- ClientGenerics
    Docs --- AdminAzureStor

    %% Click Events for Client Interface
    click ClientBlob "https://github.com/azure/azurestor/blob/master/R/blob_client_funcs.R"
    click ClientFile "https://github.com/azure/azurestor/blob/master/R/file_client_funcs.R"
    click ClientGenerics "https://github.com/azure/azurestor/blob/master/R/client_generics.R"
    click ClientBlobDoc "https://github.com/azure/azurestor/blob/master/man/blob.Rd"
    click ClientFileDoc "https://github.com/azure/azurestor/blob/master/man/file.Rd"
    click ClientFileTransferDoc "https://github.com/azure/azurestor/blob/master/man/file_transfer.Rd"

    %% Click Events for Admin Interface
    click AdminAzureStor "https://github.com/azure/azurestor/blob/master/R/AzureStor.R"
    click AdminCreateDoc "https://github.com/azure/azurestor/blob/master/man/create_storage_account.Rd"
    click AdminDeleteDoc "https://github.com/azure/azurestor/blob/master/man/delete_storage_account.Rd"
    click AdminGetDoc "https://github.com/azure/azurestor/blob/master/man/get_storage_account.Rd"

    %% Click Events for Storage Endpoints
    click EndpointFunction "https://github.com/azure/azurestor/blob/master/R/client_endpoint.R"
    click EndpointDocs "https://github.com/azure/azurestor/blob/master/man/storage_endpoint.Rd"

    %% Click Events for Transfer Utilities
    click TU_Azcopy "https://github.com/azure/azurestor/blob/master/R/azcopy.R"
    click TU_BlobTransfer "https://github.com/azure/azurestor/blob/master/R/blob_transfer_internal.R"
    click TU_BlobUpload "https://github.com/azure/azurestor/blob/master/R/blob_upload_internal.R"
    click TU_FileTransfer "https://github.com/azure/azurestor/blob/master/R/file_transfer_internal.R"
    click TU_TransferUtils "https://github.com/azure/azurestor/blob/master/R/transfer_utils.R"
    click TU_FormatUtils "https://github.com/azure/azurestor/blob/master/R/transfer_format_utils.R"
    click TU_DownloadDest "https://github.com/azure/azurestor/blob/master/R/download_dest.R"
    click TU_AzcopyDoc "https://github.com/azure/azurestor/blob/master/man/azcopy.Rd"
    click TU_FileTransferDoc "https://github.com/azure/azurestor/blob/master/man/file_transfer.Rd"

    %% Click Events for Authentication & Authorization
    click Auth_AzcopyAuth "https://github.com/azure/azurestor/blob/master/R/azcopy_auth.R"
    click Auth_SAS "https://github.com/azure/azurestor/blob/master/R/sas.R"
    click Auth_SignRequest "https://github.com/azure/azurestor/blob/master/R/sign_request.R"
    click Auth_SASDoc "https://github.com/azure/azurestor/blob/master/man/sas.Rd"
    click Auth_SignRequestDoc "https://github.com/azure/azurestor/blob/master/man/sign_request.Rd"

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef admin fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef endpoint fill:#d6d8db,stroke:#343a40,stroke-width:2px;
    classDef transfer fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef auth fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef doc fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef test fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
