Onboarding Guide: treetracker-api (TreeTracker API)

Generated from the Understand-Anything knowledge graph. Source commit 85258c8.

Project Overview

The TreeTracker API is a Greenstand Node.js/Express microservice. It exposes a REST API over PostgreSQL (via Knex), validates requests with Joi and express-validator, serves Swagger docs, and exchanges domain events over RabbitMQ (rascal/amqplib). It stores grower and capture images in AWS S3.

The code follows a layered, MVC-like flow: router → handler → service → model → repository → database, with messaging and object storage as side integrations.

Architecture Layers

Key Concepts

Guided Tour

Follow these steps in order to learn the codebase end to end:

  1. Project Overview: Read the README for purpose, architecture, and setup/migration/seeding workflows.
  2. Bootstrap and Express Wiring: server/server.js boots; server/app.js wires middleware, Swagger UI, the router, error handler, and event handlers.
  3. Routing and API Surface: routes/index.js aggregates feature routers; treeRoutes.js is a representative router; swaggerDoc.js assembles the OpenAPI spec.
  4. Request Handlers and Validation: treeHandler/index.js handles tree CRUD/matching/tags; schemas.js (Joi) guards inputs; docs.js supplies Swagger paths.
  5. The Service Layer: TreeService.js orchestrates over one session; HttpError.js carries status + rollback flag.
  6. Domain Models and Repositories: models/tree.js holds domain logic; TreeRepository.js extends BaseRepository.js.
  7. Database Connection and Transactions: knex.js configures the shared connection; Session.js manages the transaction lifecycle.
  8. Database Schema and Seed Data: SQL migrations create the tree table (capture ref, GPS, species, status, geo indexes); seed fixtures make a fresh DB usable.
  9. Asynchronous Messaging: QueueService.js, RabbitMQ.js, EventHandlerService.js, DomainEvent.js implement publish/subscribe over rascal.
  10. Image Upload to S3: s3.js builds the client; S3Service.js exposes uploadImage; GrowerAccountImageService.js uploads + persists in one transaction.
  11. Testing Approach: tree.spec.js exercises endpoints end-to-end; __tests__/utils.js seeds/cleans data and builds PostGIS geometry.
  12. Containerization, CI, and Deployment: Dockerfile (node:16-alpine, node .); PR CI runs lint + migrations + tests against Postgres/RabbitMQ service containers; Kustomize deploys 2 replicas with sealed secrets.

File Map (by layer)

Complexity Hotspots

Approach these areas carefully: they carry the most logic or the largest surface (56 files rated moderate+):


Regenerate with /understand then /understand-onboard. See docs/regenerating.md in the docs repo.