# merginmaps/mobile architecture

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

- Interactive diagram: https://gitdiagram.com/merginmaps/mobile
- Repository: https://github.com/merginmaps/mobile

## Overview

#### Purpose and Entry Points
Mergin Maps Mobile is a cross-platform field-survey GIS client. It opens QGIS-designed projects, renders/edit geospatial layers and forms, captures position/media, and synchronizes project data with Mergin Maps services. The primary executable starts in `app/main.cpp`; QML UI composition begins at `app/qml/main.qml`. Build targets are organized by `CMakeLists.txt`, `app/CMakeLists.txt`, and `core/CMakeLists.txt`.

#### Runtime Architecture
The native application is C++ on Qt/Qt Quick, using QGIS core libraries for projects, layers, map rendering, forms, geometry, and GIS data formats. QML provides the touch UI; C++ exposes stateful controllers and `QAbstractItemModel`-style models to it. Dependency and platform packaging are CMake/vcpkg based, including customized QGIS, Qt Positioning, Spatialite, and GeoDiff ports under `vcpkg/ports/qgis`, `vcpkg/ports/qtpositioning`, and `vcpkg/ports/geodiff`.

#### Project Lifecycle and Cloud Sync
`core/project.cpp` represents project-level state; `core/localprojectsmanager.cpp` manages local project discovery/storage. `app/activeproject.cpp` bridges the selected project into application/UI state. Network-facing Mergin Maps integration is centralized in `core/merginapi.cpp`, authentication in `core/merginuserauth.cpp`, and synchronization orchestration in `app/synchronizationmanager.cpp`. The control path is project selection/download → local QGIS project load/edit → status/change detection → upload/download/reconciliation with the Mergin Maps server. Credential persistence is bounded behind `core/credentialstore.h` with keychain and plaintext implementations.

#### Map, Layers, and Editing
The map runtime adapts QGIS rendering and coordinate state through `app/map/inputmapcanvasmap.cpp`, `app/map/inputmapsettings.cpp`, and `app/map/inputmaptransform.cpp`, surfaced by `app/qml/map/MMMapCanvas.qml`. Layer-tree and feature-list models translate QGIS layer state for QML in `app/layer/layertreemodel.cpp`, `app/layersmodel.cpp`, and `app/layerfeaturesmodel.cpp`. Interactive capture/editing is implemented as map-tool controllers, notably `app/maptools/recordingmaptool.cpp`, `app/maptools/splittingmaptool.cpp`, and `app/mapsketchingcontroller.cpp`.

#### Forms, Attributes, and Feature Queries
Feature form presentation is driven by `app/attributes/attributecontroller.cpp`, `app/attributes/attributeformmodel.cpp`, and `app/qml/form/MMFormPage.qml`. This boundary maps QGIS field/widget definitions and feature values to QML editors, validates changes, and commits them back to editable layers. Related/value-reference features have dedicated models (`app/relationfeaturesmodel.cpp`, `app/valuerelationfeaturesmodel.cpp`); filtering is separated into `app/filter/filtercontroller.cpp` and supporting filter models.

#### Positioning and Device Integration
`app/position/positionkit.cpp` coordinates position data consumed by map and survey flows. Providers abstract internal GPS, Android, Bluetooth/NMEA, network, and simulated sources via `app/position/providers/abstractpositionprovider.cpp`, `app/position/providers/bluetoothpositionprovider.cpp`, and `app/position/providers/nmeaparser.cpp`. Recording/tracking is a separate backend layer in `app/position/tracking/positiontrackingmanager.cpp`, with Android/iOS implementations. Native boundaries include Android Java services in `app/android/src/uk/co/lutraconsulting/PositionTrackingService.java` and Objective-C++ iOS integration in `app/ios/iosinterface.mm`.

#### Delivery and UI Development
Android, iOS, Linux, macOS, and Windows builds are automated under `.github/workflows/android.yml`, `.github/workflows/ios.yml`, and `.github/workflows/win.yml`; mobile-store delivery uses Fastlane (`fastlane/Fastfile`). Resources and translations are compiled into Qt resources, including `app/i18n/input_i18n.qrc`. The separate Gallery executable (`gallery/main.cpp`, `gallery/qml/Main.qml`) is a component-development sandbox for shared QML UI, not the production survey runtime.

