# martin-iflap/gpx_to_fit architecture

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

- Interactive diagram: https://gitdiagram.com/martin-iflap/gpx_to_fit
- Repository: https://github.com/martin-iflap/gpx_to_fit

## Overview

GPX → FIT is a browser-based running and hiking converter: the user loads a route, sets timing constraints and optional anchors/stops, then receives a paced FIT activity and profile. Python runs client-side through Pyodide; the core parses the route, models terrain-aware speed, fits timing between anchors, and writes FIT output. The graph also shows the optional surface lookup and the separate tuning harness. Relationships for unsampled modules are included only where the README or SOURCE INDEX supports them; the index does not establish dynamic GUI wiring.

Main entry points: [`src/gpx2fit/gui/js/pyodideBridge.js`](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/pyodideBridge.js) (Pyodide bridge), [`tuning/__main__.py`](https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/__main__.py) (Tuning commands), [`src/gpx2fit/core/pacing/combine.py`](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/combine.py) (Anchor-fitted pacing), [`src/gpx2fit/gui/js/main.js`](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/main.js) (App controls)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Browser interface"]
  node_gui["App controls<br/>[main.js]"]
  node_bridge["Pyodide bridge<br/>[pyodideBridge.js]"]
  node_route_map["Route map<br/>[map.js]"]
  node_anchor_ui["Anchor and stop UI<br/>[anchorPopovers.js]"]
  node_photo_ui["Photo anchors UI<br/>[photoAnchors.js]"]
  node_profile_ui["Activity profile UI<br/>[profilePanel.js]"]
end

subgraph group_conversion["Conversion engine"]
  node_gpx_reader["GPX parser<br/>[gpx_reader.py]"]
  node_data_models["Track and activity models<br/>[models.py]"]
end

subgraph group_pacing["Pacing model"]
  node_anchors["Anchor resolution<br/>[anchors.py]"]
  node_photo_anchors["Photo anchor resolution<br/>[photo_anchors.py]"]
  node_stops["Stop timing<br/>[stops.py]"]
  node_surface["Surface factors<br/>[surface.py]"]
  node_gradient["Gradient model<br/>[gradient.py]"]
  node_curve["Curve selection<br/>[curve_selection.py]"]
  node_combine["Anchor-fitted pacing<br/>[combine.py]"]
end

subgraph group_output["Activity output"]
  node_fit_writer["FIT writer<br/>[fit_writer.py]"]
  node_activity_profile["Profile data"]
end

subgraph group_calibration["Model calibration"]
  node_tuning_cli["Tuning commands<br/>[__main__.py]"]
  node_fit_reader["Recorded FIT reader<br/>[fit_reader.py]"]
  node_prepare["Activity preparation<br/>[prepare.py]"]
  node_tuning_model["Parameterized model<br/>[model.py]"]
  node_comparison["Pacing comparison<br/>[compare.py]"]
  node_parameter_fit["Parameter search<br/>[fit.py]"]
end

node_user(("Route user"))
node_valhalla["Valhalla routing"]

node_user -->|"sets route and timing"| node_gui
node_gui -->|"requests parse and convert"| node_bridge
node_bridge -->|"loads Python conversion"| node_gpx_reader
node_gui -->|"initializes map"| node_route_map
node_gui -->|"initializes profile"| node_profile_ui
node_anchor_ui -->|"uses conversion bridge"| node_bridge
node_photo_ui -->|"resolves photos"| node_bridge
node_gpx_reader -->|"builds track"| node_data_models
node_bridge -->|"resolves photo times"| node_photo_anchors
node_photo_anchors -->|"uses anchor resolution"| node_anchors
node_stops -->|"creates stop anchors"| node_anchors
node_bridge -->|"passes stop inputs"| node_stops
node_valhalla -.->|"provides route surface data"| node_surface
node_surface -.->|"adjusts leg speed"| node_combine
node_gradient -->|"supplies terrain gradients"| node_curve
node_curve -->|"selects speed shape"| node_combine
node_anchors -->|"provides timing constraints"| node_combine
node_combine -->|"produces timed track"| node_fit_writer
node_combine -->|"produces profile data"| node_activity_profile
node_activity_profile -->|"renders activity profile"| node_profile_ui
node_user -->|"runs calibration"| node_tuning_cli
node_tuning_cli -->|"reads recorded activities"| node_fit_reader
node_tuning_cli -->|"prepares corpus"| node_prepare
node_tuning_cli -->|"runs comparisons"| node_comparison
node_tuning_cli -->|"fits pacing constants"| node_parameter_fit
node_comparison -->|"scores model output"| node_tuning_model
node_parameter_fit -->|"searches model parameters"| node_tuning_model
node_prepare -->|"uses decoded activity"| node_fit_reader

