Onboarding Guide: images-api (Greenstand Images API)

Generated from the Understand-Anything knowledge graph. Source commit 9d761d1.

Project Overview

The images-api is a Greenstand Node.js/Express microservice. It exposes a RESTful image resize API: it fetches a remote source image over HTTP, validates resize parameters with Joi, and applies transforms with the Sharp image library. The service follows a layered, MVC-like structure (protocol, service, and model layers). It ships a Knex/PostgreSQL persistence scaffold for future stateful features, but the current image-resize flow is stateless.

The request flow is: router → handler → service → (Sharp/Joi) → HTTP response, with a shared utility layer for async wrapping and centralized error handling.

Architecture Layers

Key Concepts

Guided Tour

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

  1. Application Bootstrap: server/server.js loads environment config, sets the log level via server/setup.js, imports the Express app, and listens on the configured port.
  2. The Express App Factory: server/app.js wires CORS, JSON body parsing, a content-type guard, the image-resize router, and a single global error handler. Highest fan-out file.
  3. Routing and Request Dispatch: server/routes.js maps the image-resize GET routes to their handlers, each wrapped in the async error handler.
  4. Image-Resize Handlers: server/handlers/resizeImageHandler.js reads and validates request parameters, then streams the resized image back through the service.
  5. The Service Layer: Sharp and Joi: server/services/ResizeImageService.js fetches the remote image, validates params with Joi, and applies Sharp transforms.
  6. Cross-Cutting Utilities and Error Handling: server/utils/utils.js (async wrapper + global error middleware), server/utils/HttpError.js (shared error type), server/utils/helper.js (pagination/query parsing).
  7. The Data Layer: Knex and Postgres: server/repositories/BaseRepository.js, server/database/Session.js, server/database/knex.js, and knexfile.js provide the persistence scaffold.
  8. The API Contract: docs/api/spec/images-api.yaml defines the two public GET endpoints; read it alongside the handlers from Step 4.
  9. Testing Strategy: server/app.spec.js (unit: 415 on non-JSON POST, 200 on GET /), api-tests/image-resize-api.spec.js (integration, mocking Axios), api-tests/lib/supertest.js (shared HTTP client).
  10. Project Manifest and Environment: package.json (entry point, scripts, dependencies), .env.development.example (Postgres URLs + upstream API), README.md (architecture overview).
  11. Containerization: Dockerfile (single-stage node:16-alpine, npm ci, node .) and .dockerignore.
  12. Kubernetes Deployment: deployment/base/* Kustomize manifests: namespace, Deployment (one replica), Service, and an Ambassador Mapping that routes external /images/ traffic in.
  13. CI/CD Pipelines: treetracker-api-pull-request-ci.yml (lint + integration tests on PR) and treetracker-api-build-deploy-dev.yml (semantic-release, build/push image, update dev overlay on push to main).

File Map (by layer)

Complexity Hotspots

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


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