Main entry points: [`app/qml/main.qml`](https://github.com/merginmaps/mobile/blob/master/app/qml/main.qml) (QML application shell), [`app/position/positionkit.cpp`](https://github.com/merginmaps/mobile/blob/master/app/position/positionkit.cpp) (Position kit), [`app/qml/map/MMMapCanvas.qml`](https://github.com/merginmaps/mobile/blob/master/app/qml/map/MMMapCanvas.qml) (Map canvas), [`app/main.cpp`](https://github.com/merginmaps/mobile/blob/master/app/main.cpp) (Native entry point)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Mobile application"]
  node_native_entry["Native entry point<br/>Qt executable<br/>[main.cpp]"]
  node_qml_shell["QML application shell<br/>Qt Quick UI<br/>[main.qml]"]
  node_active_project["Active project bridge<br/>UI state controller<br/>[activeproject.cpp]"]
end

subgraph group_sync["Projects and sync"]
  node_local_projects[("Local project manager<br/>project storage")]
  node_project_state["Project state<br/>QGIS project model<br/>[project.cpp]"]
  node_mergin_api["Mergin API client<br/>network client<br/>[merginapi.cpp]"]
  node_auth["User authentication<br/>auth service<br/>[merginuserauth.cpp]"]
  node_credentials[("Credential store<br/>secure storage boundary<br/>[credentialstore.h]")]
  node_synchronization["Synchronization manager<br/>sync orchestrator"]
end

subgraph group_gis["GIS interaction"]
  node_qgis_runtime{{"QGIS runtime<br/>GIS library boundary"}}
  node_map_canvas["Map canvas<br/>QML map view<br/>[MMMapCanvas.qml]"]
  node_map_adapter["Map rendering adapter<br/>map state adapter"]
  node_layer_models["Layer and feature models<br/>QML item models<br/>[layertreemodel.cpp]"]
  node_editing_tools["Capture and editing tools<br/>map-tool controllers"]
  node_form_page["Feature form UI<br/>QML form view<br/>[MMFormPage.qml]"]
  node_attribute_controller["Attribute form controller<br/>form model/controller"]
end

subgraph group_position["Position and device"]
  node_position_kit["Position kit<br/>position coordinator<br/>[positionkit.cpp]"]
  node_position_providers["Position providers<br/>provider abstraction"]
  node_tracking["Position tracking<br/>tracking backend"]
  node_platform_services{{"Native platform services<br/>Android and iOS integration"}}
end

subgraph group_delivery["Build and delivery"]
  node_build["CMake build targets<br/>build system<br/>[CMakeLists.txt]"]
  node_ci_delivery["CI and store delivery<br/>release automation<br/>[android.yml]"]
  node_gallery["QML Gallery<br/>component sandbox<br/>[main.cpp]"]
end

node_native_entry -->|"starts"| node_qml_shell
node_native_entry -->|"initializes"| node_active_project
node_qml_shell -->|"binds state"| node_active_project
node_active_project -->|"selects and loads"| node_project_state
node_local_projects -->|"discovers and stores"| node_project_state
node_project_state -->|"uses"| node_qgis_runtime
node_synchronization -->|"downloads and updates"| node_local_projects
node_synchronization -->|"orchestrates requests"| node_mergin_api
node_mergin_api -->|"authenticates with"| node_auth
node_auth -->|"persists credentials"| node_credentials
node_map_canvas -->|"renders through"| node_map_adapter
node_map_adapter -->|"adapts rendering"| node_qgis_runtime
node_qml_shell -->|"composes"| node_map_canvas
node_layer_models -->|"adapts layers and features"| node_qgis_runtime
node_qml_shell -->|"displays"| node_layer_models
node_editing_tools -->|"edits layers"| node_qgis_runtime
node_map_canvas -->|"routes interaction"| node_editing_tools
node_form_page -->|"edits through"| node_attribute_controller
node_attribute_controller -->|"reads and commits features"| node_qgis_runtime
node_qml_shell -->|"composes"| node_form_page
node_position_kit -->|"consumes fixes"| node_position_providers
node_position_kit -->|"coordinates recording"| node_tracking
node_tracking -->|"uses"| node_platform_services
node_position_kit -->|"supplies position"| node_map_adapter
node_build -->|"builds"| node_native_entry
node_ci_delivery -->|"runs platform builds"| node_build
node_gallery -.->|"develops shared UI for"| node_qml_shell

click node_native_entry "https://github.com/merginmaps/mobile/blob/master/app/main.cpp"
click node_qml_shell "https://github.com/merginmaps/mobile/blob/master/app/qml/main.qml"
click node_active_project "https://github.com/merginmaps/mobile/blob/master/app/activeproject.cpp"
click node_local_projects "https://github.com/merginmaps/mobile/blob/master/core/localprojectsmanager.cpp"
click node_project_state "https://github.com/merginmaps/mobile/blob/master/core/project.cpp"
click node_mergin_api "https://github.com/merginmaps/mobile/blob/master/core/merginapi.cpp"
click node_auth "https://github.com/merginmaps/mobile/blob/master/core/merginuserauth.cpp"
click node_credentials "https://github.com/merginmaps/mobile/blob/master/core/credentialstore.h"
click node_synchronization "https://github.com/merginmaps/mobile/blob/master/app/synchronizationmanager.cpp"
click node_map_canvas "https://github.com/merginmaps/mobile/blob/master/app/qml/map/MMMapCanvas.qml"
click node_map_adapter "https://github.com/merginmaps/mobile/blob/master/app/map/inputmapcanvasmap.cpp"
click node_layer_models "https://github.com/merginmaps/mobile/blob/master/app/layer/layertreemodel.cpp"
click node_editing_tools "https://github.com/merginmaps/mobile/blob/master/app/maptools/recordingmaptool.cpp"
click node_form_page "https://github.com/merginmaps/mobile/blob/master/app/qml/form/MMFormPage.qml"
click node_attribute_controller "https://github.com/merginmaps/mobile/blob/master/app/attributes/attributecontroller.cpp"
click node_position_kit "https://github.com/merginmaps/mobile/blob/master/app/position/positionkit.cpp"
click node_position_providers "https://github.com/merginmaps/mobile/blob/master/app/position/providers/abstractpositionprovider.cpp"
click node_tracking "https://github.com/merginmaps/mobile/blob/master/app/position/tracking/positiontrackingmanager.cpp"
click node_platform_services "https://github.com/merginmaps/mobile/blob/master/app/android/src/uk/co/lutraconsulting/PositionTrackingService.java"
click node_build "https://github.com/merginmaps/mobile/blob/master/CMakeLists.txt"
click node_ci_delivery "https://github.com/merginmaps/mobile/blob/master/.github/workflows/android.yml"
click node_gallery "https://github.com/merginmaps/mobile/blob/master/gallery/main.cpp"

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_native_entry,node_qml_shell,node_active_project toneBlue
class node_local_projects,node_project_state,node_mergin_api,node_auth,node_credentials,node_synchronization toneAmber
class node_qgis_runtime,node_map_canvas,node_map_adapter,node_layer_models,node_editing_tools,node_form_page,node_attribute_controller toneMint
class node_position_kit,node_position_providers,node_tracking,node_platform_services toneRose
class node_build,node_ci_delivery,node_gallery toneIndigo
```

## Components

### Mobile application

- [Native entry point](https://github.com/merginmaps/mobile/blob/master/app/main.cpp): Qt executable · `app/main.cpp`
- [QML application shell](https://github.com/merginmaps/mobile/blob/master/app/qml/main.qml): Qt Quick UI · `app/qml/main.qml`
- [Active project bridge](https://github.com/merginmaps/mobile/blob/master/app/activeproject.cpp): UI state controller · Exposes the selected project to application and QML state. · `app/activeproject.cpp`

### Projects and sync

- [Local project manager](https://github.com/merginmaps/mobile/blob/master/core/localprojectsmanager.cpp): project storage · `core/localprojectsmanager.cpp`
- [Project state](https://github.com/merginmaps/mobile/blob/master/core/project.cpp): QGIS project model · `core/project.cpp`
- [Mergin API client](https://github.com/merginmaps/mobile/blob/master/core/merginapi.cpp): network client · `core/merginapi.cpp`
- [User authentication](https://github.com/merginmaps/mobile/blob/master/core/merginuserauth.cpp): auth service · `core/merginuserauth.cpp`
- [Credential store](https://github.com/merginmaps/mobile/blob/master/core/credentialstore.h): secure storage boundary · Bounds keychain and plaintext credential implementations. · `core/credentialstore.h`
- [Synchronization manager](https://github.com/merginmaps/mobile/blob/master/app/synchronizationmanager.cpp): sync orchestrator · Reconciles local project changes with Mergin Maps services. · `app/synchronizationmanager.cpp`

### GIS interaction

- **QGIS runtime**: GIS library boundary · Provides projects, layers, rendering, forms, and geometry.
- [Map canvas](https://github.com/merginmaps/mobile/blob/master/app/qml/map/MMMapCanvas.qml): QML map view · `app/qml/map/MMMapCanvas.qml`
- [Map rendering adapter](https://github.com/merginmaps/mobile/blob/master/app/map/inputmapcanvasmap.cpp): map state adapter · Adapts QGIS rendering and coordinate state for QML. · `app/map/inputmapcanvasmap.cpp`
- [Layer and feature models](https://github.com/merginmaps/mobile/blob/master/app/layer/layertreemodel.cpp): QML item models · Translates QGIS layer trees and feature lists for QML. · `app/layer/layertreemodel.cpp`
- [Capture and editing tools](https://github.com/merginmaps/mobile/blob/master/app/maptools/recordingmaptool.cpp): map-tool controllers · Supports recording, splitting, and sketching edits. · `app/maptools/recordingmaptool.cpp`
- [Feature form UI](https://github.com/merginmaps/mobile/blob/master/app/qml/form/MMFormPage.qml): QML form view · `app/qml/form/MMFormPage.qml`
- [Attribute form controller](https://github.com/merginmaps/mobile/blob/master/app/attributes/attributecontroller.cpp): form model/controller · Maps QGIS fields and feature values to editors and commits changes. · `app/attributes/attributecontroller.cpp`

### Position and device

- [Position kit](https://github.com/merginmaps/mobile/blob/master/app/position/positionkit.cpp): position coordinator · `app/position/positionkit.cpp`
- [Position providers](https://github.com/merginmaps/mobile/blob/master/app/position/providers/abstractpositionprovider.cpp): provider abstraction · Supports internal GPS, Bluetooth/NMEA, network, and simulation sources. · `app/position/providers/abstractpositionprovider.cpp`
- [Position tracking](https://github.com/merginmaps/mobile/blob/master/app/position/tracking/positiontrackingmanager.cpp): tracking backend · Uses Android and iOS platform implementations. · `app/position/tracking/positiontrackingmanager.cpp`
- [Native platform services](https://github.com/merginmaps/mobile/blob/master/app/android/src/uk/co/lutraconsulting/PositionTrackingService.java): Android and iOS integration · `app/android/src/uk/co/lutraconsulting/PositionTrackingService.java`

### Build and delivery

- [CMake build targets](https://github.com/merginmaps/mobile/blob/master/CMakeLists.txt): build system · Builds native app, core library, and dependencies. · `CMakeLists.txt`
- [CI and store delivery](https://github.com/merginmaps/mobile/blob/master/.github/workflows/android.yml): release automation · Builds platform packages and drives mobile-store delivery. · `.github/workflows/android.yml`
- [QML Gallery](https://github.com/merginmaps/mobile/blob/master/gallery/main.cpp): component sandbox · Separate executable for shared QML component development. · `gallery/main.cpp`

## Connections

- Native entry point → QML application shell: starts
- Native entry point → Active project bridge: initializes
- QML application shell → Active project bridge: binds state
- Active project bridge → Project state: selects and loads
- Local project manager → Project state: discovers and stores
- Project state → QGIS runtime: uses
- Synchronization manager → Local project manager: downloads and updates
- Synchronization manager → Mergin API client: orchestrates requests
- Mergin API client → User authentication: authenticates with
- User authentication → Credential store: persists credentials
- Map canvas → Map rendering adapter: renders through
- Map rendering adapter → QGIS runtime: adapts rendering
- QML application shell → Map canvas: composes
- Layer and feature models → QGIS runtime: adapts layers and features
- QML application shell → Layer and feature models: displays
- Capture and editing tools → QGIS runtime: edits layers
- Map canvas → Capture and editing tools: routes interaction
- Feature form UI → Attribute form controller: edits through
- Attribute form controller → QGIS runtime: reads and commits features
- QML application shell → Feature form UI: composes
- Position kit → Position providers: consumes fixes
- Position kit → Position tracking: coordinates recording
- Position tracking → Native platform services: uses
- Position kit → Map rendering adapter: supplies position
- CMake build targets → Native entry point: builds
- CI and store delivery → CMake build targets: runs platform builds
- QML Gallery → QML application shell: develops shared UI for
