# wiedehopf/tar1090 architecture

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

- Interactive diagram: https://gitdiagram.com/wiedehopf/tar1090
- Repository: https://github.com/wiedehopf/tar1090

## Overview

##### Project type and purpose
– tar1090 is a specialized full-stack application comprised of a static single-page web interface (HTML/JS/CSS) and a light backend layer that collects JSON data from an ADS-B decoder (readsb or dump1090-fa), maintains history snapshots, and serves everything via a web server (nginx or lighttpd). It adds a rich UI frontend on top of an existing ADS-B decoder.

##### File structure
– Top level
- install.sh / uninstall.sh / version.sh / tar1090.sh : installation and service scripts
- nginx-readsb-api.conf, nginx.conf : example web server configs
- tar1090.service : systemd unit
- toCSV.py, concat-example.sh, cachebust.sh : utility scripts
- 88-tar1090.conf, default : default runtime configs (/etc/default/tar1090)
– html/ (the entire frontend)
- index.html, script.js, config.js
- libs/ (OpenLayers, jQuery plugins, zstd decoder)
- layers.js, dbloader.js, jsonWorker.js : JS modules handling maps, data loading, decompression
- geojson/ and flags/ : static overlay data (airspaces, orbits, country flags)
- style.css, formatter.js, markers.js, planeObject.js, registrations.js : UI logic
– Multi-instance support
- Instances defined in /etc/default/tar1090_instances, separate html-<name>/, config.js per instance

##### README for additional insights
– The README details
- how the install script sets up systemd, config files, and web server includes
- how tar1090 reads JSON from /run/<instance> created by readsb/dump1090
- how JS modules request data via HTTP (optionally through nginx-readsb-api.conf)
- external integrations: flightawareLinks, shareBaseUrl, heywhatsthat.com outlines, AIS catcher

a. Main components
– ADS-B Decoder Service (readsb or dump1090-fa)
– Tar1090 Daemon (systemd service + tar1090.sh)
– Data Storage
- Live data socket or files in /run/<instance>
- History snapshots (JSON files written periodically)
- Optional globe history (zstd-compressed heatmap data)
– Web Server (nginx or lighttpd)
– Static Frontend (html directory)
– Client Browser (end user interface)
– External Services (FlightAware, ADSB-exchange, heywhatsthat.com, AIS-catcher)

b. Relationships and interactions
1. Decoder Service → writes live JSON feed & history files → Tar1090 service reads these and rotates snapshots.
2. Tar1090 service ↔ configuration files (/etc/default/tar1090, config.js) define intervals, ports, instance names.
3. Web Server
- Serves static files from /usr/local/share/tar1090/html
- Proxies or directly exposes decoder JSON endpoints (e.g., /data/aircraft.json)
- Optionally uses nginx-readsb-api.conf to consolidate API calls.
4. Browser → HTTP GET static assets (HTML/JS/CSS/GeoJSON) → runs JS modules.
5. Browser JS modules → poll decoder API endpoints → render map via OpenLayers → overlay geojson & history.
6. Browser → may call external URLs (flightawareLinks, shareBaseUrl) or load heywhatsthat.com outlines via getupintheair.sh.

c. Architectural patterns & design principles
– Separation of concerns: Data decoding vs. UI rendering vs. installation/config
– Static SPA frontend fetching JSON data asynchronously
– File-based “database”: snapshots instead of a traditional DB
– Modular JS with workers (jsonWorker.js) for off-main-thread parsing / decompression
– Multi-instance tenancy via directory naming and config files

d. Key technologies & libraries
– readsb / dump1090-fa (C/C++ decoder)
– systemd service + shell scripts (bash)
– nginx or lighttpd web server
– JavaScript, OpenLayers 8.x, jQuery UI Touch Punch
– zstddec-tar1090 for zstd decompression in JS
– GeoJSON overlays, CSS for theming

