# microsoft/proxy architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/proxy
- Repository: https://github.com/microsoft/proxy

## Overview

Based on our analysis of the file structure and README file, this project is an open‐source, header-only C++20 library designed to offer next-generation, pointer-semantics-based polymorphism without relying on conventional inheritance. The primary purpose is to simplify managing polymorphic objects (including their lifetime and behavior) and to provide a highly flexible facade/dispatch framework that supports various types of expressions (member function calls, free functions, operator calls, conversions, etc.) in a way that is both efficient and extensible.

##### Main Architectural Components
- Core Library Interface – At the heart of the system is the header “proxy.h” along with the underlying facade builder mechanisms (for example, the “facade_builder” used to build custom facades such as Formattable, Streamable, Drawable, etc.). This is the central component where users include the header and gain access to all functionalities.
- Dispatch and Convention Modules – Identify various dispatch types and conventions defined either via macros (e.g., PRO_DEF_MEM_DISPATCH, PRO_DEF_FREE_DISPATCH) or through class templates (e.g., operator_dispatch, explicit_conversion_dispatch, implicit_conversion_dispatch, weak_dispatch). These modules are responsible for evaluating expressions at run-time and binding the abstraction to concrete implementations.
- Memory and Object Ownership Management – The library supports object lifetime management through different ownership models: raw pointer proxies, unique ownership (using std::unique_ptr), shared and weak ownership (via make_proxy_shared and related aliases). This layer abstracts how the underlying object storage is managed.
- Utility Components and Extensions – These include reflection (using proxy_reflect), support for standard formatting (“std::format”, stream insertion, etc.), and additional features like allocator awareness, copy support, relocation, and runtime type information (RTTI).

##### Supporting Infrastructure
- Samples – The “samples” directory shows usage examples that illustrate how to build and use different facade types in various scenarios (formatting, streaming, drawing, etc.).
- Tests – Unit tests (in the “tests” directory) ensure the correctness of proxy creation, dispatch capabilities, and lifetime management.
- Benchmarks – The “benchmarks” directory highlights performance-related tests that quantify how the proxy mechanism performs versus classical approaches.
- Build and CI Infrastructure – The project uses CMake (with CMakeLists.txt at various levels) for building. GitHub Actions workflows (located in .github/workflows) automate continuous integration and release pipelines.

##### Diagrammatic Elements
- Dependencies (for instance, the dependency of the proxy objects on the facade built at compile-time, and the integration with standard library formatting or streaming facilities).

## Diagram (Mermaid)

