# cesanta/mongoose architecture

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

- Interactive diagram: https://gitdiagram.com/cesanta/mongoose
- Repository: https://github.com/cesanta/mongoose

## Overview

Mongoose is an embedded networking library and web server for devices and desktop systems. Its central workflow is an application running the event manager, accepting network traffic, and handling it through a selected protocol; optional TLS secures connections. The library also offers a built-in TCP/IP stack and hardware drivers, firmware OTA support, and device-dashboard assets. The README documents these capabilities, but many implementations are not excerpted, so uncertain internal calls are omitted rather than inferred.

Main entry points: [`src/net.h`](https://github.com/cesanta/mongoose/blob/master/src/net.h) (Event manager), [`src/http.c`](https://github.com/cesanta/mongoose/blob/master/src/http.c) (HTTP server/client), [`src/tls_builtin.c`](https://github.com/cesanta/mongoose/blob/master/src/tls_builtin.c) (TLS backends), [`src/net_builtin.c`](https://github.com/cesanta/mongoose/blob/master/src/net_builtin.c) (Built-in TCP/IP)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Network runtime"]
  node_event_manager["Event manager<br/>[net.h]"]
  node_socket_io["Socket I/O<br/>[sock.c]"]
  node_dns["DNS resolver<br/>[dns.c]"]
  node_buffers["Connection buffers<br/>[iobuf.h]"]
end

subgraph group_protocols["Protocols and security"]
  node_http["HTTP server/client<br/>[http.c]"]
  node_websocket["WebSocket<br/>[ws.c]"]
  node_mqtt["MQTT<br/>[mqtt.c]"]
  node_modbus["Modbus TCP<br/>[modbus.c]"]
  node_sntp["SNTP<br/>[sntp.c]"]
  node_tls["TLS backends<br/>[tls_builtin.c]"]
end

subgraph group_embedded["Embedded networking"]
  node_builtin_stack["Built-in TCP/IP<br/>[net_builtin.c]"]
  node_link_layers["Link layers<br/>[l2_eth.c]"]
  node_hardware_drivers["Hardware drivers"]
end

subgraph group_device["Device features"]
  node_ota["Firmware updates<br/>[ota.c]"]
  node_dashboard_assets["Dashboard assets<br/>[dashboard.js]"]
  node_filesystem["Filesystem support<br/>[fs.c]"]
end

node_application(("Application"))
node_external_stack["External TCP/IP stack"]
node_external_peer(("Network peers"))

node_application -->|"runs poll loop"| node_event_manager
node_application -->|"registers listener"| node_http
node_event_manager -.->|"polls connections"| node_socket_io
node_event_manager -.->|"resolves names"| node_dns
node_http -->|"uses networking"| node_event_manager
node_websocket -->|"exchanges frames"| node_external_peer
node_mqtt -->|"publishes messages"| node_external_peer
node_modbus -->|"serves protocol"| node_external_peer
node_sntp -->|"syncs time"| node_external_peer
node_tls -.->|"secures connections"| node_http
node_tls -.->|"secures connections"| node_websocket
node_tls -.->|"secures connections"| node_mqtt
node_event_manager -->|"uses BSD sockets"| node_external_stack
node_event_manager -->|"supports built-in stack"| node_builtin_stack
node_builtin_stack -.->|"uses link layer"| node_link_layers
node_hardware_drivers -.->|"provides interfaces"| node_builtin_stack
node_application -->|"initiates updates"| node_ota
node_http -->|"serves files"| node_filesystem
node_application -.->|"uses dashboard"| node_dashboard_assets
node_event_manager -.->|"manages connection I/O"| node_buffers

click node_event_manager "https://github.com/cesanta/mongoose/blob/master/src/net.h"
click node_socket_io "https://github.com/cesanta/mongoose/blob/master/src/sock.c"
click node_dns "https://github.com/cesanta/mongoose/blob/master/src/dns.c"
click node_buffers "https://github.com/cesanta/mongoose/blob/master/src/iobuf.h"
click node_http "https://github.com/cesanta/mongoose/blob/master/src/http.c"
click node_websocket "https://github.com/cesanta/mongoose/blob/master/src/ws.c"
click node_mqtt "https://github.com/cesanta/mongoose/blob/master/src/mqtt.c"
click node_modbus "https://github.com/cesanta/mongoose/blob/master/src/modbus.c"
click node_sntp "https://github.com/cesanta/mongoose/blob/master/src/sntp.c"
click node_tls "https://github.com/cesanta/mongoose/blob/master/src/tls_builtin.c"
click node_builtin_stack "https://github.com/cesanta/mongoose/blob/master/src/net_builtin.c"
click node_link_layers "https://github.com/cesanta/mongoose/blob/master/src/l2_eth.c"
click node_hardware_drivers "https://github.com/cesanta/mongoose/tree/master/src/drivers"
click node_ota "https://github.com/cesanta/mongoose/blob/master/src/ota.c"
click node_dashboard_assets "https://github.com/cesanta/mongoose/blob/master/resources/dashboard.js"
click node_filesystem "https://github.com/cesanta/mongoose/blob/master/src/fs.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_event_manager,node_socket_io,node_dns,node_buffers toneBlue
class node_http,node_websocket,node_mqtt,node_modbus,node_sntp,node_tls toneAmber
class node_builtin_stack,node_link_layers,node_hardware_drivers toneMint
class node_ota,node_dashboard_assets,node_filesystem toneRose
class node_application,node_external_stack,node_external_peer toneIndigo
```

## Components

### Network runtime

- [Event manager](https://github.com/cesanta/mongoose/blob/master/src/net.h): `src/net.h`
- [Socket I/O](https://github.com/cesanta/mongoose/blob/master/src/sock.c): `src/sock.c`
- [DNS resolver](https://github.com/cesanta/mongoose/blob/master/src/dns.c): `src/dns.c`
- [Connection buffers](https://github.com/cesanta/mongoose/blob/master/src/iobuf.h): `src/iobuf.h`

### Protocols and security

- [HTTP server/client](https://github.com/cesanta/mongoose/blob/master/src/http.c): `src/http.c`
- [WebSocket](https://github.com/cesanta/mongoose/blob/master/src/ws.c): `src/ws.c`
- [MQTT](https://github.com/cesanta/mongoose/blob/master/src/mqtt.c): `src/mqtt.c`
- [Modbus TCP](https://github.com/cesanta/mongoose/blob/master/src/modbus.c): `src/modbus.c`
- [SNTP](https://github.com/cesanta/mongoose/blob/master/src/sntp.c): `src/sntp.c`
- [TLS backends](https://github.com/cesanta/mongoose/blob/master/src/tls_builtin.c): `src/tls_builtin.c`

### Embedded networking

- [Built-in TCP/IP](https://github.com/cesanta/mongoose/blob/master/src/net_builtin.c): `src/net_builtin.c`
- [Link layers](https://github.com/cesanta/mongoose/blob/master/src/l2_eth.c): `src/l2_eth.c`
- [Hardware drivers](https://github.com/cesanta/mongoose/tree/master/src/drivers): `src/drivers`

### Device features

- [Firmware updates](https://github.com/cesanta/mongoose/blob/master/src/ota.c): `src/ota.c`
- [Dashboard assets](https://github.com/cesanta/mongoose/blob/master/resources/dashboard.js): `resources/dashboard.js`
- [Filesystem support](https://github.com/cesanta/mongoose/blob/master/src/fs.c): `src/fs.c`

### Other components

- **Application**
- **External TCP/IP stack**
- **Network peers**

## Connections

- Application → Event manager: runs poll loop
- Application → HTTP server/client: registers listener
- Event manager → Socket I/O: polls connections
- Event manager → DNS resolver: resolves names
- HTTP server/client → Event manager: uses networking (evidence: `src/http.c`)
- WebSocket → Network peers: exchanges frames
- MQTT → Network peers: publishes messages
- Modbus TCP → Network peers: serves protocol
- SNTP → Network peers: syncs time
- TLS backends → HTTP server/client: secures connections
- TLS backends → WebSocket: secures connections
- TLS backends → MQTT: secures connections
- Event manager → External TCP/IP stack: uses BSD sockets
- Event manager → Built-in TCP/IP: supports built-in stack
- Built-in TCP/IP → Link layers: uses link layer
- Hardware drivers → Built-in TCP/IP: provides interfaces
- Application → Firmware updates: initiates updates
- HTTP server/client → Filesystem support: serves files (evidence: `src/http.c`)
- Application → Dashboard assets: uses dashboard
- Event manager → Connection buffers: manages connection I/O (evidence: `src/net.h`)
