# owntracks/recorder architecture

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

- Interactive diagram: https://gitdiagram.com/owntracks/recorder
- Repository: https://github.com/owntracks/recorder

## Overview

OwnTracks Recorder ingests location updates over MQTT or HTTP, processes and stores them, then exposes them through REST, WebSocket, and browser views; `ocat` independently reads stored records for export. The graph also includes documented reverse-geocoding, hooks, fences, and caching capabilities. Several implementation files were not excerpted, so their internal connections are omitted or shown only where the README documents the behavior.

Main entry points: [`recorder.c`](https://github.com/owntracks/recorder/blob/master/recorder.c) (Recorder), [`storage.c`](https://github.com/owntracks/recorder/blob/master/storage.c) (Record files), [`http.c`](https://github.com/owntracks/recorder/blob/master/http.c) (HTTP server and API), [`docroot/last/map_google.js`](https://github.com/owntracks/recorder/blob/master/docroot/last/map_google.js) (Live map client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Ingestion and processing"]
  node_recorder["Recorder<br/>[recorder.c]"]
  node_geo["Reverse geocoding<br/>[geo.c]"]
  node_fences["Geofences<br/>[fences.c]"]
  node_hooks["Lua hooks<br/>[hooks.c]"]
end

subgraph group_store["Storage and retrieval"]
  node_file_store[("Record files<br/>[storage.c]")]
  node_geo_cache[("Geo cache<br/>[gcache.c]")]
end

subgraph group_service["HTTP and exports"]
  node_http_server["HTTP server and API<br/>[http.c]"]
  node_http_engine["Mongoose server<br/>[mongoose.c]"]
  node_ocat["ocat exports<br/>[ocat.c]"]
  node_web_views["Views and authentication"]
end

subgraph group_web["Browser views"]
  node_live_map["Live map client<br/>[map_google.js]"]
  node_websocket["WebSocket client<br/>[websock.js]"]
  node_map_utils["Map helpers<br/>[map.js]"]
  node_misc_utils["Display helpers<br/>[misc.js]"]
  node_debug["Browser debugging<br/>[debug.js]"]
  node_map_google_utils["Google map helpers<br/>[map_google.js]"]
end

subgraph group_internal["Shared runtime"]
  node_json["JSON handling<br/>[json.c]"]
  node_geohash["Geohash encoding<br/>[geohash.c]"]
  node_zonedetect["Time zone detection<br/>[zonedetect.c]"]
  node_shared_data["Runtime state<br/>[udata.h]"]
  node_string_buffer["String utilities<br/>[utstring.h]"]
end

node_apps(("OwnTracks apps"))
node_mqtt(("MQTT broker"))
node_http_clients(("HTTP publishers"))

node_apps -->|"publish updates"| node_mqtt
node_mqtt -->|"deliver updates"| node_recorder
node_apps -.->|"send updates"| node_http_clients
node_http_clients -->|"POST updates"| node_recorder
node_recorder -->|"store records"| node_file_store
node_recorder -.->|"resolve locations"| node_geo
node_recorder -->|"use cached geodata"| node_geo_cache
node_recorder -.->|"invoke hooks"| node_hooks
node_recorder -.->|"process fences"| node_fences
node_http_server -->|"read records"| node_file_store
node_http_server -.->|"serve requests"| node_http_engine
node_http_server -->|"serve pages"| node_web_views
node_file_store -->|"read records"| node_ocat
node_http_server -->|"send live updates"| node_websocket
node_websocket -->|"deliver locations"| node_live_map
node_live_map -->|"render popups"| node_map_utils
node_live_map -->|"format labels"| node_misc_utils
node_live_map -->|"manage markers"| node_map_google_utils
node_websocket -->|"log messages"| node_debug
node_map_utils -->|"format locations"| node_misc_utils
node_map_utils -->|"log map setup"| node_debug
node_map_google_utils -->|"log map updates"| node_debug
node_recorder -->|"decode payloads"| node_json
node_file_store -.->|"encode locations"| node_geohash
node_file_store -.->|"resolve time zones"| node_zonedetect

click node_recorder "https://github.com/owntracks/recorder/blob/master/recorder.c"
click node_http_server "https://github.com/owntracks/recorder/blob/master/http.c"
click node_http_engine "https://github.com/owntracks/recorder/blob/master/mongoose.c"
click node_file_store "https://github.com/owntracks/recorder/blob/master/storage.c"
click node_ocat "https://github.com/owntracks/recorder/blob/master/ocat.c"
click node_geo "https://github.com/owntracks/recorder/blob/master/geo.c"
click node_geo_cache "https://github.com/owntracks/recorder/blob/master/gcache.c"
click node_fences "https://github.com/owntracks/recorder/blob/master/fences.c"
click node_hooks "https://github.com/owntracks/recorder/blob/master/hooks.c"
click node_web_views "https://github.com/owntracks/recorder/tree/master/docroot"
click node_live_map "https://github.com/owntracks/recorder/blob/master/docroot/last/map_google.js"
click node_websocket "https://github.com/owntracks/recorder/blob/master/docroot/last/websock.js"
click node_map_utils "https://github.com/owntracks/recorder/blob/master/docroot/utils/map.js"
click node_misc_utils "https://github.com/owntracks/recorder/blob/master/docroot/utils/misc.js"
click node_debug "https://github.com/owntracks/recorder/blob/master/docroot/utils/debug.js"
click node_map_google_utils "https://github.com/owntracks/recorder/blob/master/docroot/utils/map_google.js"
click node_json "https://github.com/owntracks/recorder/blob/master/json.c"
click node_geohash "https://github.com/owntracks/recorder/blob/master/geohash.c"
click node_zonedetect "https://github.com/owntracks/recorder/blob/master/zonedetect.c"
click node_shared_data "https://github.com/owntracks/recorder/blob/master/udata.h"
click node_string_buffer "https://github.com/owntracks/recorder/blob/master/utstring.h"

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_recorder,node_geo,node_fences,node_hooks toneBlue
class node_file_store,node_geo_cache toneAmber
class node_http_server,node_http_engine,node_ocat,node_web_views toneMint
class node_live_map,node_websocket,node_map_utils,node_misc_utils,node_debug,node_map_google_utils toneRose
class node_json,node_geohash,node_zonedetect,node_shared_data,node_string_buffer,node_apps,node_mqtt,node_http_clients toneIndigo
```

## Components

### Ingestion and processing

- [Recorder](https://github.com/owntracks/recorder/blob/master/recorder.c): `recorder.c`
- [Reverse geocoding](https://github.com/owntracks/recorder/blob/master/geo.c): `geo.c`
- [Geofences](https://github.com/owntracks/recorder/blob/master/fences.c): `fences.c`
- [Lua hooks](https://github.com/owntracks/recorder/blob/master/hooks.c): `hooks.c`

### Storage and retrieval

- [Record files](https://github.com/owntracks/recorder/blob/master/storage.c): `storage.c`
- [Geo cache](https://github.com/owntracks/recorder/blob/master/gcache.c): `gcache.c`

### HTTP and exports

- [HTTP server and API](https://github.com/owntracks/recorder/blob/master/http.c): `http.c`
- [Mongoose server](https://github.com/owntracks/recorder/blob/master/mongoose.c): `mongoose.c`
- [ocat exports](https://github.com/owntracks/recorder/blob/master/ocat.c): `ocat.c`
- [Views and authentication](https://github.com/owntracks/recorder/tree/master/docroot): `docroot`

### Browser views

- [Live map client](https://github.com/owntracks/recorder/blob/master/docroot/last/map_google.js): `docroot/last/map_google.js`
- [WebSocket client](https://github.com/owntracks/recorder/blob/master/docroot/last/websock.js): `docroot/last/websock.js`
- [Map helpers](https://github.com/owntracks/recorder/blob/master/docroot/utils/map.js): `docroot/utils/map.js`
- [Display helpers](https://github.com/owntracks/recorder/blob/master/docroot/utils/misc.js): `docroot/utils/misc.js`
- [Browser debugging](https://github.com/owntracks/recorder/blob/master/docroot/utils/debug.js): `docroot/utils/debug.js`
- [Google map helpers](https://github.com/owntracks/recorder/blob/master/docroot/utils/map_google.js): `docroot/utils/map_google.js`

### Shared runtime

- [JSON handling](https://github.com/owntracks/recorder/blob/master/json.c): `json.c`
- [Geohash encoding](https://github.com/owntracks/recorder/blob/master/geohash.c): `geohash.c`
- [Time zone detection](https://github.com/owntracks/recorder/blob/master/zonedetect.c): `zonedetect.c`
- [Runtime state](https://github.com/owntracks/recorder/blob/master/udata.h): `udata.h`
- [String utilities](https://github.com/owntracks/recorder/blob/master/utstring.h): `utstring.h`

### Other components

- **OwnTracks apps**
- **MQTT broker**
- **HTTP publishers**

## Connections

- OwnTracks apps → MQTT broker: publish updates
- MQTT broker → Recorder: deliver updates
- OwnTracks apps → HTTP publishers: send updates
- HTTP publishers → Recorder: POST updates
- Recorder → Record files: store records
- Recorder → Reverse geocoding: resolve locations
- Recorder → Geo cache: use cached geodata (evidence: `recorder.c`)
- Recorder → Lua hooks: invoke hooks
- Recorder → Geofences: process fences
- HTTP server and API → Record files: read records (evidence: `http.c`)
- HTTP server and API → Mongoose server: serve requests
- HTTP server and API → Views and authentication: serve pages
- Record files → ocat exports: read records
- HTTP server and API → WebSocket client: send live updates
- WebSocket client → Live map client: deliver locations (evidence: `docroot/last/map_google.js`)
- Live map client → Map helpers: render popups (evidence: `docroot/last/map_google.js`)
- Live map client → Display helpers: format labels (evidence: `docroot/last/map_google.js`)
- Live map client → Google map helpers: manage markers (evidence: `docroot/last/map_google.js`)
- WebSocket client → Browser debugging: log messages (evidence: `docroot/last/websock.js`)
- Map helpers → Display helpers: format locations (evidence: `docroot/utils/map.js`)
- Map helpers → Browser debugging: log map setup (evidence: `docroot/utils/map.js`)
- Google map helpers → Browser debugging: log map updates (evidence: `docroot/utils/map_google.js`)
- Recorder → JSON handling: decode payloads (evidence: `recorder.c`)
- Record files → Geohash encoding: encode locations
- Record files → Time zone detection: resolve time zones