```mermaid
flowchart TD 
    Client["Client Code (Samples)"]:::support
    ProxyCore["Proxy Library Core\n(proxy.h)"]:::core
    Client -->|"usesAPI"| ProxyCore

    subgraph "Facade Builder"
        FacadeDocs["Facade Builder (Docs)"]:::core
        FacadeSamples["Facade Builder (Samples)"]:::core
    end

    subgraph "Dispatch Modules (Docs)"
        MDispatchDocs["Mem Dispatch (Docs)"]:::dispatch
        FDispatchDocs["Free Dispatch (Docs)"]:::dispatch
        ODispatchDocs["Operator Dispatch (Docs)"]:::dispatch
        EConvDispatchDocs["ExplicitConversionDispatch (Docs)"]:::dispatch
        IConvDispatchDocs["ImplicitConversionDispatch (Docs)"]:::dispatch
        WDispatchDocs["WeakDispatch (Docs)"]:::dispatch
    end

    subgraph "Dispatch Modules (Samples)"
        MDispatchSample["Mem Dispatch (Sample)"]:::dispatch
        FDispatchSample["Free Dispatch (Sample)"]:::dispatch
        ODispatchSample["Operator Dispatch (Sample)"]:::dispatch
        EConvDispatchSample["ExplicitConversionDispatch (Sample)"]:::dispatch
        IConvDispatchSample["ImplicitConversionDispatch (Sample)"]:::dispatch
        WDispatchSample["WeakDispatch (Sample)"]:::dispatch
    end

    subgraph "Memory Management (Docs)"
        MakeProxyDocs["make_proxy (Docs)"]:::memory
        MakeProxySharedDocs["make_proxy_shared (Docs)"]:::memory
        AllocProxyDocs["allocate_proxy (Docs)"]:::memory
        AllocProxySharedDocs["allocate_proxy_shared (Docs)"]:::memory
    end

    subgraph "Memory Management (Samples)"
        MakeProxySample["make_proxy (Sample)"]:::memory
        MakeProxySharedSample["make_proxy_shared (Sample)"]:::memory
        AllocProxySample["allocate_proxy (Sample)"]:::memory
        AllocProxySharedSample["allocate_proxy_shared (Sample)"]:::memory
    end

    subgraph "Utility Components (Docs)"
        ReflectDocs["ProxyReflect (Docs)"]:::utility
        FormatterDocs["FormatterProxyIndirectAccessor (Docs)"]:::utility
    end

    subgraph "Utility Components (Samples)"
        ReflectSample["ProxyReflect (Sample)"]:::utility
        FormatterSample["FormatterProxyIndirectAccessor (Sample)"]:::utility
    end

    subgraph "Supporting Infrastructure"
        Samples["Samples Directory"]:::support
        Tests["UnitTests"]:::support
        Benchmarks["Benchmarks"]:::support
        subgraph "CI/Build Infrastructure"
            CMake["CMake BuildFiles"]:::support
            GitHub["GitHubWorkflows"]:::support
        end
    end

    %% Core components connections
    ProxyCore -->|"buildsFacade"| FacadeDocs
    ProxyCore -->|"buildsFacade"| FacadeSamples

    FacadeDocs -->|"invokesDispatch"| MDispatchDocs
    FacadeDocs -->|"invokesDispatch"| FDispatchDocs
    FacadeDocs -->|"invokesDispatch"| ODispatchDocs
    FacadeDocs -->|"invokesDispatch"| EConvDispatchDocs
    FacadeDocs -->|"invokesDispatch"| IConvDispatchDocs
    FacadeDocs -->|"invokesDispatch"| WDispatchDocs

    FacadeSamples -->|"invokesDispatch"| MDispatchSample
    FacadeSamples -->|"invokesDispatch"| FDispatchSample
    FacadeSamples -->|"invokesDispatch"| ODispatchSample
    FacadeSamples -->|"invokesDispatch"| EConvDispatchSample
    FacadeSamples -->|"invokesDispatch"| IConvDispatchSample
    FacadeSamples -->|"invokesDispatch"| WDispatchSample

    ProxyCore -->|"managesObjects"| MakeProxyDocs
    ProxyCore -->|"managesObjects"| MakeProxySharedDocs
    ProxyCore -->|"managesObjects"| AllocProxyDocs
    ProxyCore -->|"managesObjects"| AllocProxySharedDocs

    ProxyCore -->|"managesObjects"| MakeProxySample
    ProxyCore -->|"managesObjects"| MakeProxySharedSample
    ProxyCore -->|"managesObjects"| AllocProxySample
    ProxyCore -->|"managesObjects"| AllocProxySharedSample

    ProxyCore -->|"integrates"| ReflectDocs
    ProxyCore -->|"integrates"| FormatterDocs
    ProxyCore -->|"integrates"| ReflectSample
    ProxyCore -->|"integrates"| FormatterSample

    %% Supporting infrastructure links
    Tests -->|"validate"| ProxyCore
    Benchmarks -->|"measure"| ProxyCore
    CMake -->|"builds"| ProxyCore
    GitHub -->|"builds"| ProxyCore
    Samples -->|"demonstrate"| ProxyCore

    %% Click Events
    click ProxyCore "https://github.com/microsoft/proxy/blob/main/proxy.h"
    click FacadeDocs "https://github.com/microsoft/proxy/tree/main/docs/basic_facade_builder/"
    click FacadeSamples "https://github.com/microsoft/proxy/tree/main/samples/basic_facade_builder/"
    click MDispatchDocs "https://github.com/microsoft/proxy/blob/main/docs/PRO_DEF_MEM_DISPATCH.md"
    click FDispatchDocs "https://github.com/microsoft/proxy/blob/main/docs/PRO_DEF_FREE_DISPATCH.md"
    click ODispatchDocs "https://github.com/microsoft/proxy/tree/main/docs/operator_dispatch/"
    click EConvDispatchDocs "https://github.com/microsoft/proxy/tree/main/docs/explicit_conversion_dispatch/"
    click IConvDispatchDocs "https://github.com/microsoft/proxy/tree/main/docs/implicit_conversion_dispatch/"
    click WDispatchDocs "https://github.com/microsoft/proxy/tree/main/docs/weak_dispatch/"
    click MDispatchSample "https://github.com/microsoft/proxy/blob/main/samples/PRO_DEF_MEM_DISPATCH.cpp"
    click FDispatchSample "https://github.com/microsoft/proxy/blob/main/samples/PRO_DEF_FREE_DISPATCH.cpp"
    click ODispatchSample "https://github.com/microsoft/proxy/blob/main/samples/operator_dispatch.cpp"
    click EConvDispatchSample "https://github.com/microsoft/proxy/blob/main/samples/explicit_conversion_dispatch.cpp"
    click IConvDispatchSample "https://github.com/microsoft/proxy/blob/main/samples/implicit_conversion_dispatch.cpp"
    click WDispatchSample "https://github.com/microsoft/proxy/blob/main/samples/weak_dispatch.cpp"
    click MakeProxyDocs "https://github.com/microsoft/proxy/blob/main/docs/make_proxy.md"
    click MakeProxySharedDocs "https://github.com/microsoft/proxy/blob/main/docs/make_proxy_shared.md"
    click AllocProxyDocs "https://github.com/microsoft/proxy/blob/main/docs/allocate_proxy.md"
    click AllocProxySharedDocs "https://github.com/microsoft/proxy/blob/main/docs/allocate_proxy_shared.md"
    click MakeProxySample "https://github.com/microsoft/proxy/blob/main/samples/make_proxy.cpp"
    click MakeProxySharedSample "https://github.com/microsoft/proxy/blob/main/samples/make_proxy_shared.cpp"
    click AllocProxySample "https://github.com/microsoft/proxy/blob/main/samples/allocate_proxy.cpp"
    click AllocProxySharedSample "https://github.com/microsoft/proxy/blob/main/samples/allocate_proxy_shared.cpp"
    click ReflectDocs "https://github.com/microsoft/proxy/blob/main/docs/proxy_reflect.md"
    click FormatterDocs "https://github.com/microsoft/proxy/blob/main/docs/formatter_proxy_indirect_accessor.md"
    click ReflectSample "https://github.com/microsoft/proxy/blob/main/samples/proxy_reflect.cpp"
    click FormatterSample "https://github.com/microsoft/proxy/tree/main/samples/formatter_proxy_indirect_accessor/"
    click Samples "https://github.com/microsoft/proxy/tree/main/samples/"
    click Tests "https://github.com/microsoft/proxy/tree/main/tests/"
    click Benchmarks "https://github.com/microsoft/proxy/tree/main/benchmarks/"
    click CMake "https://github.com/microsoft/proxy/blob/main/CMakeLists.txt"
    click GitHub "https://github.com/microsoft/proxy/tree/main/.github/workflows/"

    %% Styling
    classDef core fill:#FFDDCC,stroke:#333,stroke-width:2px;
    classDef dispatch fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef memory fill:#CCCCFF,stroke:#333,stroke-width:2px;
    classDef utility fill:#FFF2CC,stroke:#333,stroke-width:2px;
    classDef support fill:#F0F0F0,stroke:#333,stroke-width:2px;
```
