Onboarding Guide: treetracker-field-data

Generated from the Understand-Anything knowledge graph and domain graph. Source commit 8ffb53c. Each claim was checked in the source.

Pull request #119 (merged 2026-10-27, release 1.15.0) removed the RabbitMQ client, the domain event outbox, and the event replay. The service now uses no message broker. The domain_event tables stay in the schema, but no code reads or writes them. The README.md of the source repo still names RabbitMQ: that text is out of date.

Project Overview

The field-data service stores the raw tree tracking data that the Treetracker app uploads (README.md:3). The data has five resources: the raw capture, the session, the track, the device configuration, and the wallet registration. Each new raw capture also goes into the legacy trees table.

How the parts fit:

The API has 16 routes (server/routes/*.js). Only /raw-captures is plural:

In the cluster, the Ambassador Mapping serves the API under the prefix /field-data/ (deployment/base/mapping.yaml:6).

Architecture Layers

The counts are files. The bold names are the layer labels in the graph.

Key Concepts

Guided Tour

The tour has 15 steps. The bold names are the tour titles in the graph.

  1. Process Entry Point
    Files: server/server.js, package.json, server/setup.js
    What to see: the server loads .env.<NODE_ENV> and listens on NODE_PORT or 3006. On SIGINT, it destroys both Knex clients (server/server.js:16).
  2. Express App Assembly
    Files: server/app.js, config/config.js
    What to see: CORS is on only in development (line 18). The 415 check comes before the routers. The error handler comes after them (line 58). A catch-all GET handler comes last (line 62).
  3. Routers and Error Plumbing
    Files: server/routes/index.js, server/routes/rawCaptureRoutes.js, server/utils/utils.js, server/utils/HttpError.js
    What to see: server/routes/index.js exports the five routers as an array. Each route wraps its handler in handlerWrapper.
  4. Handlers and Joi Validation
    Files: server/handlers/rawCaptureHandler/index.js, server/handlers/rawCaptureHandler/schemas.js, server/handlers/sessionHandler/index.js, server/utils/helper.js
    What to see: rawCapturePost deletes extra_attributes from the body. It sets each rotation_matrix value below 0.001 to 0 (lines 45 to 53). Then it validates.
  5. API Documentation Contract
    Files: server/handlers/swaggerDoc.js, server/handlers/rawCaptureHandler/docs.js, docs/api/spec/treetracker-field-data.yaml
    What to see: each docs.js converts its Joi schemas with joi-to-swagger. swaggerDoc.js merges them for /docs.
    Note: rawCaptureHandler/docs.js:77 documents /raw-capture/{raw_capture_id} (singular). The router uses /raw-captures. The YAML spec uses the correct plural path (line 142).
  6. Service Layer
    Files: server/services/RawCaptureService.js, server/services/SessionService.js, server/services/WalletRegistrationService.js, server/services/LegacyAPIService.js
    What to see: each create method begins a transaction, calls the model, and commits. On an error it rolls back and throws again.
  7. Database Sessions and Knex
    Files: server/infra/database/Sessions/BaseSession.js, server/infra/database/Sessions/Session.js, server/infra/database/Sessions/LegacySession.js, server/infra/database/knex.js
    What to see: beginTransaction throws when a transaction is already open (BaseSession.js:19). Only the field-data client gets the DATABASE_SCHEMA search path (knex.js:54).
  8. Domain Models
    Files: server/models/RawCapture.js, server/models/SessionModel.js, server/models/WalletRegistration.js, server/models/DeviceConfiguration.js, server/models/Track.js
    What to see: each model returns frozen objects with Object.freeze. A new raw capture gets the status unprocessed (RawCapture.js:94).
  9. The Legacy Database Bridge
    Files: server/models/LegacyTree.js, server/repositories/Legacy/TreeRepository.js, server/repositories/Legacy/PlanterRepository.js, docs/adr/0001-organization-by-session-bridge.md
    What to see: the legacy tree uses the lowercased raw capture id as its uuid (LegacyTree.js:41). If a legacy tree with the same uuid exists, the model returns that tree and writes no new one (line 63). TreeRepository sets the location with ST_PointFromText and SRID 4326 (line 28).
    Note: the ADR records a manual step. An operator fills session.organization_id. Then the operator sets the organization of the matching legacy trees.
  10. Repositories
    Files: server/repositories/BaseRepository.js, server/repositories/RawCaptureRepository.js, server/repositories/SessionRepository.js
    What to see: BaseRepository.getByFilter accepts nested and and or filters (lines 30 to 81). getById throws 404 when no row matches (line 19).
  11. Field Data Schema
    Files: database/migrations/sqls/20201225201548-createCaptures-up.sql, database/migrations/sqls/20220125153204-session-up.sql, database/migrations/sqls/20220124224437-device-configuration-up.sql, database/migrations/sqls/20220120081019-wallet-registration-up.sql, database/migrations/sqls/20230906143147-create-track-table-up.sql
    What to see: a raw capture gets session_id from 20220126225534-bulk-pack-capture-updates-up.sql:6. A track references a session and stores locations_url.
  12. Migrations and Local Setup
    Files: README.md, database/migrations/20250527074027-add-root-capture-columns.js, database/migrations/sqls/20240722001220-add-session-segment-table-up.sql, database/database.json.example, database/db_init.sql
    What to see: each migration JavaScript file reads its -up.sql or -down.sql file and runs it with db.runSql. The newest migration adds raw_capture.root and root_check_processed_at.
  13. Integration Tests
    Files: __tests__/raw-capture-api.spec.js, __tests__/clear-db.js, __tests__/insert-test-capture.js, __tests__/legacy-table-creation.js
    What to see: Mocha loads every file in __tests__. So the root before hook of legacy-table-creation.js creates trees, tree_attributes, and planter before the specs run. The reject test stubs rejectLegacyTree with sinon (raw-capture-api.spec.js:122).
  14. Container and Kubernetes Deployment
    Files: Dockerfile, deployment/base/kustomization.yaml, deployment/base/deployment.yaml, deployment/base/database-migration-job.yaml
    What to see: the image uses node:16-alpine and runs node .. The Deployment runs 2 replicas on port 3006. The migration Job runs db-migrate up as an Argo CD PostSync hook.
    Note: the overlays set the image tag and the database secrets. The development and test overlays also patch the Mapping with CORS settings. The production overlay does not.
  15. CI/CD Pipelines
    Files: .github/workflows/pull-request-ci.yml, .github/workflows/treetracker-api-build-deploy-dev.yml, .github/workflows/treetracker-api-deploy-prod.yml
    What to see: a pull request to main runs lint, the migrations, and npm test against a postgis/postgis service. A push to main also runs semantic-release, pushes the image, and sets the tag in the development overlay. The release job does not run when the commit message has skip-ci. The workflow commits the overlay change only when the commit message has no chore.
    Note: three manual workflows set a chosen tag in the development, test, or production overlay.

File Map (by layer)

Bootstrap & Configuration

API Layer

Service Layer

Domain Models

Data Access

Shared Utilities

Database Schema & Data

Tests

Infrastructure & CI/CD

Documentation & API Specs

Complexity Hotspots

The graph rates 4 file-level nodes as complex. Three more groups need care. Two have complex logic. One holds stale docs and broken scripts.

Business Domains

domain-graph.json has 6 domains, 21 flows, and 91 steps. The bold names are the flow labels in the graph.

Raw Capture Ingestion: this domain receives, lists, reads, and rejects raw captures.

Session & Track Tracking: this domain stores sessions and the track files of a session.

Device Configuration: this domain stores the phone and app build of a session.

Wallet Registration: this domain stores the grower wallet registrations.

Legacy Database Bridging: this domain keeps the legacy tables in step with the field data.

Schema Migrations & Seed Data: this domain defines the schema and fills development databases.