# managedcode/storage architecture

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

- Interactive diagram: https://gitdiagram.com/managedcode/storage
- Repository: https://github.com/managedcode/storage

## Overview

##### Main Components
- Core Library (ManagedCode.Storage.Core): Contains all the shared interfaces, base classes (e.g., IStorage, BaseStorage), common models, extensions (like ServiceCollectionExtensions), and helper classes.
- Storage Provider Implementations: Separate modules for each provider located under the “Storages” directory. These include:
– ManagedCode.Storage.Azure
– ManagedCode.Storage.Aws
– ManagedCode.Storage.Google
– ManagedCode.Storage.FileSystem
- Integration Components: Located under “Integraions” (such as ManagedCode.Storage.Client and ManagedCode.Storage.Server). These enable the library to work with ASP.NET and other hosting environments by supplying SignalR clients, extension methods for controllers, and background services.
- Test Infrastructure: Under “Tests” and “ManagedCode.Storage.TestFakes” which simulate various storage providers and demonstrate usage.

##### Relationships and Interactions
- At the top level, clients (for example, services in an ASP.NET application) inject an IStorage instance (or the provider-specific interface) into their constructors. This is achieved by using dependency injection and extension methods such as AddAzureStorage, AddAWSStorage, etc.
- The extension methods (found in several projects like the core and provider-specific extensions folders) register corresponding implementations with the DI container.
- Once registered, the universal IStorage abstraction internally resolves to a provider-specific implementation (e.g., IAzureStorage, IAWSStorage). Dependency inversion and factory patterns (e.g., using IStorageFactory) help abstract the differences.
- The “Core” library components call upon additional helper classes, such as those for stream handling (see Crc32Helper.cs, StreamHelper.cs) and provider creation logic.
- The integration layers (found under “Integraions/ManagedCode.Storage.Server”) offer additional functionality like controller extensions and background services for setup or maintenance of storage connections.
- The “TestFakes” module provides test doubles for cloud providers, making it easier to simulate provider behavior in testing scenarios.

##### Architectural Patterns and Design Principles
- Use of Dependency Injection: The extension methods tie together configuration and concrete storage implementations.
- Factory/Strategy Pattern: The library uses factories (via IStorageFactory) to select the appropriate storage provider at runtime.
- Abstraction and Wrapping: The idea is to wrap the indigenous APIs (Azure SDK, AWS S3, Google Cloud client libraries, file system operations) behind uniform interfaces.
- Separation of Concerns: Core/shared functionality is kept independent of storage-specific code, enabling easier maintenance and extension.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Application Layer
    A("Application / Service Layer"):::app

    %% Dependency Injection & Configuration
    B("DI - Storage Registrations"):::di

    %% Core Library
    C("ManagedCode.Storage.Core"):::core

    %% Provider Modules Subgraph
    subgraph "Provider Modules"
        subgraph "Azure Storage Providers"
            D1("Azure Storage Module"):::provider
            D2("Azure DataLake Module"):::provider
        end
        E("AWS Storage Module"):::provider
        F("Google Cloud Storage Module"):::provider
        G("FileSystem Storage Module"):::provider
    end

    %% Integration Layer - Client
    subgraph "Integration - Client"
        H1("Client Integration"):::integration
        H2("SignalR Integration"):::integration
    end

    %% Integration Layer - Server
    I("Integration - Server"):::integration

    %% Test/Mock Layer
    subgraph "Test/Mock Layer"
        J("Test Fakes"):::test
        K("Tests"):::test
    end

    %% Connections
    A -->|"injects"| B
    B -->|"registers"| C

    C -->|"implements"| D1
    C -->|"implements"| D2
    C -->|"implements"| E
    C -->|"implements"| F
    C -->|"implements"| G

    B -->|"registers"| H1
    B -->|"registers"| H2
    B -->|"registers"| I

    H1 -->|"uses"| C
    H2 -->|"uses"| C
    I  -->|"extends"| C

    J -->|"simulates"| D1
    J -->|"simulates"| D2
    J -->|"simulates"| E
    J -->|"simulates"| F
    J -->|"simulates"| G

    K -->|"validates"| C

    %% Click Events
    click C "https://github.com/managedcode/storage/tree/main/ManagedCode.Storage.Core/"
    click D1 "https://github.com/managedcode/storage/tree/main/Storages/ManagedCode.Storage.Azure/"
    click D2 "https://github.com/managedcode/storage/tree/main/Storages/ManagedCode.Storage.Azure.DataLake/"
    click E "https://github.com/managedcode/storage/tree/main/Storages/ManagedCode.Storage.Aws/"
    click F "https://github.com/managedcode/storage/tree/main/Storages/ManagedCode.Storage.Google/"
    click G "https://github.com/managedcode/storage/tree/main/Storages/ManagedCode.Storage.FileSystem/"
    click H1 "https://github.com/managedcode/storage/tree/main/Integraions/ManagedCode.Storage.Client/"
    click H2 "https://github.com/managedcode/storage/tree/main/Integraions/ManagedCode.Storage.Client.SignalR/"
    click I "https://github.com/managedcode/storage/tree/main/Integraions/ManagedCode.Storage.Server/"
    click J "https://github.com/managedcode/storage/tree/main/ManagedCode.Storage.TestFakes/"
    click K "https://github.com/managedcode/storage/tree/main/Tests/"

    %% Class Definitions for Styling
    classDef app fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef di fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef core fill:#66ccff,stroke:#333,stroke-width:2px;
    classDef provider fill:#b3ffb3,stroke:#333,stroke-width:2px;
    classDef integration fill:#ffff99,stroke:#333,stroke-width:2px;
    classDef test fill:#ffcccc,stroke:#333,stroke-width:2px;
```
