moxie/conventions

Code conventions

Naming

  • snake_case for internal variables, functions, and object properties you control.
  • camelCase only where it matches external APIs (AWS, Brightcove, client payloads, etc.).

Colors (mobile / JSON payloads)

Hex colors must be RGB or RGBA. Do not use ARGB — clients adapt as needed.

Errors

  • Use moxie.throw() for structured MoxieError data.
  • Use generate.crash() for shaped error responses where that helper applies.
  • Top-level src/index.ts catches errors and returns API Gateway–compatible output.

Logging

  • Use moxie.log(type, message, body, include_benchmox) — avoid console.log() (Biome / hooks discourage it).

Request context

const { moxie } = global

const request = moxie.request   // method, path, body, querystrings, headers
const identity = moxie.identity // site, path, env, flags, urls, hosts
const settings = moxie.settings // routes, sites, env, caching, specs

Endpoint design

  • Keep index.js thin: orchestration only.
  • Put query validation in config.js via querystrings.options when possible — avoid duplicating the same rules in the handler.
  • Prefer declarative mapping.js over imperative field copying for JSON:API endpoints.

TypeScript

  • Target ES2020, CommonJS, @app./src (see tsconfig.json).
  • Strict mode is off in this repo — still prefer clear types on new TS code where practical.