# golioth/golioth-firmware-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/golioth/golioth-firmware-sdk
- Repository: https://github.com/golioth/golioth-firmware-sdk

## Overview

##### Main Components

a. Platform Layer:
- Supported platforms (ESP-IDF, ModusToolbox, Zephyr/NCS, Linux) as base components
- Platform-specific ports (/port directory) for each supported system
- Platform abstraction through golioth_sys interface

b. Core SDK Layer:
- CoAP Client implementation (src/coap_client*.c files)
- Authentication mechanisms (src/Kconfig.authentication)
- Event handling system (src/event_group.c)

c. Service Layer:
- LightDB State (lightdb_state.c)
- Firmware Updates (fw_update.c)
- Logging (log.c)
- RPC (rpc.c)
- Settings (settings.c)
- Stream (stream.c)
- Location Services (location.c, location_wifi.c)

d. External Dependencies:
- libcoap (external/libcoap)
- zcbor (external/zcbor)
- Unity testing framework (external/unity)

##### Connection Flow

- Data flow from embedded device through platform layer
- Platform abstraction layer interaction with core services
- Service layer communication with Golioth cloud
- Authentication and security paths

##### Specific Implementation Details

- CoAP protocol implementation
- ZCBOR encoding/decoding
- Platform-specific network stacks
- Hardware abstraction layer

##### Testing Infrastructure

Separate section for:
- Hardware-in-Loop (HIL) testing
- Unit testing framework
- Continuous Integration paths

**┌─────────────────────────────────────────────────────┐**
- Golioth Cloud                      │
- ┘
- ▲

**┌─────────────────────────────────────────────────────┐**
- Security Layer (TLS/DTLS)              │
- ┘
- ▲

**┌─────────────────────────────────────────────────────┐**
- Service Layer                     │
- ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐  │
- LightDB │ │   OTA   │ │  Logs   │ │   RPC   │  │
- ┘ └─────────┘ └─────────┘ └─────────┘  │
- ┘
- ▲

**┌─────────────────────────────────────────────────────┐**
- Core SDK Layer                   │
- ┘
- ▲

**┌─────────────────────────────────────────────────────┐**
- Platform Abstraction Layer            │
- ┘
- ▲

**┌─────────────────────────────────────────────────────┐**
- Platform Layer                     │
- ESP-IDF │ ModusToolbox │ Zephyr/NCS │    Linux     │
- ┘

- Component relationships
- Testing coverage indicators

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef cloud fill:#e6e6ff,stroke:#9999ff
    classDef security fill:#ffe6e6,stroke:#ff9999
    classDef service fill:#e6ffe6,stroke:#99ff99
    classDef core fill:#fff2e6,stroke:#ffcc99
    classDef platform fill:#e6f3ff,stroke:#99ccff
    classDef external fill:#f2e6ff,stroke:#cc99ff
    classDef testing fill:#ffe6f2,stroke:#ff99cc

    %% Cloud Layer
    Cloud["Golioth Cloud Platform"]:::cloud

    %% Security Layer
    Security["Security Layer (TLS/DTLS)"]:::security

    %% Service Layer
    subgraph ServiceLayer["Service Layer"]
        LightDB["LightDB State"]
        FW["Firmware Updates"]
        Logs["Logging Service"]
        RPC["RPC Service"]
        Settings["Settings Service"]
        Stream["Stream Service"]
        Location["Location Services"]
    end

    %% Core SDK Layer
    subgraph CoreSDK["Core SDK Layer"]
        CoAP["CoAP Client"]
        Auth["Authentication"]
        Event["Event System"]
        MBox["Message Box"]
    end

    %% Platform Abstraction
    PlatformAbs["Platform Abstraction Layer"]

    %% Platform Layer
    subgraph Platforms["Platform Layer"]
        ESP["ESP-IDF"]
        Linux["Linux"]
        Modus["ModusToolbox"]
        Zephyr["Zephyr/NCS"]
    end

    %% External Dependencies
    subgraph External["External Dependencies"]
        LibCoAP["libcoap"]
        ZCBOR["zcbor"]
        Unity["Unity Testing"]
    end

    %% Testing Infrastructure
    subgraph Testing["Testing Infrastructure"]
        HIL["Hardware-in-Loop"]
        UnitTest["Unit Testing"]
    end

    %% Relationships
    Cloud --> Security
    Security --> ServiceLayer
    ServiceLayer --> CoreSDK
    CoreSDK --> PlatformAbs
    PlatformAbs --> Platforms
    CoreSDK --> External

    %% Click events for component mapping
    click ESP "https://github.com/golioth/golioth-firmware-sdk/tree/main//port/esp_idf/"
    click Linux "https://github.com/golioth/golioth-firmware-sdk/tree/main//port/linux/"
    click Modus "https://github.com/golioth/golioth-firmware-sdk/tree/main//port/modus_toolbox/"
    click Zephyr "https://github.com/golioth/golioth-firmware-sdk/tree/main//port/zephyr/"
    click CoAP "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/coap_client.c"
    click Auth "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/Kconfig.authentication"
    click Event "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/event_group.c"
    click MBox "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/mbox.c"
    click LightDB "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/lightdb_state.c"
    click FW "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/fw_update.c"
    click Logs "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/log.c"
    click RPC "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/rpc.c"
    click Settings "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/settings.c"
    click Stream "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/stream.c"
    click Location "https://github.com/golioth/golioth-firmware-sdk/blob/main//src/location.c"
    click LibCoAP "https://github.com/golioth/golioth-firmware-sdk/tree/main//external/libcoap/"
    click ZCBOR "https://github.com/golioth/golioth-firmware-sdk/tree/main//external/zcbor/"
    click Unity "https://github.com/golioth/golioth-firmware-sdk/tree/main//external/unity/"
    click HIL "https://github.com/golioth/golioth-firmware-sdk/tree/main//tests/hil/"
    click UnitTest "https://github.com/golioth/golioth-firmware-sdk/tree/main//tests/unit_tests/"

    %% Apply classes
    class Cloud,Security,LightDB,FW,Logs,RPC,Settings,Stream,Location service
    class CoAP,Auth,Event,MBox core
    class ESP,Linux,Modus,Zephyr,PlatformAbs platform
    class LibCoAP,ZCBOR,Unity external
    class HIL,UnitTest testing
```
