# openthread/ot-br-posix architecture

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

- Interactive diagram: https://gitdiagram.com/openthread/ot-br-posix
- Repository: https://github.com/openthread/ot-br-posix

## Overview

##### Project type and purpose
- This is a network‐services project (OpenThread Border Router, “OTBR”). It implements a POSIX‐based daemon that bridges a Thread mesh network to external IP networks (Ethernet/Wi-Fi) and exposes control interfaces (DBus, REST, Web UI).
- Its purpose:
- Route IPv6 between Thread and LAN/WAN
- Provide mDNS/SRP service discovery
- Handle DHCPv6 prefix delegation and NAT64
- Support external commissioning (mobile apps)

##### File structure
- Top‐level build & config:
- CMakeLists.txt, etc/cmake, etc/docker, etc/openwrt, etc/yocto
- .github/workflows for CI (build, Docker images, platform tests)
- Source code modules under src/:
- src/agent: the core OTBR agent daemon
- src/border_agent: Thread‐side commissioning & network management
- src/backbone_router: IPv6 backbone routing & DUA manager
- src/host: interaction with the Thread radio (NCP/SPINEL) on POSIX
- src/dbus: DBus client/server glue for external control
- src/mdns: mDNS over LAN and interface to SRP on Thread
- src/rest: REST-JSON server for ot-ctl‐style HTTP API
- src/web: embedded web server + single-page app front end
- src/sdp_proxy, src/trel_dnssd: service discovery proxies
- src/utils, src/common: shared utilities, main loop, logging
- src/proto: Protocol‐Buffers definitions for telemetry & features
- src/openwrt: scripts & glue for OpenWRT package
- Example deployments under examples/platforms (Raspberry Pi, NXP, Ubuntu, etc.)
- Tests under tests/ for each subsystem (gtest, DBus, mDNS, REST, scripts)
- Third-party libraries: cJSON, cpp-httplib, upstream OpenThread

##### README for additional insights
- Focus is on “Border Router” functions and multi‐interface support.

##### Detail without overthinking
- Break the system into as many distinct logical components as useful (e.g., NCP driver, commissioning manager, DUA manager, mDNS adapter, HTTP server thread)
- Network interfaces and IPC/RPC layers

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Systems
    Radio["Thread Radio (NCP)"]:::external
    LANWAN["Ethernet/Wi-Fi LAN\nIPv4/IPv6 WAN"]:::external

    %% Physical Layer
    subgraph "Physical Layer"
        Radio
    end

    %% Host Networking Layer
    subgraph "Host Networking Layer"
        HostStack["Host Stack\n(src/host)"]:::dataplane
    end
    click HostStack "https://github.com/openthread/ot-br-posix/tree/main/src/host/"

    %% Core Agent Layer
    subgraph "OTBR Agent Core" 
        AgentCore["Agent Core\n(src/agent)"]:::core
        BorderAgent["Border Agent\n(src/border_agent)"]:::core
        BackboneRouter["Backbone Router\n(src/backbone_router)"]:::dataplane
    end
    click AgentCore "https://github.com/openthread/ot-br-posix/tree/main/src/agent/"
    click BorderAgent "https://github.com/openthread/ot-br-posix/tree/main/src/border_agent/"
    click BackboneRouter "https://github.com/openthread/ot-br-posix/tree/main/src/backbone_router/"

    %% Service Discovery
    subgraph "Service Discovery" 
        MDNS["mDNS\n(src/mdns)"]:::service
        SDPProxy["SDP Proxy\n(src/sdp_proxy)"]:::service
        TRELDNSSD["TREL DNS-SD\n(src/trel_dnssd)"]:::service
    end
    click MDNS "https://github.com/openthread/ot-br-posix/tree/main/src/mdns/"
    click SDPProxy "https://github.com/openthread/ot-br-posix/tree/main/src/sdp_proxy/"
    click TRELDNSSD "https://github.com/openthread/ot-br-posix/tree/main/src/trel_dnssd/"

    %% Control Interfaces
    subgraph "Control Interfaces" 
        DBusAPI["DBus API\n(src/dbus)"]:::control
        RESTAPI["REST/HTTP API\n(src/rest)"]:::control
        WebUI["Web UI\n(src/web)"]:::control
    end
    click DBusAPI "https://github.com/openthread/ot-br-posix/tree/main/src/dbus/"
    click RESTAPI "https://github.com/openthread/ot-br-posix/tree/main/src/rest/"
    click WebUI "https://github.com/openthread/ot-br-posix/tree/main/src/web/"

    %% IPv6 Functions & Scripts
    subgraph "IPv6 Network Functions & Scripts"
        Scripts["Scripts & Sidecars\n(script/)"]:::script
    end
    click Scripts "https://github.com/openthread/ot-br-posix/tree/main/script/"

    %% Packaging & Deployment
    subgraph "Packaging & Deployment"
        Docker["Docker\n(etc/docker)"]:::packaging
        OpenWRT["OpenWRT\n(etc/openwrt/src/openwrt)"]:::packaging
        Yocto["Yocto\n(etc/yocto)"]:::packaging
    end
    click Docker "https://github.com/openthread/ot-br-posix/tree/main/etc/docker/"
    click OpenWRT "https://github.com/openthread/ot-br-posix/tree/main/src/openwrt/"
    click Yocto "https://github.com/openthread/ot-br-posix/tree/main/etc/yocto/"

    %% Relationships
    Radio -->|SPINEL| HostStack
    HostStack -->|netif/multicast routing| AgentCore
    AgentCore -->|commissioning| BorderAgent
    AgentCore -->|IPv6 routing| BackboneRouter
    AgentCore -->|use| MDNS
    AgentCore -->|use| SDPProxy
    AgentCore -->|use| TRELDNSSD
    AgentCore -->|expose| DBusAPI
    AgentCore -->|expose| RESTAPI
    RESTAPI -->|serves| WebUI
    AgentCore -->|invoke| Scripts
    LANWAN -->|data-plane| BackboneRouter
    LANWAN -->|control-plane| DBusAPI

    %% Styles
    classDef dataplane fill:#E0F7FA,stroke:#00BCD4,color:#000
    classDef control fill:#E8F5E9,stroke:#4CAF50,color:#000
    classDef external fill:#FFF3E0,stroke:#FF9800,color:#000
    classDef core fill:#E3F2FD,stroke:#2196F3,color:#000
    classDef service fill:#F3E5F5,stroke:#9C27B0,color:#000
    classDef script fill:#FBE9E7,stroke:#FF5722,color:#000
    classDef packaging fill:#ECEFF1,stroke:#607D8B,color:#000
```
