# jonathandreyer/esp-modem architecture

> Architecture diagram of the GitHub repository jonathandreyer/esp-modem, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jonathandreyer/esp-modem
- Repository: https://github.com/jonathandreyer/esp-modem

## Overview

#### Purpose and Status
`esp-modem` is an archived ESP-IDF managed component for controlling GSM/LTE modems through AT commands and exposing PPP/PPPoS connectivity as an ESP network interface. It supports C and C++ consumers and has Linux host portability for development/testing. The successor is `esp-protocols`.

#### Public Integration Surface
Applications consume the C API and C++ abstractions rather than transport internals:
- C entry points and configuration: `include/esp_modem_api.h`, `include/esp_modem_dce_config.h`
- C++ API, DCE/DTE model, and factories: `include/cxx_include/esp_modem_api.hpp`, `include/cxx_include/esp_modem_dce_factory.hpp`, `include/cxx_include/esp_modem_dte.hpp`
- Component build/package boundary: `CMakeLists.txt`, `idf_component.yml`

#### DTE Transport and Terminal Layer
The DTE represents the host-side data-terminal equipment: UART or virtual/file/socket-backed channels. Terminal implementations own byte I/O, while higher layers consume command/response streams.
- UART and Linux UART implementations: `src/esp_modem_uart.cpp`, `src/esp_modem_uart_linux.cpp`
- Terminal implementations and resource creators: `src/esp_modem_term_uart.cpp`, `src/esp_modem_term_fs.cpp`, `src/esp_modem_vfs_socket_creator.cpp`
- Private platform-compatible terminal interfaces: `private_include/uart_terminal.hpp`, `private_include/vfs_termial.hpp`

#### DCE, AT Command, and Module Layer
The DCE is the modem-facing control plane. It issues AT commands through the DTE terminal, parses modem responses, and exposes common operations plus module-specific behavior. The command library separates reusable command definitions from DCE lifecycle/state handling.
- Core DCE implementation: `src/esp_modem_dce.cpp`, `include/cxx_include/esp_modem_dce.hpp`
- Command execution/library: `src/esp_modem_command_library.cpp`, `include/cxx_include/esp_modem_command_library.hpp`
- Module selection and object construction: `src/esp_modem_modules.cpp`, `src/esp_modem_factory.cpp`, `include/cxx_include/esp_modem_dce_module.hpp`

#### CMUX Multiplexing
CMUX is an optional framing layer over the modem serial channel. It enables concurrent logical channels, allowing AT command traffic to continue while PPP data is active.
- CMUX protocol implementation: `src/esp_modem_cmux.cpp`
- Public CMUX contract: `include/cxx_include/esp_modem_cmux.hpp`
- Concurrent AT/PPP usage example: `examples/simple_cmux_client/main/simple_cmux_client_main.cpp`

#### PPP and Network-Interface Boundary
The networking integration binds modem data mode to ESP-IDF `esp_netif`/PPP facilities. Control transitions move the modem from AT-command mode into data mode; PPP packets then flow between the DTE transport and the network stack.
- Netif integration: `src/esp_modem_netif.cpp`, `include/cxx_include/esp_modem_netif.hpp`
- C API adaptation layer: `src/esp_modem_c_api.cpp`, `include/esp_modem_c_api_types.h`
- PPPoS client entry point: `examples/pppos_client/main/pppos_client_main.c`

#### Runtime Portability and Concurrency
ESP-IDF/FreeRTOS is the primary embedded runtime. Linux variants provide host execution through mocked ESP event APIs and a TUN-backed netif path, with platform-specific primitives selected underneath common abstractions.
- FreeRTOS and Linux primitives: `src/esp_modem_primitives_freertos.cpp`, `src/esp_modem_primitives_linux.cpp`
- Linux netif bridge: `src/esp_modem_netif_linux.cpp`, `port/linux/esp_netif_linux/tun_io.c`
- ESP event compatibility: `port/linux/esp_event_mock/esp_event_mock.c`

