How the Greenstand repos work together
These maps show how the 14 code repos of the estate work together at run time. A code repo is a source repo that holds code. The maps show the main calls and the shared systems. They do not show every call. The last map shows the platform that the code repos run on. To learn about Greenstand itself, start with Greenstand-Overview and How to contribute to Greenstand.
How to read the maps:
- An arrow points from the repo or the system that uses something to the repo or the system that it uses.
- A cylinder is a store of data.
Capture and verification
A grower uses the Treetracker app (treetracker-android). The app uploads the photos to object
storage. Then it uploads a bundle, a small data file that lists the captures. The bundle chain
opens each bundle. The bundle chain is four public repos outside the estate. It sends each
capture to treetracker-field-data, and it registers new growers with treetracker-api. One repo
of the chain also writes the row of a capture to the trees table of the old public schema,
if that row is not there yet. treetracker-field-data uses no message broker.
flowchart TB
n_treetracker_android["treetracker-android"]
n_storage[("Cloud storage")]
n_bundles["Bundle chain"]
n_treetracker_field_data["treetracker-field-data"]
n_treetracker_api["treetracker-api"]
n_treetracker_android -->|"uploads captures"| n_storage
n_bundles -->|"downloads bundles"| n_storage
n_bundles -->|"sends captures"| n_treetracker_field_data
n_bundles -->|"registers growers"| n_treetracker_api
The admin panel (treetracker-admin-client) gets the captures to verify from
treetracker-admin-api, and it sends the verifications there. It loads the photos from
images-api. treetracker-admin-api stores each decision in the trees table. A job of
treetracker-airflow-dags is set to copy the decisions into the field_data and treetracker
schemas once a day (see Shared database).
flowchart TB n_treetracker_admin_client["treetracker-admin-client"] n_treetracker_admin_api["treetracker-admin-api"] n_images_api["images-api"] n_treetracker_admin_client -->|"verifies captures"| n_treetracker_admin_api n_treetracker_admin_client -->|"loads images"| n_images_api
A job of treetracker-airflow-dags is set to compute the earnings of the growers of one organization from their approved captures every day. The admin panel lists the earnings and logs the payments through an earnings API outside the estate.
For the story of one capture, from the grower's phone to the grower's reward, with pictures, see The journey of a capture.
For the data that an organization gets from its captures, with pictures, see chapter 4 of the capture journey.
Web map
The web map (treetracker-web-map-client) reads trees, wallets, and tokens from treetracker-query-api. It loads map tiles from treetracker-tile-server. It signs users in with Keycloak. It loads the small photos of its lists from images-api. images-api fetches the photos from cloud storage. The tree page loads the full photo from cloud storage. treetracker-airflow-dags fills the tile cache before users ask for the tiles.
flowchart TB
n_treetracker_web_map_client["treetracker-web-map-client"]
n_treetracker_query_api["treetracker-query-api"]
n_treetracker_tile_server["treetracker-tile-server"]
n_images_api["images-api"]
n_keycloak["Keycloak"]
n_storage[("Cloud storage")]
n_treetracker_airflow_dags["treetracker-airflow-dags"]
n_treetracker_web_map_client -->|"reads trees, wallets"| n_treetracker_query_api
n_treetracker_web_map_client -->|"loads tiles"| n_treetracker_tile_server
n_treetracker_web_map_client -->|"loads images"| n_images_api
n_treetracker_web_map_client -->|"signs users in"| n_keycloak
n_images_api -->|"fetches photos"| n_storage
n_treetracker_airflow_dags -->|"fills the tile cache"| n_treetracker_tile_server
For the story of one capture on the public web map, with pictures, see chapter 2 of the capture journey.
Wallet
The wallet app (treetracker-wallet-app) and the wallet admin panel (treetracker-wallet-admin-client) use treetracker-wallet-api. The code has two versions of treetracker-wallet-api that share one set of wallets. No public source confirms which version each one uses in production. The wallet app signs users in with Keycloak. The wallet app reads the tree of a token from treetracker-query-api for its token page.
No API creates tokens. A job of treetracker-airflow-dags creates them when an operator starts it. The operator names an organization and a wallet. The job puts one token for each approved capture of the growers of that organization and of its child organizations into that wallet. A capture that has a token already gets no second token.
flowchart TB n_treetracker_wallet_admin_client["treetracker-wallet-admin-client"] n_treetracker_wallet_api["treetracker-wallet-api"] n_treetracker_wallet_app["treetracker-wallet-app"] n_keycloak["Keycloak"] n_treetracker_query_api["treetracker-query-api"] n_treetracker_wallet_admin_client -->|"manages wallets"| n_treetracker_wallet_api n_treetracker_wallet_app -->|"reads wallets, sends tokens"| n_treetracker_wallet_api n_treetracker_wallet_app -->|"signs users in"| n_keycloak n_treetracker_wallet_app -->|"reads token trees"| n_treetracker_query_api
For the story of one capture as an impact token, with pictures, see chapter 3 of the capture journey.
Shared database
The code repos share one PostgreSQL database. Most of them write to their own schema. Some also
write to shared schemas: treetracker-admin-api, treetracker-field-data, and the bundle chain
write to the old public schema. treetracker-airflow-dags writes tokens, earnings, session
segments, map data, stakeholder records, and the authors of messages. It is also set to run
domain-migration-scripts, a public repo outside the estate, once a day. This job copies the
captures and the decisions of the admins from the old public schema into the field_data and
treetracker schemas. treetracker-query-api and treetracker-tile-server read the data that the
other repos write. Thus, a schema change in one repo can affect them.
The user API of treetracker-wallet-app listens on a PostgreSQL channel for new wallets.
flowchart LR
n_treetracker_api["treetracker-api"]
n_postgres[("PostgreSQL")]
n_treetracker_field_data["treetracker-field-data"]
n_treetracker_wallet_app["treetracker-wallet-app"]
n_treetracker_wallet_api["treetracker-wallet-api"]
n_treetracker_admin_api["treetracker-admin-api"]
n_bundles["Bundle chain"]
n_treetracker_query_api["treetracker-query-api"]
n_treetracker_tile_server["treetracker-tile-server"]
n_treetracker_airflow_dags["treetracker-airflow-dags"]
n_treetracker_api -->|"writes"| n_postgres
n_treetracker_field_data -->|"writes"| n_postgres
n_treetracker_wallet_app -->|"listens for new wallets"| n_postgres
n_treetracker_wallet_api -->|"writes"| n_postgres
n_treetracker_admin_api -->|"writes"| n_postgres
n_bundles -->|"writes rows of the trees table"| n_postgres
n_treetracker_query_api -->|"reads"| n_postgres
n_treetracker_tile_server -->|"reads"| n_postgres
n_treetracker_airflow_dags -->|"writes tokens, earnings, sessions, map data"| n_postgres
n_treetracker_airflow_dags -->|"copies captures once a day"| n_postgres
Platform
This map shows what treetracker-infrastructure provides. It does not show run-time calls. treetracker-infrastructure provisions the database. It runs RabbitMQ, Keycloak, and the API gateway. It also deploys the pipelines (Airflow DAGs) of treetracker-airflow-dags.
The workflows of the other code repos start their deploys. Each code repo uses one of these ways:
- A workflow applies the Kubernetes manifests of the code repo to a cluster.
- A workflow commits the new image tag to the Kubernetes manifests. Then a GitOps controller outside the estate applies the change. A GitOps controller is a program that applies the changes in a repo to a cluster.
- A workflow uploads the files of a web app to static hosting.
- A workflow sends the Android app to the Google Play Store.
For the container registry, the clusters, and the other resources that the code repos share, see the shared-resource page.
flowchart LR
n_treetracker_infrastructure["treetracker-infrastructure"]
n_treetracker_airflow_dags["treetracker-airflow-dags"]
n_postgres[("PostgreSQL")]
n_rabbitmq["RabbitMQ"]
n_keycloak["Keycloak"]
n_gateway["API gateway"]
n_treetracker_infrastructure -->|"deploys the pipelines"| n_treetracker_airflow_dags
n_treetracker_infrastructure -->|"provisions"| n_postgres
n_treetracker_infrastructure -->|"runs"| n_rabbitmq
n_treetracker_infrastructure -->|"runs"| n_keycloak
n_treetracker_infrastructure -->|"runs"| n_gateway
Not on the maps
- Most links to systems outside the estate. Examples:
- The earnings API (see Capture and verification).
- The stakeholder API. The earnings API gets the names of the growers from it.
- The tables of the contract API. The earnings job reads the dates of its payment rule from them. The rule itself is in the code of the job.
- A map data API and a messaging API.
- treetracker-api and treetracker-field-data have routes that update rows of the
treestable through treetracker-admin-api. No client calls these routes today: the admin panel calls treetracker-admin-api directly. - Queues that only one repo of the estate uses, and a message that only a development setup sends.
- In production, the web map loads tiles from tile hosts. No repo of the estate shows what serves these hosts.
- Small reads, for example of country names, and the static hosting of the web apps.
How the maps are made
The edges come from ecosystem.json. Each edge records its evidence: a file
and a line in the source repo, at its snapshot commit. An edge of a system outside the estate
cites a public repo outside the estate, with its commit (@<commit>).
.github/scripts/build-ecosystem-maps.mjs draws the maps from ecosystem.json and
estate.json. The Estate index check fails a pull request if a map is stale, or if
ecosystem.json has an error. It also fails after a repo is regenerated: a person checks the
edges of that repo again, then sets its checkedAt entry to the new snapshot commit.