Glossary: treetracker-field-data
Generated by .github/scripts/build-glossary.mjs from domain-graph.json (source commit 8ffb53c). Do not edit by hand.
This glossary lists the business terms of treetracker-field-data. Each term links to its domain, which says what the domain does, its rules, and its flows. The estate glossary shows which other repos use the same terms.
Terms
- app_build: Device Configuration
- app_version: Device Configuration
- bulk_pack_version: Session & Track Tracking
- db-migrate migration: Schema Migrations & Seed Data
- device_configuration: Device Configuration, Schema Migrations & Seed Data
- device_configuration_id: Session & Track Tracking
- device_identifier: Device Configuration
- DeviceConfiguration: Device Configuration
- domain_event: Schema Migrations & Seed Data
- email: Wallet Registration
- grower_account_id: Wallet Registration
- knex seed: Schema Migrations & Seed Data
- knexLegacyDB: Legacy Database Bridging
- LegacySession: Legacy Database Bridging
- LegacyTree: Legacy Database Bridging
- locations_url: Session & Track Tracking
- logged_at: Device Configuration
- organization: Session & Track Tracking
- organization_id: Session & Track Tracking
- originating_wallet_registration_id: Session & Track Tracking
- os_version: Device Configuration
- phone: Wallet Registration
- planter: Legacy Database Bridging
- planter_registrations: Legacy Database Bridging
- raw_capture: Raw Capture Ingestion, Schema Migrations & Seed Data
- RawCapture: Raw Capture Ingestion
- RawCaptureService: Raw Capture Ingestion
- reference_id: Raw Capture Ingestion
- rejection_reason: Raw Capture Ingestion
- rotation_matrix: Raw Capture Ingestion
- sdk_version: Device Configuration
- session: Session & Track Tracking, Schema Migrations & Seed Data
- session_id: Raw Capture Ingestion
- session_segment: Schema Migrations & Seed Data
- SessionModel: Session & Track Tracking
- status (unprocessed, approved, rejected): Raw Capture Ingestion
- track: Session & Track Tracking, Schema Migrations & Seed Data
- Track: Session & Track Tracking
- tree_attributes: Legacy Database Bridging
- trees: Legacy Database Bridging
- TREETRACKER_LEGACY_API_URL: Legacy Database Bridging
- user_photo_url: Wallet Registration
- v1_legacy_organization: Wallet Registration
- wallet: Wallet Registration
- wallet_registration: Wallet Registration, Schema Migrations & Seed Data
- WalletRegistration: Wallet Registration
Domains
Raw Capture Ingestion
Receives tree photo captures that the Treetracker app uploads and stores them in the field_data raw_capture table with status 'unprocessed'. Each capture belongs to an existing session and gets reference_id set to the id of a mirrored row in the legacy trees table. The domain also lists, reads, and rejects captures through the /raw-captures routes.
Terms: raw_capture, RawCapture, RawCaptureService, session_id, reference_id, rotation_matrix, rejection_reason, status (unprocessed, approved, rejected)
Rules:
- POST /raw-captures requires a uuid id and session_id, lat in -90..90, lon in -180..180, a URI image_url, and an ISO captured_at (rawCaptureSchema, unknown keys rejected).
- The handler deletes extra_attributes from the body before validation, because the mobile app does not send them yet; so no tree_attributes rows come from the API.
- The handler sets each rotation_matrix entry below 0.001 to 0 before validation.
- A capture whose session_id is not stored yet fails with HTTP 409 'has yet to be created, kindly retry later'.
- Creation is idempotent on raw_capture.id: an existing id returns the stored capture with 200, a new id is inserted with status 'unprocessed' and returns 201.
- PATCH /raw-captures/:raw_capture_id/reject requires rejection_reason and an Authorization header (422 'legacy authorization header needed' when missing); organization_id is an optional integer.
- The legacy admin API call must succeed before the capture is set to status 'rejected'.
- POST and PATCH requests without Content-Type application/json fail with HTTP 415.
Flows:
- Upload Raw Capture (
POST /raw-captures): Stores one tree capture from the Treetracker app: it checks the session, mirrors the capture into the legacy trees table, then inserts the raw_capture row with reference_id set to the legacy tree id. It returns 201 for a new capture or 200 for an existing id. - Reject Raw Capture (
PATCH /raw-captures/:raw_capture_id/reject): Rejects a capture in both systems: it patches the mirrored legacy tree through the legacy admin API with approved false and active false, then sets raw_capture.status to 'rejected' with the rejection_reason. - List Raw Captures (
GET /raw-captures): Returns a page of raw captures, newest first, filtered by status or bulk_pack_file_name, with a total count and prev/next links. - Get Raw Capture by Id (
GET /raw-captures/:raw_capture_id): Returns one raw capture with its session, wallet and device fields, or HTTP 404 when the id is unknown.
Session & Track Tracking
Records field data collection sessions on the /session routes and GPS track uploads on the /track routes. A session row links one device_configuration to the originating wallet_registration and carries target_wallet, check_in_photo_url, track_url, organization, start_time and bulk_pack_version; a track row links a locations_url file to a session.
Terms: session, SessionModel, track, Track, device_configuration_id, originating_wallet_registration_id, organization, organization_id, bulk_pack_version, locations_url
Rules:
- POST /session requires uuid id, device_configuration_id and originating_wallet_registration_id; bulk_pack_version must be 'v1' or 'v2'; unknown keys are rejected.
- Session creation is idempotent on id: 201 for a new row with created_at now, 200 with the stored session for a repeated id.
- Session list filters grower_account_id and wallet apply to wallet_registration, all other filter keys are prefixed with 'session.'.
- POST /track requires a URI locations_url, a uuid session_id and bulk_pack_file_name; track creation is not idempotent and always returns 201.
- GET /track/:track_id uses BaseRepository.getById, so an unknown id fails with 404 'Can not found track by id:<id>' from the repository.
- session.organization_id is not accepted by POST /session; per ADR 0001 a database operator sets it from the organization string.
Flows:
- Create Session (
POST /session): Stores a collection session that the app uploads before its captures, idempotent on the session id. - List Sessions (
GET /session): Returns a page of sessions joined with device and wallet details, with a count over the same joins and prev/next links. - Get Session by Id (
GET /session/:session_id): Returns one session with device and wallet details, or HTTP 404. - Record Track (
POST /track): Stores a reference to an uploaded GPS track file (locations_url) for a session and bulk pack. - List Tracks (
GET /track): Returns a page of tracks filtered by session_id or bulk_pack_file_name, with a count and prev/next links. - Get Track by Id (
GET /track/:track_id): Returns one track row; an unknown id fails with HTTP 404 from the repository.
Device Configuration
Stores the phone and app build that a grower used, as rows in the device_configuration table on the /device-configuration routes. Sessions reference these rows, and capture and session reads join them for device_identifier.
Terms: device_configuration, DeviceConfiguration, device_identifier, app_build, app_version, os_version, sdk_version, logged_at
Rules:
- POST /device-configuration requires uuid id, device_identifier, brand, model, device, hardware, manufacturer, app_build, app_version, os_version, sdk_version and an ISO logged_at; serial may be empty or null; unknown keys are rejected.
- Creation is idempotent on id: 201 for a new row with created_at now, 200 with the stored row for a repeated id.
- GET /device-configuration accepts only offset, limit and bulk_pack_file_name.
Flows:
- Register Device Configuration (
POST /device-configuration): Stores the device and app details that the app sends, idempotent on the configuration id. - List Device Configurations (
GET /device-configuration): Returns a page of device configurations filtered by bulk_pack_file_name, with a count and prev/next links. - Get Device Configuration by Id (
GET /device-configuration/:device_configuration_id): Returns one device configuration or HTTP 404.
Wallet Registration
Stores grower wallet registrations made on a device in the wallet_registration table on the /wallet-registration routes: wallet, grower_account_id, names, phone or email, user_photo_url, location and registered_at. A session names its originating wallet registration, and the wallet value identifies the legacy planter.
Terms: wallet_registration, WalletRegistration, wallet, grower_account_id, phone, email, user_photo_url, v1_legacy_organization
Rules:
- POST /wallet-registration requires uuid id and grower_account_id, wallet, URI user_photo_url, first_name, last_name, and lat -90..90 and lon -180..180; email must match /.*@.*/.
- Either phone or email is required (HTTP 422 'Either phone or email is required').
- Creation is idempotent on id: 201 for a new row, 200 with the stored row for a repeated id; the model does not set created_at (the column default does).
- GET /wallet-registration accepts only offset, limit and bulk_pack_file_name.
Flows:
- Register Wallet (
POST /wallet-registration): Stores a grower wallet registration from the app, idempotent on the registration id. - List Wallet Registrations (
GET /wallet-registration): Returns a page of wallet registrations filtered by bulk_pack_file_name, with a count and prev/next links. - Get Wallet Registration by Id (
GET /wallet-registration/:wallet_registration_id): Returns one wallet registration or HTTP 404.
Legacy Database Bridging
Keeps the legacy treetracker database in step with field data during the monolith migration. At runtime it writes a trees row (and tree_attributes rows when given) for each new capture through a second Knex client on DATABASE_URL_LEGACYDB, and rejects legacy trees through the legacy admin API. One-off ETL scripts in database/etl backfill trees.session_id and field_data.wallet_registration from legacy data.
Terms: trees, tree_attributes, planter, planter_registrations, LegacyTree, LegacySession, knexLegacyDB, TREETRACKER_LEGACY_API_URL
Rules:
- A legacy planter whose phone or email equals the session wallet must exist; otherwise the capture upload fails with HTTP 422 'Legacy planter has not been created for the legacy tree'.
- The legacy trees row is idempotent on uuid (the lowercased capture id): an existing row is reused.
- estimated_geometric_location is set with ST_PointFromText('POINT(lon lat)', 4326).
- time_created and time_updated of the legacy tree both take captured_at.
- Legacy rejection sets approved false and active false through the admin API, scoped to /organization/<id>/ when organization_id is given.
- A legacy session id is uuid-by-string(device_identifier + planter_identifier).
Flows:
- Mirror Capture to Legacy Trees (
RawCaptureService.createRawCapture during POST /raw-captures): Builds and writes the legacy trees row for a new capture inside the LegacySession transaction that RawCaptureService opens; its id becomes raw_capture.reference_id. - Backfill Legacy Session Ids (
node database/etl/create-legacy-session-ids.js): One-off script that sets trees.session_id on active legacy trees from the device and planter identifiers. - Backfill Wallet Registrations from Legacy (
database/etl/create-wallet-registration-from-legacy-2.sql (run by an operator)): One-off SQL that creates field_data.wallet_registration rows from legacy planter_registrations, the latest planter photo and session_id in trees, and treetracker.grower_account.
Schema Migrations & Seed Data
Defines and evolves the field data schema with db-migrate (46 up and down SQL files under database/migrations/sqls) and fills development databases with Knex seeds. The domainEvents migrations create the domain_event table, LIST-partitioned by status, with domain_event_sent and domain_event_handled yearly partitions up to 2026; no runtime code under server/ reads or writes these tables. session_segment and the raw_capture root and root_check_processed_at columns also exist only in the schema at this commit.
Terms: db-migrate migration, raw_capture, session, track, wallet_registration, device_configuration, session_segment, domain_event, knex seed
Rules:
- Each migration JavaScript file reads its sqls/<name>-up.sql or -down.sql file and runs it with db.runSql.
- The domain_event tables (domain_event_raised, domain_event_received, domain_event_sent_2021..2026, domain_event_handled_2021..2026) are created by migrations but not written by runtime code.
- In Kubernetes, migrations run as an Argo CD PostSync Job with DATABASE_URL from the database-migration-connection secret; in CI, npm run db-migrate-ci runs them.
- Seeds run in file order 00 to 04 with NODE_ENV development or usertest and DATABASE_URL_SEEDER, and they also write the legacy planter and trees tables.
Flows:
- Apply Schema Migrations (
npm run db-migrate-ci / database-migration-job (Argo CD PostSync)): Runs pending db-migrate migrations against the field data schema in CI, locally, and on each Argo CD sync. - Seed Development Data (
npm run seed-dev / npm run seed-usertest (knex seed:run)): Fills a development or user-test database with device configurations, wallet registrations, sessions and about 13,500 raw captures with matching legacy trees.