SPB Git

Repository Public BSD-3-Clause

ARCHITECTURE.md 11.3 KB 134 lines markdown

1# ORIX Maps — architecture23ORIX Maps is a native iOS / iPadOS map application that works without any Apple or Google map service and without a4network once a region is installed. This document describes how it is built. Decisions and their reasons are in5`docs/adr/`; formats are specified in `docs/ORIXMAP_FORMAT.md`, `docs/CATALOG_API.md` and6`Packages/ORIXRouting/docs/ORIXGRAPH_FORMAT.md`; what works today is in `STATUS.md`.78## The three parts910```11 Build node (macOS)                     Web node                         Device12 ───────────────────                    ─────────                        ──────13 OSM extract (Geofabrik)                www.orixlab.dev/maps/v1/         ORIX Maps app14   │ osmium extract                       catalog.json                     │ CatalogClient ── HTTPS, no identifier15   ├─ Planetiler + Protomaps ─ map.pmtiles  regions/<id>.json               │ DownloadManager ─ Range resume16   ├─ orix-geocoder-build ─ search.sqlite   regions/<id>/versions.json      │ PackageVerifier ─ Ed25519 + SHA-25617   ├─ orix-routing-build ─ routing.orixgraph files/<id>/<ver>/….orixmap      │ RegionStore ──── atomic install18   └─ orix-package build ─ <id>-<ver>.orixmap  (static files, Range, ETag)   ▼19        signed with the node's private key                                 map.pmtiles   → MapLibre Native (Metal)20   orix-package publish / catalog → rsync                                   search.sqlite → SearchEngine (FTS5)21                                                                            routing.orixgraph → Router (A*)22```2324Nothing flows from the device to a server except plain `GET` requests for the catalog and for the package the user25chose. Search text, routes, positions and saved places never leave the device.2627## Repository layout2829| Path | Content |30|---|---|31| `Apps/ORIXMaps/` | The application: XcodeGen project, SwiftUI sources, resources (world base map, world labels, glyphs, privacy manifest) |32| `Packages/` | One SwiftPM package per module (below); each builds and tests alone on macOS with `swift test` |33| `Infrastructure/` | Build-time tools, macOS only: `ingestion/ORIXOSM` (PBF reader), `tile-builder`, `geocoder-builder`, `routing-builder`, `package-builder`, `distribution/`, `build-region.sh`, `regions.json` |34| `docs/` | ADRs, format and API specifications, data source register, testing, release |35| `scripts/` | `build.sh` (generate / build / run / test), `asc.py`, `make-icon.swift`, `inspect-pmtiles.py`, localization |36| `data/` | Local geodata and development keys, git-ignored |3738## Modules3940Dependencies point downwards only; `ORIXGeoCore` depends on nothing.4142```43                         Apps/ORIXMaps (SwiftUI, composition root: AppModel)44   ┌──────────┬───────────┬───────────┬─────────────┬───────────┬──────────┬───────────┬──────────┐45 ORIXMap-   ORIXMap-    ORIXSearch  ORIXNavigation ORIXPlaces ORIXTracks ORIXLocation ORIXDesign-46 Renderer   Package        │            │             │           │          │        System47   │           │           │        ORIXRouting   ORIXGeoExchange ┘          │        ORIXPrivacy48 ORIXMapStyle  │           │            │             │                      │        ORIXTerrain49   └───────────┴───────────┴────────────┴──── ORIXGeoCore ───────────────────┘        ORIXTileStore50                                                                                      ORIXAtlas (prototype)51```5253| Module | Responsibility | Notes |54|---|---|---|55| `ORIXGeoCore` | Coordinates, bounding boxes (antimeridian-aware), Web Mercator and tile math, spherical geodesy, polyline projection and simplification, coordinate text (decimal, DMS, DDM, UTM), encoded polylines | Pure Swift |56| `ORIXMapStyle` | `MapTheme` (39 colour roles + weights and visibility rules), the eight ORIX themes, theme file import/export with validation, `StyleBuilder` (MapLibre style documents for the tile schema, base map + regions + world labels + application overlays), `RegionRenderPlanner`, point-of-interest groups | No rendering code |57| `ORIXMapRenderer` | Engine-neutral `MapController` (camera, style, overlays, events, frame statistics) and `MapBackend` protocol; `MapLibreBackend` / `MapCanvas` is the only code importing MapLibre | ADR 0002 |58| `ORIXTileStore` | PMTiles v3 reader, Mapbox Vector Tile decoder, LRU cache, `TileStore` actor | Used by tools and by the Atlas prototype; MapLibre reads archives itself |59| `ORIXAtlas` | Specification and prototype of the proprietary Metal engine | Not linked in the app; `docs/ATLAS_ENGINE.md` |60| `ORIXMapPackage` | `.orixmap` container reader/writer, manifest, Ed25519 trust store, streaming verifier, `RegionStore` (atomic install, update, rollback, delete, space checks, crash recovery), `CatalogClient`, `DownloadManager` | The only module with network code |61| `ORIXSearch` | Search index schema, writer and engine: FTS5 full text, grid spatial index, address resolution, categories (64, bilingual), typo correction, reverse geocoding, multi-region | System SQLite |62| `ORIXRouting` | `.orixgraph` format (memory-mapped), writer, A* / Dijkstra on directed-edge states with turn restrictions, car / bicycle / pedestrian profiles, alternatives, waypoints, maneuvers, English and French instructions | ADR 0004 |63| `ORIXNavigation` | `NavigationSession`: map matching, progress and ETA, announcement scheduling, off-route detection with hysteresis, reroute requests, stops and arrival; `VoiceGuide` (AVSpeechSynthesizer) | Value-type state machine, no clock, no I/O |64| `ORIXLocation` | `LocationService` (progressive permission, usage-based accuracy and background rule), `CoreLocationProvider`, `SimulatedLocationProvider` | |65| `ORIXGeoExchange` | GPX 1.1, GeoJSON, KML 2.2 codecs with limits and hostile-input tests | Shared by places and tracks |66| `ORIXPlaces` | Collections, saved places with notes, local history, export/import, backup (SQLite) | |67| `ORIXTracks` | `TrackRecorder` (filtering, segments), statistics, profiles, `TripReplay`, `TrackStore` with crash-safe in-progress recording | |68| `ORIXTerrain` | Elevation sources (HGT tiles, mosaic) and `ElevationProfile` | No elevation data is distributed yet: inactive in the app |69| `ORIXPrivacy` | Log redaction, `PrivacyLog`, `NetworkPolicy` (what a request may contain) | Enforced on every request by `PolicedTransport` in the app |70| `ORIXDesignSystem` | Tokens, floating map controls, chips, buttons, empty states, notices, unit-aware formatter | |7172## Application7374`AppModel` is the composition root: it creates the stores and services once and injects them through the SwiftUI75environment. There are no singletons.7677| Object | Role |78|---|---|79| `MapController` + `StyleCoordinator` | The map view state; the style document is rebuilt when the theme, label language or set of regions changes. Overlays (route, position, pins, selection, track, measure, user layers, search results) are GeoJSON sources declared in every style, so a theme change never loses them. |80| `RegionsModel` | Installed regions, catalog, downloads; publishes `MapRegion` values to the map, search and routing layers |81| `SearchModel` | Opens one index per installed region; debounced suggestions, full search, categories, reverse geocoding for dropped pins |82| `DirectionsModel` | Opens one graph per region; planning (stops, modes, avoid options, alternatives), guidance with `NavigationSession`, simulated drives, rerouting, voice |83| `LibraryModel`, `TracksModel`, `UserLayersModel`, `ThemeStore` | Saved places and history, tracks and recording, imported layers, themes |84| `LocationService` | The single source of position for the map arrow, guidance and recording |8586The interface is one screen: the map, floating controls, and a panel (a native sheet with detents on iPhone, a side87column on iPad) whose content follows `AppModel.route` — home/search, place card, directions, guidance, measure, track88recording or replay. Secondary screens (maps, collections, tracks, Explorer, planner, compass, Map Studio, settings,89about) are sheets.9091### Rendering stack92931. `background` in the water colour.942. For the base map then each drawn region: land, land cover / land use, water, tunnels, buildings (flat, then extruded95   when tilted), roads by class (casing then fill), railways, boundaries, bridges.963. Application line overlays (user layers, measure, track, alternative routes, route, travelled part).974. Labels of every source (water, roads, references, one-way arrows, house numbers, places of interest by group,98   places), then the bundled world labels (Natural Earth), which yield to region labels from zoom 7.995. Application symbols: maneuver points, pins, selection, position.100101The base map (zoom 0–6) draws fills at every zoom, overzoomed outside regions; regions take over fills and labels from102zoom 7, and draw their road network at every zoom. A region whose bounds lie inside another installed region with the103same data is not drawn twice.104105### Region lifecycle on the device106107`catalog.json` → the user taps Download → free-space check → `DownloadManager` streams to a partial file (Range +108If-Range resume, strong ETag = SHA-256) → size and SHA-256 check → `PackageVerifier` (header, manifest limits, Ed25519109signature against the compiled-in trust store, canonical layout, streaming SHA-256 of every component) → extraction into110a staging directory → fsync → rename → the previous version is kept for rollback → `RegionStore` publishes the change →111style rebuilt, search index and routing graph opened. A file imported from Files takes the same path from the verifier112on. Leftover staging state is cleaned at the next launch.113114## Concurrency115116Swift 6 language mode everywhere. Stores and engines shared across tasks are actors (`RegionStore`, `DownloadManager`,117`CatalogClient`, `SearchEngine`, `PlacesStore`, `TrackStore`, `TileStore`); the routing graph is immutable and118memory-mapped, and `Router` is a value type, so route computations run on detached tasks. Interface models are119main-actor `@Observable` classes. Pure state machines (`NavigationSession`, `TrackRecorder`) are value types tested120without a clock.121122## Security and privacy by construction123124- The only network code is in `ORIXMapPackage`, behind `HTTPTransport`; the app wraps it in `PolicedTransport`, which125  refuses any request that is not HTTPS to the catalog host, carries a query string, a body, a cookie or a126  non-allow-listed header.127- Packages are trusted by signature, not by where they came from. Installed file names come from a fixed table, never128  from the package. Every parser of external bytes (packages, PBF, PMTiles, vector tiles, graphs, search indexes, GPX /129  GeoJSON / KML, themes, backups) is bounds-checked and has corrupted-input tests.130- Logs go through `PrivacyLog`, which scrubs coordinates and long numbers.131- Position is requested only when a feature that needs it is used; background updates are on only while guidance or a132  recording runs.133- See `docs/PRIVACY.md` for the behaviour as shipped and `docs/SECURITY.md` for the threat model.134
Files main
Menu

Theme