# nrfconnect/asset-tracker-template architecture

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

- Interactive diagram: https://gitdiagram.com/nrfconnect/asset-tracker-template
- Repository: https://github.com/nrfconnect/asset-tracker-template

## Overview

The project is an embedded firmware application for nRF91-based IoT devices, designed as an Asset Tracker Template. It uses the nRF Connect SDK and Zephyr OS, built with a modular framework. The firmware is structured around a main application module (main.c) and several feature-specific modules (located under app/src/modules), each implementing its own state machine via Zephyr’s State Machine Framework and communicating through a message bus (zbus). The architecture emphasizes low-power operation and configurability via Kconfig and CMake.

##### Main Components
- Main Application: Represent the main module (main.c) as the central hub that ties together all functionalities. This component orchestrates the state machines, message-based interactions, and overall business logic.
- Feature Modules: Create individual blocks for each module (e.g., Button, Cloud, Environmental, FOTA, LED, Location, Network, Power). Note that each module has its own source files, Kconfig entries, and CMake integration.
- Communication Bus: Include a component for the message bus (zbus) that enables inter-module communication. All modules sending or receiving messages should point to this central intermediary.
- Configuration/Build System: Although less active at runtime, indicate the existence of configuration via Kconfig and the build orchestration through CMakeLists.txt. This helps illustrate how the firmware is tailored and constructed.

##### Architectural Patterns and Design Principles
- Modular Design: Emphasize that each module is isolated, has its specific functionality, and interacts via a common bus.
- Message-based Communication: Clearly illustrate that modules do not directly call each other but instead exchange messages via zbus.

##### Relevant Technologies and Frameworks
- Zephyr OS and nRF Connect SDK as the underlying platform.
- Zephyr’s State Machine Framework (SMF) for module behavior.
- zbus for message passing.
- CMake and Kconfig for build configuration and compile-time feature selection.

## Diagram (Mermaid)

```mermaid
graph TD
    A["Main Application"]:::main
    subgraph "Feature Modules"
        B["Button Module"]:::module
        C["Cloud Module"]:::module
        D["Environmental Module"]:::module
        E["FOTA Module"]:::module
        F["LED Module"]:::module
        G["Location Module"]:::module
        H["Network Module"]:::module
        I["Power Module"]:::module
    end
    J["Communication Bus (zbus)"]:::bus
    subgraph "Configuration/Build System"
        K["CMakeLists.txt"]:::config
        L["Kconfig"]:::config
        M["Kconfig.main"]:::config
    end
    N["Embedded Hardware"]:::hardware

    A -->|"init"| B
    A -->|"init"| C
    A -->|"init"| D
    A -->|"init"| E
    A -->|"init"| F
    A -->|"init"| G
    A -->|"init"| H
    A -->|"init"| I

    B -->|"msg"| J
    J -->|"msg"| B

    C -->|"msg"| J
    J -->|"msg"| C

    D -->|"msg"| J
    J -->|"msg"| D

    E -->|"msg"| J
    J -->|"msg"| E

    F -->|"msg"| J
    J -->|"msg"| F

    G -->|"msg"| J
    J -->|"msg"| G

    H -->|"msg"| J
    J -->|"msg"| H

    I -->|"msg"| J
    J -->|"msg"| I

    N -->|"sensorData"| A
    A -->|"command"| N

    click A "https://github.com/nrfconnect/asset-tracker-template/blob/main/app/src/main.c"
    click B "https://github.com/nrfconnect/asset-tracker-template/tree/main/app/src/modules/button"
    click C "https://github.com/nrfconnect/asset-tracker-template/tree/main/app/src/modules/cloud"
    click D "https://github.com/nrfconnect/asset-tracker-template/tree/main/app/src/modules/environmental"
    click E "https://github.com/nrfconnect/asset-tracker-template/tree/main/app/src/modules/fota"
    click F "https://github.com/nrfconnect/asset-tracker-template/tree/main/app/src/modules/led"
    click G "https://github.com/nrfconnect/asset-tracker-template/tree/main/app/src/modules/location"
    click H "https://github.com/nrfconnect/asset-tracker-template/tree/main/app/src/modules/network"
    click I "https://github.com/nrfconnect/asset-tracker-template/tree/main/app/src/modules/power"
    click K "https://github.com/nrfconnect/asset-tracker-template/blob/main/app/CMakeLists.txt"
    click L "https://github.com/nrfconnect/asset-tracker-template/tree/main/app/Kconfig"
    click M "https://github.com/nrfconnect/asset-tracker-template/blob/main/app/src/Kconfig.main"

    classDef main fill:#f9e79f,stroke:#c0392b,stroke-width:2px;
    classDef module fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef bus fill:#a9dfbf,stroke:#27ae60,stroke-width:2px;
    classDef config fill:#f5b7b1,stroke:#e74c3c,stroke-width:2px;
    classDef hardware fill:#fad7a0,stroke:#d35400,stroke-width:2px;
```
