# azure-samples/digital-twins-explorer architecture

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

- Interactive diagram: https://gitdiagram.com/azure-samples/digital-twins-explorer
- Repository: https://github.com/azure-samples/digital-twins-explorer

## Overview

##### Project Type & Purpose
- The project is a full-stack application designed to help developers interact with Azure Digital Twins.
- It consists of a React-based client application (front end) and serverless back-end components implemented as Azure Functions (backend) that facilitate proxying requests, handling live telemetry via SignalR, and receiving notifications via Event Grid.

##### Analysis of the File Structure
- The top-level contains documentation, licensing, deployment scripts (e.g. Dockerfile, ARM templates under the “deployment” directory), and the “functions” folder for Azure Functions.
- The “client” folder holds the entire frontend code: configuration files, ESLint configuration, public assets (HTML and localization files) and a detailed “src” directory with multiple components (GraphViewerComponent, ModelViewerComponent, TwinViewerComponent, etc.), services (API, SignalR, Import/Export, Event), and utilities.
- The presence of extensive component subdirectories in “client/src/components” strongly indicates a modular, component-based UI built with React and using patterns like pub/sub messaging (via an EventService) to handle inter-component communication.
- The “functions” folder contains C#-based Azure Functions that play roles as Proxy, SignalR handlers, and EventGrid receivers, which are essential for communication with Azure Digital Twins in both local and cloud deployments.
- The “deployment” folder includes ARM templates which denote the infrastructure-as-code aspects needed for cloud deployment.

##### Elements
a. Main Components:
- Azure Functions (Backend Services): Identify key functions such as:
▪ Proxy function – for request forwarding to the Azure Digital Twins service.
▪ SignalR function – for live telemetry and client notifications.
▪ EventGrid function – for handling events from Azure Digital Twins.
- External Azure Services:
▪ Azure Digital Twins – the core external service holding the twin data.
▪ Azure SignalR – used to enable real-time client updates in the cloud.
▪ Azure Event Grid – for receiving and broadcasting event notifications.
- Deployment/Containerization: Include Docker (for containerized deployment) and ARM templates (for resource provisioning in Azure).

b. Relationships & Interactions:
▪ The React client issuing API calls (and using pub/sub events internally) to the Azure Functions proxy.
▪ Azure Functions interacting with the Azure Digital Twins service to retrieve and update twin data.
▪ Real-time communication flows from the SignalR function back to the client.
▪ Event flows from Azure Digital Twins sent via Event Grid to the functions and pushed to the client.

c. Architectural Patterns & Design Principles:
- Separation of concerns: UI (client) is decoupled from business logic/network calls in the backend (Azure Functions).
- Use of serverless architectures for backend processing and real-time communications.
- Use of plugin extensibility for import/export features, as well as a pub/sub event system for inter-component messaging within the client.
- Use of proxying (both in local development via setupProxy.js and in cloud deployments via Function proxies).

d. Technologies, Frameworks, and Libraries:
- Frontend: React, Golden Layout (for dynamic panel layouts), ESLint (code quality), and additional libraries such as Office Fabric UI for command bars.
- Backend: C# in Azure Functions, .NET Core, and integration with Azure services (Digital Twins, SignalR, Event Grid).
- Build/Deployment: Docker for containerization, ARM templates for infrastructure provisioning, and Node.js for the client’s development environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Client (Frontend)"
        CA["Client Application (React SPA)"]:::frontend
        GV["Graph Viewer Component"]:::frontend
        MV["Model Viewer Component"]:::frontend
        TV["Twin Viewer Component"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Azure Functions)"
        PF["Proxy Function"]:::backend
        SRF["SignalR Function"]:::backend
        EVF["EventGrid Function"]:::backend
    end

    %% Azure Cloud Services
    subgraph "Azure Cloud Services"
        ADT["Azure Digital Twins"]:::cloud
        ASR["Azure SignalR Service"]:::cloud
        AEG["Azure Event Grid"]:::cloud
    end

    %% Deployment Artifacts
    subgraph "Deployment"
        ARM1["ARM Template (Compute/Resources)"]:::deployment
        ARM2["ARM Template (EventGrid)"]:::deployment
        DOCKER["Docker Deployment"]:::deployment
    end

    %% Interactions from Client to Backend
    CA -->|"issuesAPICalls"| PF
    CA -->|"realTimeTelemetry"| SRF
    CA -->|"eventNotifications"| EVF

    %% UI Components integration within Client
    CA -->|"renders"| GV
    CA -->|"renders"| MV
    CA -->|"renders"| TV

    %% Backend interactions with Azure Services
    PF -->|"twinDataRequests"| ADT
    SRF -->|"pushRealtimeUpdates"| ASR
    EVF -->|"handleEvents"| AEG

    %% Azure Services sending updates back to Client via Backend
    ASR -->|"updateClients"| CA
    AEG -->|"eventDrivenUpdates"| CA

    %% Deployment artifacts provisioning
    ARM1 --> PF
    ARM1 --> SRF
    ARM1 --> ADT
    ARM1 --> ASR
    ARM2 --> EVF
    ARM2 --> AEG
    DOCKER --> CA
    DOCKER --> PF

    %% Click Events
    click CA "https://github.com/azure-samples/digital-twins-explorer/tree/main/client/"
    click GV "https://github.com/azure-samples/digital-twins-explorer/tree/main/client/src/components/GraphViewerComponent"
    click MV "https://github.com/azure-samples/digital-twins-explorer/tree/main/client/src/components/ModelViewerComponent"
    click TV "https://github.com/azure-samples/digital-twins-explorer/tree/main/client/src/components/TwinViewerComponent"
    click PF "https://github.com/azure-samples/digital-twins-explorer/blob/main/functions/Proxy.cs"
    click SRF "https://github.com/azure-samples/digital-twins-explorer/blob/main/functions/SignalR.cs"
    click EVF "https://github.com/azure-samples/digital-twins-explorer/blob/main/functions/EventGrid.cs"
    click ARM1 "https://github.com/azure-samples/digital-twins-explorer/blob/main/deployment/template.json"
    click ARM2 "https://github.com/azure-samples/digital-twins-explorer/blob/main/deployment/template-eventgrid.json"
    click DOCKER "https://github.com/azure-samples/digital-twins-explorer/tree/main/Dockerfile"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef backend fill:#f8bbd0,stroke:#880e4f,stroke-width:2px;
    classDef cloud fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef deployment fill:#fff9c4,stroke:#f57f17,stroke-width:2px;
```