click node_gui "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/main.js"
click node_bridge "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/pyodideBridge.js"
click node_route_map "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/map.js"
click node_anchor_ui "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/anchorPopovers.js"
click node_photo_ui "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/photoAnchors.js"
click node_profile_ui "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/profilePanel.js"
click node_gpx_reader "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/gpx_reader.py"
click node_data_models "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/models.py"
click node_anchors "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/anchors.py"
click node_photo_anchors "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/photo_anchors.py"
click node_stops "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/stops.py"
click node_surface "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/surface.py"
click node_gradient "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/gradient.py"
click node_curve "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/curve_selection.py"
click node_combine "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/combine.py"
click node_fit_writer "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/fit_writer.py"
click node_activity_profile "https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/activity_profile.py"
click node_tuning_cli "https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/__main__.py"
click node_fit_reader "https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/fit_reader.py"
click node_prepare "https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/prepare.py"
click node_tuning_model "https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/model.py"
click node_comparison "https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/compare.py"
click node_parameter_fit "https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/fit.py"

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_gui,node_bridge,node_route_map,node_anchor_ui,node_photo_ui,node_profile_ui,node_user toneBlue
class node_gpx_reader,node_data_models toneAmber
class node_anchors,node_photo_anchors,node_stops,node_surface,node_gradient,node_curve,node_combine toneMint
class node_fit_writer,node_activity_profile toneRose
class node_tuning_cli,node_fit_reader,node_prepare,node_tuning_model,node_comparison,node_parameter_fit,node_valhalla toneIndigo
```

## Components

### Browser interface

- [App controls](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/main.js): `src/gpx2fit/gui/js/main.js`
- [Pyodide bridge](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/pyodideBridge.js): `src/gpx2fit/gui/js/pyodideBridge.js`
- [Route map](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/map.js): `src/gpx2fit/gui/js/map.js`
- [Anchor and stop UI](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/anchorPopovers.js): `src/gpx2fit/gui/js/anchorPopovers.js`
- [Photo anchors UI](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/photoAnchors.js): `src/gpx2fit/gui/js/photoAnchors.js`
- [Activity profile UI](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/gui/js/profilePanel.js): `src/gpx2fit/gui/js/profilePanel.js`

### Conversion engine

- [GPX parser](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/gpx_reader.py): `src/gpx2fit/core/gpx_reader.py`
- [Track and activity models](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/models.py): `src/gpx2fit/core/models.py`

### Pacing model

- [Anchor resolution](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/anchors.py): `src/gpx2fit/core/pacing/anchors.py`
- [Photo anchor resolution](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/photo_anchors.py): `src/gpx2fit/core/pacing/photo_anchors.py`
- [Stop timing](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/stops.py): `src/gpx2fit/core/pacing/stops.py`
- [Surface factors](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/surface.py): `src/gpx2fit/core/pacing/surface.py`
- [Gradient model](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/gradient.py): `src/gpx2fit/core/pacing/gradient.py`
- [Curve selection](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/curve_selection.py): `src/gpx2fit/core/pacing/curve_selection.py`
- [Anchor-fitted pacing](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/pacing/combine.py): `src/gpx2fit/core/pacing/combine.py`

### Activity output

- [FIT writer](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/fit_writer.py): `src/gpx2fit/core/fit_writer.py`
- [Profile data](https://github.com/martin-iflap/gpx_to_fit/blob/main/src/gpx2fit/core/activity_profile.py): `src/gpx2fit/core/activity_profile.py`

### Model calibration

- [Tuning commands](https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/__main__.py): `tuning/__main__.py`
- [Recorded FIT reader](https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/fit_reader.py): `tuning/fit_reader.py`
- [Activity preparation](https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/prepare.py): `tuning/prepare.py`
- [Parameterized model](https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/model.py): `tuning/model.py`
- [Pacing comparison](https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/compare.py): `tuning/compare.py`
- [Parameter search](https://github.com/martin-iflap/gpx_to_fit/blob/main/tuning/fit.py): `tuning/fit.py`

### Other components

- **Route user**
- **Valhalla routing**

## Connections

- Route user → App controls: sets route and timing (evidence: `README.md`)
- App controls → Pyodide bridge: requests parse and convert (evidence: `src/gpx2fit/gui/js/main.js`)
- Pyodide bridge → GPX parser: loads Python conversion (evidence: `README.md`)
- App controls → Route map: initializes map (evidence: `src/gpx2fit/gui/js/main.js`)
- App controls → Activity profile UI: initializes profile (evidence: `src/gpx2fit/gui/js/main.js`)
- Anchor and stop UI → Pyodide bridge: uses conversion bridge (evidence: `src/gpx2fit/gui/js/anchorPopovers.js`)
- Photo anchors UI → Pyodide bridge: resolves photos (evidence: `src/gpx2fit/gui/js/pyodideBridge.js`)
- GPX parser → Track and activity models: builds track (evidence: `src/gpx2fit/core/gpx_reader.py`)
- Pyodide bridge → Photo anchor resolution: resolves photo times (evidence: `src/gpx2fit/gui/js/pyodideBridge.js`)
- Photo anchor resolution → Anchor resolution: uses anchor resolution (evidence: `src/gpx2fit/core/pacing/photo_anchors.py`)
- Stop timing → Anchor resolution: creates stop anchors (evidence: `src/gpx2fit/core/pacing/stops.py`)
- Pyodide bridge → Stop timing: passes stop inputs (evidence: `README.md`)
- Valhalla routing → Surface factors: provides route surface data (evidence: `README.md`)
- Surface factors → Anchor-fitted pacing: adjusts leg speed (evidence: `README.md`)
- Gradient model → Curve selection: supplies terrain gradients (evidence: `src/gpx2fit/core/pacing/curve_selection.py`)
- Curve selection → Anchor-fitted pacing: selects speed shape (evidence: `src/gpx2fit/core/pacing/combine.py`)
- Anchor resolution → Anchor-fitted pacing: provides timing constraints (evidence: `README.md`)
- Anchor-fitted pacing → FIT writer: produces timed track (evidence: `README.md`)
- Anchor-fitted pacing → Profile data: produces profile data (evidence: `README.md`)
- Profile data → Activity profile UI: renders activity profile (evidence: `README.md`)
- Route user → Tuning commands: runs calibration (evidence: `README.md`)
- Tuning commands → Recorded FIT reader: reads recorded activities (evidence: `tuning/__main__.py`)
- Tuning commands → Activity preparation: prepares corpus (evidence: `tuning/__main__.py`)
- Tuning commands → Pacing comparison: runs comparisons (evidence: `tuning/__main__.py`)
- Tuning commands → Parameter search: fits pacing constants (evidence: `tuning/__main__.py`)
- Pacing comparison → Parameterized model: scores model output (evidence: `tuning/compare.py`)
- Parameter search → Parameterized model: searches model parameters (evidence: `tuning/fit.py`)
- Activity preparation → Recorded FIT reader: uses decoded activity (evidence: `tuning/prepare.py`)
