# wm1801/zephyr_app architecture

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

- Interactive diagram: https://gitdiagram.com/wm1801/zephyr_app
- Repository: https://github.com/wm1801/zephyr_app

## Overview

##### Project type and purpose
- This is an embedded firmware project using the Zephyr RTOS for the ESP32-S3 DevKitC board.
- It demonstrates a minimal “hello-world” style application with a small C library (`my_lib`) built and flashed via CMake/west, typically inside a Docker container.

##### File structure
- Top level
- CMakeLists.txt        – Zephyr/CMake build glue
- prj.conf              – Zephyr configuration macros (Kconfig)
- board/jc4827w543.overlay – Device Tree overlay for ESP32-S3 DevKitC
- /my_lib.h      – Public header for the custom library
- src/main.c            – Application entry point
- src/my_lib.c          – Library implementation
- Build tools
- CMake (with Ninja) orchestrates compilation
- west handles Zephyr module fetching and higher-level build commands
- Docker image encapsulates SDK and toolchain

##### README insights
- Uses Zephyr’s Docker image for reproducible builds
- Instructs on both plain CMake and west workflows
- Targets esp32s3_devkitc via specific board identifier

a. Main components
- Hardware Layer: ESP32-S3 DevKitC board (CPU, peripherals)
- Zephyr RTOS Layer: kernel, HAL (esp32s3), drivers
- Device Tree Layer: base DTS + overlay file for pin configuration
- Application Layer: `main.c` + `my_lib` library
- Build System: CMake + Ninja + west + Docker container
- Deployment: `west flash` / serial uploader

b. Relationships & data flows
- Source code and headers feed into CMake
- CMake invokes the Zephyr build system, which:
– compiles the RTOS kernel and HAL
– processes Device Tree (DTS + overlay)
– compiles application sources
– links everything into a firmware binary
- Docker wraps the toolchain and environment
- west fetches Zephyr modules before build
- `west flash` sends the binary to the board over USB/UART

c. Architectural patterns
- Layered architecture: Hardware → HAL/Drivers → Kernel → Application
- Modular Device Tree overlays for board customization
- Separation of concerns: build orchestration (CMake/west) vs. runtime code

d. Key technologies & roles
- C (source language)
- Zephyr RTOS (kernel, HAL)
- CMake (build scripting)
- west (meta-tool for module management)
- Docker (reproducible environment)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build Environment
    Docker["Docker Environment"]:::build
    West["west (Zephyr meta-tool)"]:::build
    CMake["CMake + Ninja"]:::build

    %% Configuration Files
    subgraph "Configuration" 
        direction TB
        PRJ_CONF[/prj.conf/]:::config
        OVERLAY[/board/jc4827w543.overlay/]:::config
    end

    %% Application Layer
    subgraph "Application Code"
        direction TB
        MAIN["src/main.c"]:::app
        MY_LIB_C["src/my_lib.c"]:::app
        MY_LIB_H["include/my_lib.h"]:::app
    end

    %% Zephyr RTOS Layer
    subgraph "Zephyr RTOS Components"
        direction TB
        KERNEL["Kernel"]:::rtos
        HAL["HAL (esp32s3)"]:::rtos
        DRIVERS["Drivers"]:::rtos
    end

    %% Device Tree Processing
    DT["Device Tree Processing"]:::rtos

    %% Firmware and Deployment
    BIN["Firmware Binary"]:::rtos
    FLASH[/Flash via west flash \/ USB-UART/]:::deploy
    BOARD["ESP32-S3 DevKitC Board"]:::hardware

    %% Build Flow
    Docker --> CMake
    West --> CMake
    PRJ_CONF --> CMake
    OVERLAY --> DT
    DT --> CMake
    MAIN --> CMake
    MY_LIB_C --> CMake
    MY_LIB_H --> CMake

    CMake --> KERNEL
    CMake --> HAL
    CMake --> DRIVERS
    CMake --> BIN

    BIN --> FLASH
    FLASH --> BOARD

    %% Click Events
    click BOARD "https://github.com/wm1801/zephyr_app/blob/main/README.md"
    click CMake "https://github.com/wm1801/zephyr_app/blob/main/cmake_demo/CMakeLists.txt"
    click PRJ_CONF "https://github.com/wm1801/zephyr_app/blob/main/cmake_demo/prj.conf"
    click OVERLAY "https://github.com/wm1801/zephyr_app/blob/main/cmake_demo/board/jc4827w543.overlay"
    click MAIN "https://github.com/wm1801/zephyr_app/blob/main/cmake_demo/src/main.c"
    click MY_LIB_C "https://github.com/wm1801/zephyr_app/blob/main/cmake_demo/src/my_lib.c"
    click MY_LIB_H "https://github.com/wm1801/zephyr_app/blob/main/cmake_demo/include/my_lib.h"
    click Docker "https://github.com/wm1801/zephyr_app/blob/main/README.md"
    click FLASH "https://github.com/wm1801/zephyr_app/blob/main/README.md"

    %% Styling
    classDef build fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef rtos fill:#FFA500,stroke:#333,stroke-width:1px
    classDef app fill:#90EE90,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef hardware fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef deploy fill:#CCCCCC,stroke:#333,stroke-width:1px
```
