# Topology

## Device topologies

OpenGate platform supports different device connection strategies. The following sections explain these connection strategies.

## Direct connection strategy

Direct connection strategy is the most common connection scenario. Gateways and devices use it.

```mermaid
flowchart BT
    GA["GatewayA"]
    GB["GatewayB"]
    NET(["Internet"])
    OG["OpenGate Platform"]

    GA -.-> NET
    GB -.-> NET
    NET -.-> OG

    classDef platform fill:#fde8c8,stroke:#c98f2b,color:#000
    classDef node fill:#e2e4e8,stroke:#8a8f98,color:#000
    class OG platform
    class GA,GB node
```

Each device reaches the platform on its own, with no intermediate node to traverse: `deviceId` alone
identifies the destination, and `path` is empty.

## Indirect connection strategy

Devices behind gateways and complex connection scenarios like non-transparent mesh networks use an **indirect connection strategy**.

OpenGate supports these scenarios using a path. The path is an array of nodes (devices) to be traversed to reach the destination:

```mermaid
flowchart BT
    D11["Device_1_1"]
    D12["Device_1_2"]
    MESH2(["mesh network"])
    D1["Device_1"]
    MESH1(["mesh network"])
    GA["GatewayA"]
    GB["GatewayB"]
    NET(["Internet"])
    OG["OpenGate Platform"]

    D11 -.-> MESH2
    D12 -.-> MESH2
    MESH2 -.-> D1
    D1 -.-> MESH1
    MESH1 -.-> GA
    GA -.-> NET
    GB -.-> NET
    NET -.-> OG

    classDef platform fill:#fde8c8,stroke:#c98f2b,color:#000
    classDef node fill:#e2e4e8,stroke:#8a8f98,color:#000
    class OG platform
    class D11,D12,D1,GA,GB node
```

- The endpoint device, in case of operations, diagnostics sent by the platform.
- The platform, in case of events, responses, etc., sent by the on-field device.

### Indirect connection scenarios

Taking an indirect connection scenario, we have:

- A gateway device with the id: `GatewayA`
- An intermediate device connected to the gateway with the id: `Device_1`
- Two endpoint devices connected to the intermediate device with the ids: `Device_1_1` and `Device_1_2` respectively.

From a platform point of view, the `path` and `deviceId` parameter values are:

- To reach the Gateway:
  - `"deviceId": "GatewayA"`
  - `"path": []`
- To reach the intermediate device:
  - `"deviceId": "Device_1"`
  - `"path": ["GatewayA"]`
- To reach an endpoint device:
  - `"deviceId": "Device_1_1"`
  - `"path": ["GatewayA", "Device_1"]`
