1.0.0 • Published 1 year ago

first-delivery v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

api.tryhabitat.com

This is a monorepo for the main First Delivery API and Dispatch platform, built using Turborepo to manage each application and their shared packages for (types, configs, etc.)

Stack

  • Node 16.5.0
  • Postgres 13
  • Redis
    • needed for socket.io sticky sessions, rate limiting, BullMQ, and application level data caching)
  • BullMQ for worker

Structure

  • /apps - contains the monorepo apps
    • /api - main api (Node, Express, Typescript, Postgres)
    • /dispatch - dispatch app (React, Typescript)
  • /packages - contains shared packages

Requirements

  • Local install of Postgres 13 running on 5432, Redis on 6379, and Node 16+
  • Postgres database w/ these creds and database postgresql://postgres:password@localhost/habitat-dev

Getting started

  1. Clone the repo: git clone https://github.com/Habitat-Food-Fast/api.tryhabitat.com.git
  2. If you're using VSCode, open the project as a workspace (File > Open Workspace From File > Select .vscode/api-monorepo.code-workspace). This will allow VSCode to organize the directories in a way that's intuitive and hides clutter.

The following commands are done at the project root using it's package.json and turbo.json

  1. npm i - our current suppored version for node is 16.5.0, though higher versions may work, may be best to switch to 16.5.0 using nvm
  2. npm run load-local - loads default local .env files in api and dispatch
  3. npm run seed - seeds the db
  4. npm run migrate - gets migrations up to current
  5. npm run dev - compile and run api and dispatch in parallel

Debugging

Dispatch

Dispatch debugging can all be done using Chrome DevTools - React DevTools extension is also useful

API

API debugging is currently all done via VSCode - the /.vscode/launch.json contains various configurations

  • Attach by Process ID - Connect to the development server or worker for live debugging. Note that if you change code, the will stop and you will have to manually restart it
    • node /build/server/worker.js - connect to worker
    • node /build/server/server.js - connect to server
  • Run active Mocha file - Runs the active file in the workspace, useful for debugging a single test
  • Debug API scripts/script.ts - Runs the file apps/api/scripts/script.ts, is a free for all that everyone uses for quick scripting, but prone to being overwritten.

Best Practices

File structure

TODO

Types

TODO

1.0.0

1 year ago