#### Application Entry Points and Network Scenarios
Examples are independent ESP-IDF applications demonstrating the intended orchestration: create transport/DCE, initialize modem and network, then run application traffic.
- Basic C PPP client: `examples/pppos_client/main/pppos_client_main.c`
- Interactive C++ modem command console: `examples/modem_console/main/modem_console_main.cpp`
- Wi-Fi AP/NAT forwarding over PPPoS: `examples/ap_to_pppos/main/ap_to_pppos.c`
- Linux modem/TUN application: `examples/linux_modem/main/modem_main.cpp`

Main entry points: [`src/esp_modem_netif.cpp`](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_netif.cpp) (PPPoS netif integration), [`src/esp_modem_dce.cpp`](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_dce.cpp) (DCE control plane), [`include/cxx_include/esp_modem_dte.hpp`](https://github.com/jonathandreyer/esp-modem/blob/master/include/cxx_include/esp_modem_dte.hpp) (DTE abstraction), [`src/esp_modem_netif_linux.cpp`](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_netif_linux.cpp) (Linux TUN netif)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public Surface"]
  node_component["Component package<br/>build package<br/>[idf_component.yml]"]
  node_c_api["C API<br/>[esp_modem_api.h]"]
  node_cpp_api["C++ API &amp; factories<br/>public C++ API<br/>[esp_modem_api.hpp]"]
  node_c_adapter["C API adapter<br/>API bridge"]
end

subgraph group_core["Modem Control"]
  node_dce["DCE control plane<br/>modem controller<br/>[esp_modem_dce.cpp]"]
  node_commands["AT command library<br/>command executor"]
  node_modules["Module selection<br/>module factory"]
end

subgraph group_transport["Transport &amp; Multiplexing"]
  node_dte["DTE abstraction<br/>host terminal API<br/>[esp_modem_dte.hpp]"]
  node_terminals["Terminal implementations<br/>byte I/O"]
  node_uart_platform["UART platforms<br/>platform transport"]
  node_cmux{{"CMUX framing<br/>multiplexer<br/>[esp_modem_cmux.cpp]"}}
end

subgraph group_network["Network &amp; Runtime"]
  node_netif["PPPoS netif integration<br/>network bridge"]
  node_primitives["Runtime primitives<br/>concurrency runtime"]
  node_linux_netif["Linux TUN netif<br/>host network bridge"]
  node_event_mock["ESP event mock<br/>Linux compatibility<br/>[esp_event_mock.c]"]
end

subgraph group_examples["Example Applications"]
  node_pppos_example["C PPPoS client<br/>ESP-IDF example"]
  node_console_example["Modem command console<br/>ESP-IDF example"]
  node_cmux_example["Concurrent CMUX client<br/>ESP-IDF example"]
  node_linux_example["Linux modem app<br/>host example<br/>[modem_main.cpp]"]
  node_nat_example["AP-to-PPPoS forwarding<br/>ESP-IDF example<br/>[ap_to_pppos.c]"]
end

node_component -->|"packages"| node_c_api
node_component -->|"packages"| node_cpp_api
node_c_api -->|"calls"| node_c_adapter
node_c_adapter -->|"adapts"| node_dce
node_cpp_api -->|"constructs"| node_modules
node_modules -->|"selects"| node_dce
node_dce -->|"executes"| node_commands
node_dce -->|"uses"| node_dte
node_dte -->|"owns I/O"| node_terminals
node_terminals -->|"uses"| node_uart_platform
node_cmux -.->|"multiplexes"| node_dte
node_dce -->|"enters data mode"| node_netif
node_netif -->|"exchanges PPP packets"| node_dte
node_netif -->|"uses"| node_primitives
node_linux_netif -.->|"Linux variant"| node_netif
node_linux_netif -->|"uses events"| node_event_mock
node_pppos_example -->|"uses"| node_c_api
node_pppos_example -->|"runs PPPoS"| node_netif
node_console_example -->|"uses"| node_cpp_api
node_cmux_example -->|"demonstrates"| node_cmux
node_cmux_example -->|"runs PPP concurrently"| node_netif
node_linux_example -->|"uses"| node_linux_netif
node_nat_example -->|"forwards over PPPoS"| node_netif

click node_component "https://github.com/jonathandreyer/esp-modem/blob/master/idf_component.yml"
click node_c_api "https://github.com/jonathandreyer/esp-modem/blob/master/include/esp_modem_api.h"
click node_cpp_api "https://github.com/jonathandreyer/esp-modem/blob/master/include/cxx_include/esp_modem_api.hpp"
click node_c_adapter "https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_c_api.cpp"
click node_dce "https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_dce.cpp"
click node_commands "https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_command_library.cpp"
click node_modules "https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_modules.cpp"
click node_dte "https://github.com/jonathandreyer/esp-modem/blob/master/include/cxx_include/esp_modem_dte.hpp"
click node_terminals "https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_term_uart.cpp"
click node_uart_platform "https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_uart_linux.cpp"
click node_cmux "https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_cmux.cpp"
click node_netif "https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_netif.cpp"
click node_primitives "https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_primitives_freertos.cpp"
click node_linux_netif "https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_netif_linux.cpp"
click node_event_mock "https://github.com/jonathandreyer/esp-modem/blob/master/port/linux/esp_event_mock/esp_event_mock.c"
click node_pppos_example "https://github.com/jonathandreyer/esp-modem/blob/master/examples/pppos_client/main/pppos_client_main.c"
click node_console_example "https://github.com/jonathandreyer/esp-modem/blob/master/examples/modem_console/main/modem_console_main.cpp"
click node_cmux_example "https://github.com/jonathandreyer/esp-modem/blob/master/examples/simple_cmux_client/main/simple_cmux_client_main.cpp"
click node_linux_example "https://github.com/jonathandreyer/esp-modem/blob/master/examples/linux_modem/main/modem_main.cpp"
click node_nat_example "https://github.com/jonathandreyer/esp-modem/blob/master/examples/ap_to_pppos/main/ap_to_pppos.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_component,node_c_api,node_cpp_api,node_c_adapter toneBlue
class node_dce,node_commands,node_modules toneAmber
class node_dte,node_terminals,node_uart_platform,node_cmux toneMint
class node_netif,node_primitives,node_linux_netif,node_event_mock toneRose
class node_pppos_example,node_console_example,node_cmux_example,node_linux_example,node_nat_example toneIndigo
```

## Components

### Public Surface

- [Component package](https://github.com/jonathandreyer/esp-modem/blob/master/idf_component.yml): build package · ESP-IDF managed-component boundary. · `idf_component.yml`
- [C API](https://github.com/jonathandreyer/esp-modem/blob/master/include/esp_modem_api.h): public C API · `include/esp_modem_api.h`
- [C++ API & factories](https://github.com/jonathandreyer/esp-modem/blob/master/include/cxx_include/esp_modem_api.hpp): public C++ API · `include/cxx_include/esp_modem_api.hpp`
- [C API adapter](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_c_api.cpp): API bridge · `src/esp_modem_c_api.cpp`

### Modem Control

- [DCE control plane](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_dce.cpp): modem controller · Owns modem lifecycle, state, and common operations. · `src/esp_modem_dce.cpp`
- [AT command library](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_command_library.cpp): command executor · Reusable AT command definitions and response parsing. · `src/esp_modem_command_library.cpp`
- [Module selection](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_modules.cpp): module factory · `src/esp_modem_modules.cpp`

### Transport & Multiplexing

- [DTE abstraction](https://github.com/jonathandreyer/esp-modem/blob/master/include/cxx_include/esp_modem_dte.hpp): host terminal API · Host-side data-terminal equipment exposed to the DCE. · `include/cxx_include/esp_modem_dte.hpp`
- [Terminal implementations](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_term_uart.cpp): byte I/O · UART, filesystem, and socket-backed terminal channels. · `src/esp_modem_term_uart.cpp`
- [UART platforms](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_uart_linux.cpp): platform transport · ESP and Linux UART backends. · `src/esp_modem_uart_linux.cpp`
- [CMUX framing](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_cmux.cpp): multiplexer · Optional logical channels for concurrent AT and PPP traffic. · `src/esp_modem_cmux.cpp`

### Network & Runtime

- [PPPoS netif integration](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_netif.cpp): network bridge · Connects modem data mode to ESP-IDF esp_netif/PPP. · `src/esp_modem_netif.cpp`
- [Runtime primitives](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_primitives_freertos.cpp): concurrency runtime · FreeRTOS and Linux implementations beneath common abstractions. · `src/esp_modem_primitives_freertos.cpp`
- [Linux TUN netif](https://github.com/jonathandreyer/esp-modem/blob/master/src/esp_modem_netif_linux.cpp): host network bridge · `src/esp_modem_netif_linux.cpp`
- [ESP event mock](https://github.com/jonathandreyer/esp-modem/blob/master/port/linux/esp_event_mock/esp_event_mock.c): Linux compatibility · `port/linux/esp_event_mock/esp_event_mock.c`

### Example Applications

- [C PPPoS client](https://github.com/jonathandreyer/esp-modem/blob/master/examples/pppos_client/main/pppos_client_main.c): ESP-IDF example · `examples/pppos_client/main/pppos_client_main.c`
- [Modem command console](https://github.com/jonathandreyer/esp-modem/blob/master/examples/modem_console/main/modem_console_main.cpp): ESP-IDF example · `examples/modem_console/main/modem_console_main.cpp`
- [Concurrent CMUX client](https://github.com/jonathandreyer/esp-modem/blob/master/examples/simple_cmux_client/main/simple_cmux_client_main.cpp): ESP-IDF example · `examples/simple_cmux_client/main/simple_cmux_client_main.cpp`
- [Linux modem app](https://github.com/jonathandreyer/esp-modem/blob/master/examples/linux_modem/main/modem_main.cpp): host example · `examples/linux_modem/main/modem_main.cpp`
- [AP-to-PPPoS forwarding](https://github.com/jonathandreyer/esp-modem/blob/master/examples/ap_to_pppos/main/ap_to_pppos.c): ESP-IDF example · `examples/ap_to_pppos/main/ap_to_pppos.c`

## Connections

- Component package → C API: packages
- Component package → C++ API & factories: packages
- C API → C API adapter: calls
- C API adapter → DCE control plane: adapts
- C++ API & factories → Module selection: constructs
- Module selection → DCE control plane: selects
- DCE control plane → AT command library: executes
- DCE control plane → DTE abstraction: uses
- DTE abstraction → Terminal implementations: owns I/O
- Terminal implementations → UART platforms: uses
- CMUX framing → DTE abstraction: multiplexes
- DCE control plane → PPPoS netif integration: enters data mode
- PPPoS netif integration → DTE abstraction: exchanges PPP packets
- PPPoS netif integration → Runtime primitives: uses
- Linux TUN netif → PPPoS netif integration: Linux variant
- Linux TUN netif → ESP event mock: uses events
- C PPPoS client → C API: uses
- C PPPoS client → PPPoS netif integration: runs PPPoS
- Modem command console → C++ API & factories: uses
- Concurrent CMUX client → CMUX framing: demonstrates
- Concurrent CMUX client → PPPoS netif integration: runs PPP concurrently
- Linux modem app → Linux TUN netif: uses
- AP-to-PPPoS forwarding → PPPoS netif integration: forwards over PPPoS
