garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/the-server-stack.md

raw


topic: the-server-stack triggers: [crates/server, deploy/server-package, server-package.sh, atlas_proxy.rs, static_files.rs, pipeline.tsx, crates/atlas/src/geocoder.rs, crates/core/src/services.rs, crates/cartopolis/src/services.rs, crates/atlas/src/osm, layers.rs, route_ahead.rs, street_detail.rs, "/api/services", ServiceDirectory, geo_nav.rs, docs/guides/server.md] updated: 2026-11-12

What a Cartopolis server is made of, and where its clients find it

The client asks the server where its geo services are

GET /api/services (cartopolis_core::services::ServiceDirectory) names the geocoder, the OSM query endpoint, the map-data cell tree, terrain and height. The simulator answers from geocoder_url, osm_query_url, map_data_url, terrain_url and height_url (CARTO_* in its environment); each defaults to cartopolis.org's. The client asks once per session, after the handshake, and each resolver reads its own CARTO_* override first, then the server's answer, then its compiled-in default.

Before this every client asked cartopolis.org whatever it had signed in to, so a second server could not serve its own search or map data. The tile template was the one exception: it has been in the handshake since ADR-014.

An HTTP document, not a handshake field, so it moved no protocol version: an older server answers 404 (or its web host's page) and the client keeps its defaults. Only a value that differs from the default counts — the web build's defaults for terrain and height are relative paths, and the server spelling the same place absolutely would change only the cache key. On the hosted server Caddy must pass /api/services to the simulator, or the web client gets the page and keeps its defaults.

What the hosted stack held (measured 2026-11-10, garage44.eu)

PartRuns asDiskMemory
Simulatorsystemd, native0.55 GB109 MB
Atlassystemd, native65 GB (AHN6 sheets 62 GB) + 1.9 GB site tree6.7 GB
Nominatim (NL, address style)Docker, PostgreSQL23 GB2.5 GB
Overpass (NL, daily diffs)Docker19 GB63 MB
VersaTiles (planet z0–14 + land cover)Docker68.6 GB237 MB
CaddyDocker—88 MB

Nominatim was frozen at its 2026-07-11 import: its update node cache (105 GB) was deleted, so updating it means a full re-import. The Compose file and the Caddyfile exist only on the host; docs/guides/server.md holds an older copy.

What the client actually uses Nominatim and Overpass for

A fixed set of questions about one country, which is why both are candidates to be answered from files atlas builds from one OSM extract rather than kept as services.

Overpass answers cut from the extract (crates/atlas/src/osm)

Atlas's tall, street, transit, shops and speeds datasets read a Geofabrik .osm.pbf (ATLAS_OSM_EXTRACT, a URL or a path; the Netherlands by default, re-downloaded after a week into <data_dir>/osm/) and write, per cell, the document Overpass would have answered to the client's query. The client reads a covered cell from the map-data host and asks Overpass only for the rest.

Checked 2026-11-10 against Overpass, Groningen, Netherlands extract of that day:

Options looked at for replacing them (2026-11-10, desk research)

Place search without Nominatim (crates/atlas/src/geocoder.rs)

Atlas's geocoder dataset indexes every address, street, named place and named amenity, shop, station and sight in the extract into one file, <data_dir>/geocoder/index.bin, which atlas answers /geocode/search and /geocode/reverse from in Nominatim's jsonv2 shape; the server's geocoder_url points clients at …/geocode. Search is by word prefix, so it matches while typed, which Nominatim could not (geocoding-latency.md).

Measured 2026-11-11, whole Netherlands, mac-1, release build:

One program, two processes (crates/server, since 2026-11-11)

cartopolis-server is what a new server installs: one binary and one cartopolis.toml, the simulator's keys at the top and atlas's under [atlas]. It runs the simulator and starts itself again as cartopolis-server atlas, a second process it restarts when it ends (a doubling pause up to a minute, reset after a long run) and that ends when it does (it holds the child's stdin). The simulator's HTTP listener answers atlas's paths by passing them on (atlas_proxy, SimConfig::atlas_url), so a TLS proxy in front needs one upstream.

Rejected: one process. Merging was easy — no path is claimed by both, atlas pulls in none of the simulator's encryption or call code — but atlas.md keeps atlas out of the tick's runtime, and the numbers agree: the whole-country layer run peaked at 4.3 GB and the geocoder build at 3.5 GB. A crash there must not end the world.

It serves the web UI (web_root) and atlas's map-data tree under /data/ (static_files, with the .br copies atlas writes), and points every service the file leaves at cartopolis.org's address at its own public_base_url — tiles at the public tiles.versatiles.org, same schema as the mirror. Still the operator's: TLS in front. The hosted server still runs the two as separate systemd units behind Caddy; it does not use this binary yet.

The download (deploy/build/server-package.sh → dist/server/, published by midas deploy server at https://cartopolis.org/server/ since 2026-11-12) is the binary, cartopolis-script-host beside it (the process prim scripts run in, Bun compiled into it by deploy/build/script-host.sh, 87 MB unpacked; found there when the file names no script_host — javascript-prim-scripts.md), the built web UI in web/ beside it — found there when the file names no web_root — an example cartopolis.toml, the systemd units and install.sh, and release.json beside it for the owner to sign. That one script is both curl … | sh and the unpacked package's installer: it puts them in /opt/cartopolis-server (owned by cartopolis), asks for the address and the first admin on /dev/tty (so a piped script can still ask; cartopolis-server create-admin is the only way to an admin without the separate simulator binary), and adds the address to Caddy when Caddy is installed. The binary is server.sh's, linked against glibc ≤ 2.35. Not in it: calls, which need a public UDP address (calls_listen, calls_public_addr) the installer cannot know.

Updates are the program's, approved twice (crates/server/src/update.rs, docs/mockups/release-approval): the owner signs a release on their phone, and a server's admin installs it from the Admin page. The program reads release.json and release.json.sig every six hours, acts only on an ECDSA P-256 signature by a key compiled into it (RELEASE_KEYS, empty until the owner's phone key exists — so today nothing installs) and a version code higher than its own, and downloads the package into data/update/. Install asks the admin's password again (prove_again), runs the new program's version and check-database on a VACUUM INTO copy, keeps the old program, script host, web UI and a database snapshot in previous/, renames the new ones into place and ends; systemd starts the new one. That one counts its starts in data/update/pending.json and, past three that did not stay up two minutes, restores previous/ and ends so the old one starts; the release goes into failed.json and is skipped. The simulator only routes /api/admin/update* to it (server_update.rs, admins only; 404 on the hosted server).

Rejected on the way, 2026-11-12: a daily timer that installed by itself (install.sh --update) — the owner wants admins told, not bypassed — and updating from shell scripts at all; Forgejo releases as the source (unused since July 2026, and Forgejo 1.22 here has no latest/download URL).

The cost of the program replacing itself: its directory belongs to the user it runs as, so code that took the running server over could also replace the binary for the next start, which a root-owned binary prevented.

Admin › Data shows the extract (source, size, when downloaded) and runs every OSM layer over the country in one job (POST /api/pipeline/osm): a route of its own because a typed area is held to 400 km².