##### Detail without overthinking
– Capture every file-based interface (e.g., /run/<instance>/aircraft.json)
– Show optional components (heatmap folder, multiple map options, flag overlays)
– Include multi-instance branching prominently

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Tier
    subgraph "Data Tier" 
        direction TB
        Decoder["ADS-B Decoder Service"]:::dataTier
        LiveData["Live JSON Feed (socket/files)"]:::dataTier
        History["History Snapshots (JSON files)"]:::dataTier
    end

    %% Service Tier
    subgraph "Service Tier"
        direction TB
        TarDaemon["Tar1090 Daemon"]:::serviceTier
        TarService["Systemd Unit"]:::serviceTier
        ConfigDefaults["/etc/default/tar1090"]:::serviceTier
        InstallScript["Install/Uninstall/Version Scripts"]:::serviceTier
    end

    %% Presentation Tier
    subgraph "Presentation Tier"
        direction TB
        WebServer["Web Server (nginx/lighttpd)"]:::presentation
        StaticSPA["Static SPA (html/)"]:::presentation
        Browser["Client Browser"]:::presentation
    end

    %% External Integrations
    subgraph "External Services"
        direction TB
        FlightAware["FlightAware Links"]:::external
        ADSBExchange["ADSB-exchange"]:::external
        HeyWhatsThat["heywhatsthat.com"]:::external
        AIS["AIS-catcher"]:::external
    end

    %% Utilities
    subgraph "Utility Scripts"
        direction TB
        Concat["concat-example.sh"]:::serviceTier
        CacheBust["cachebust.sh"]:::serviceTier
        ToCSV["toCSV.py"]:::serviceTier
        GetUp["getupintheair.sh"]:::serviceTier
    end

    %% Relationships
    Decoder -->|"writes"| LiveData
    Decoder -->|"writes"| History
    LiveData -->|"reads"| TarDaemon
    History -->|"rotates"| TarDaemon
    ConfigDefaults --> TarDaemon
    TarDaemon -->|"writes rotated snapshots"| History

    TarDaemon -->|"triggers"| WebServer
    WebServer -->|"serves static files & proxies JSON"| StaticSPA
    Browser -->|"HTTP GET assets"| WebServer
    Browser -->|"AJAX JSON"| WebServer
    Browser -->|"calls"| FlightAware
    Browser -->|"calls"| ADSBExchange
    Browser -->|"loads outlines via"| HeyWhatsThat
    Browser -->|"integrates"| AIS

    StaticSPA -->|"loads modules"| dbloader
    StaticSPA --> layers
    StaticSPA --> formatter
    StaticSPA --> markers
    StaticSPA --> planeObject
    StaticSPA --> registrations
    StaticSPA --> flagsModule
    StaticSPA --> geomag

    %% Frontend Modules
    dbloader["dbloader.js"]:::presentation
    jsonWorker["jsonWorker.js"]:::presentation
    layers["layers.js"]:::presentation
    formatter["formatter.js"]:::presentation
    markers["markers.js"]:::presentation
    planeObject["planeObject.js"]:::presentation
    registrations["registrations.js"]:::presentation
    flagsModule["flags.js"]:::presentation
    geomag["geomag2020.js"]:::presentation

    %% Third-party Libraries
    subgraph "Frontend Libraries"
        direction TB
        ElmPEP["elm-pep-01.js"]:::presentation
        TouchPunch["jquery.ui.touch-punch-1.0.8.js"]:::presentation
        OLCSS["ol-8.2.0.css"]:::presentation
        OLCustom["ol-custom-10.4.0.js"]:::presentation
        OLLayerSwitch["ol-layerswitcher-4.1.1.css"]:::presentation
        Zstd["zstddec-tar1090-0.0.5.js"]:::presentation
        Images["libs/images"]:::presentation
    end

    %% Static Overlay Data
    subgraph "Static Overlay Data"
        direction TB
        GeoJSON["geojson/"]:::presentation
        FlagsDir["flags/"]:::presentation
    end

    StaticSPA --> GeoJSON
    StaticSPA --> FlagsDir

    %% Scripts & Config mapping nodes
    InstallScript --> TarDaemon
    Concat --> TarDaemon
    CacheBust --> StaticSPA
    ToCSV --> StaticSPA
    GetUp --> Browser

    %% Config files for Web Server
    nginxConf["nginx.conf"]:::serviceTier
    nginxAPI["nginx-readsb-api.conf"]:::serviceTier
    seventyConf["88-tar1090.conf"]:::serviceTier
    defaultConf["default"]:::serviceTier

    nginxConf --> WebServer
    nginxAPI --> WebServer
    seventyConf --> WebServer
    defaultConf --> WebServer

    %% Click Events
    click TarDaemon "https://github.com/wiedehopf/tar1090/blob/master/tar1090.sh"
    click TarService "https://github.com/wiedehopf/tar1090/blob/master/tar1090.service"
    click InstallScript "https://github.com/wiedehopf/tar1090/blob/master/install.sh"
    click InstallScript "https://github.com/wiedehopf/tar1090/blob/master/uninstall.sh"
    click InstallScript "https://github.com/wiedehopf/tar1090/blob/master/version.sh"
    click nginxConf "https://github.com/wiedehopf/tar1090/blob/master/nginx.conf"
    click nginxAPI "https://github.com/wiedehopf/tar1090/blob/master/nginx-readsb-api.conf"
    click seventyConf "https://github.com/wiedehopf/tar1090/blob/master/88-tar1090.conf"
    click defaultConf "https://github.com/wiedehopf/tar1090/tree/master/default"
    click indexHtml "https://github.com/wiedehopf/tar1090/blob/master/html/index.html"
    click scriptJs "https://github.com/wiedehopf/tar1090/blob/master/html/script.js"
    click configJs "https://github.com/wiedehopf/tar1090/blob/master/html/config.js"
    click defaultsJs "https://github.com/wiedehopf/tar1090/blob/master/html/defaults.js"
    click earlyJs "https://github.com/wiedehopf/tar1090/blob/master/html/early.js"
    click styleCss "https://github.com/wiedehopf/tar1090/blob/master/html/style.css"
    click dbloader "https://github.com/wiedehopf/tar1090/blob/master/html/dbloader.js"
    click jsonWorker "https://github.com/wiedehopf/tar1090/blob/master/html/jsonWorker.js"
    click layers "https://github.com/wiedehopf/tar1090/blob/master/html/layers.js"
    click formatter "https://github.com/wiedehopf/tar1090/blob/master/html/formatter.js"
    click markers "https://github.com/wiedehopf/tar1090/blob/master/html/markers.js"
    click planeObject "https://github.com/wiedehopf/tar1090/blob/master/html/planeObject.js"
    click registrations "https://github.com/wiedehopf/tar1090/blob/master/html/registrations.js"
    click flagsModule "https://github.com/wiedehopf/tar1090/blob/master/html/flags.js"
    click geomag "https://github.com/wiedehopf/tar1090/blob/master/html/geomag2020.js"
    click ElmPEP "https://github.com/wiedehopf/tar1090/blob/master/html/libs/elm-pep-01.js"
    click TouchPunch "https://github.com/wiedehopf/tar1090/blob/master/html/libs/jquery.ui.touch-punch-1.0.8.js"
    click OLCSS "https://github.com/wiedehopf/tar1090/blob/master/html/libs/ol-8.2.0.css"
    click OLCustom "https://github.com/wiedehopf/tar1090/blob/master/html/libs/ol-custom-10.4.0.js"
    click OLLayerSwitch "https://github.com/wiedehopf/tar1090/blob/master/html/libs/ol-layerswitcher-4.1.1.css"
    click Zstd "https://github.com/wiedehopf/tar1090/blob/master/html/libs/zstddec-tar1090-0.0.5.js"
    click Images "https://github.com/wiedehopf/tar1090/tree/master/html/libs/images"
    click GeoJSON "https://github.com/wiedehopf/tar1090/tree/master/html/geojson/"
    click FlagsDir "https://github.com/wiedehopf/tar1090/tree/master/html/flags/"
    click GetUp "https://github.com/wiedehopf/tar1090/blob/master/getupintheair.sh"
    click Concat "https://github.com/wiedehopf/tar1090/blob/master/concat-example.sh"
    click CacheBust "https://github.com/wiedehopf/tar1090/blob/master/cachebust.sh"
    click ToCSV "https://github.com/wiedehopf/tar1090/blob/master/toCSV.py"

    %% Styles
    classDef dataTier fill:#D0E6F6,stroke:#0277BD,color:#000
    classDef serviceTier fill:#C8E6C9,stroke:#2E7D32,color:#000
    classDef presentation fill:#FFE0B2,stroke:#EF6C00,color:#000
    classDef external fill:#E1BEE7,stroke:#6A1B9A,color:#000
```
