Onboarding Guide: treetracker-tile-server

Generated from the Understand-Anything knowledge graph. Source commit b619c05.

This repo is the Greenstand fork of upstream node-mapnik. The Greenstand part is the tile server in greenstand/, plus deployment/, the Dockerfile, and .github/. The src/ C++ code is upstream binding code. The analysis excluded the upstream test fixtures, bench/, docs/, the root deps/, all examples/ directories, and the shapefiles.

Project Overview

The tile server renders Treetracker tree data from PostGIS into 256x256 PNG tiles and UTF grid JSON tiles. It uses the native Mapnik binding to draw each tile.

How the parts fit:

Architecture Layers

The graph has 657 nodes and 1265 edges. It puts each file into one of 10 layers. The counts are graph nodes.

Key Concepts

Guided Tour

Follow these 15 steps in order. Steps 1 to 8 cover the tile server. Steps 9 to 12 cover the native Mapnik binding. Steps 13 to 15 cover the delivery.

  1. Project overview
    Files: README.md, package.json
    What to see: the README text is upstream node-mapnik documentation. In package.json, main loads the native Mapnik binding, and start runs the tile server.
  2. Server entry point
    Files: greenstand/server.js, .env
    What to see: server.js checks the two zoom thresholds at startup.
  3. Express tile routes
    Files: greenstand/app.js
    What to see: the Express service answers PNG and UTF grid routes, and it returns a version banner for other paths.
  4. Per-tile style builder
    Files: greenstand/config.js, greenstand/sphericalmercator.js, greenstand/layers/postgis.xml
    What to see: getXMLString has a GeoJSON branch and a PostGIS branch.
  5. Map modes and base queries
    Files: greenstand/Map.js, greenstand/sqls/SQLCase1.js to greenstand/sqls/SQLCase4.js
    What to see: case 1 counts trees per region, case 2 returns tree points, case 3 clusters with ST_ClusterWithin, and case 4 reads precomputed clusters.
  6. Specialized query variants
    Files: greenstand/sqls/SQLCase1WithZoomTarget.js, greenstand/sqls/SQLZoomTargetCase1.js, greenstand/sqls/*Timeline.js, greenstand/sqls/SQLCase2Wallet.js
    What to see: these SQL builders extend the base SQL builders. The zoom target is the most populated subregion two zoom levels deeper.
  7. Cached query pool
    Files: greenstand/PGPool.js
    What to see: PGPool has an LRU cache and merges concurrent identical queries.
  8. Base styles
    Files: greenstand/xml.js, greenstand/xml2.js
    What to see: config.js replaces the json_data and select * from trees placeholders.
  9. Mapnik JavaScript loader
    Files: lib/mapnik.js, lib/index.js
    What to see: lib/mapnik.js finds the compiled binding through node-pre-gyp.
  10. Native binding core
    Files: src/node_mapnik.cpp, src/mapnik_map*.cpp
    What to see: these files implement Map.fromString and Map.render, which app.js calls.
  11. Images, PNG, UTF grids
    Files: src/mapnik_image*.cpp, src/mapnik_grid.cpp
    What to see: these classes produce the two tile formats.
  12. Native build toolchain
    Files: Makefile, binding.gyp, scripts/
    What to see: make release_base builds the binding against an installed mapnik-config.
  13. Container image
    Files: Dockerfile, .dockerignore
    What to see: the base image greenstand/tile-server-base:first must supply Mapnik. The Dockerfile adds Node.js 14.21.3 and runs make release_base.
  14. Kubernetes deployment
    Files: deployment/base/
    What to see: the Ambassador Mapping routes /tiles/ to the Service. The SealedSecret supplies DB_URL.
  15. Release and deploy pipelines
    Files: .github/workflows/build-deploy.yml, .releaserc, CHANGELOG.md, .github/workflows/deploy-test.yml, .github/workflows/deploy-prod.yml
    What to see: a push releases and deploys to development. Test and production need a manual run.

File Map (by layer)

Tile Server API

Tile Style Service

Tree Query And Cache

Tile Server Tests And Fixtures

Container And Kubernetes Deployment

Release And Deploy Pipelines

Project Config And Docs

Complexity Hotspots

The graph rates 26 files as complex. Two of them are tile server source files: app.js and config.js. The line counts come from the files.

Business Domains

domain-graph.json has 4 domains, 17 flows, and 90 steps. The bold names are the flow labels in the graph. The domain view of the viewer shows each step.

Map Tile Serving: the Express routes that answer tile requests.

Tile Stylesheet Composition: Config.getXMLString builds the Mapnik style.

Tree Query Selection: Map.init picks an SQL builder.

Release and Deployment: the workflows, the image, and the manifests.