Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
/ last-mile-delivery Public archive

An (sample) API Implementation of last mile delivery written in Node.js

License

Notifications You must be signed in to change notification settings

empeje/last-mile-delivery

Repository files navigation

Last Mile Delivery API

Build Status Get help on Codementor Made in Indonesia

Live Preview

You can use https://last-mile-delivery.herokuapp.com/ for Live Preview, this instance running on free Dyno hours, so please expect error when our database records limit or hours limit reached.

How to run from source

  • Copy .env.example to .env, this .env file will be used in local for test, and development purposes. For production .env will not be used and system environment variables will be used.
$ cp .env.example .env
  • Edit .env file as needed, here are the most important config to change
PORT=8080 # this is the port we want to expose, if you change this, please look at the `docker-compose.yml` as well
GOOGLE_MAPS_API_KEY= # this is the Google Maps API Key
  • You can run the following script which run our docker-compose setup in detached mode and then attached to the logs so that you'll not stop the app when you detached from the log.
$ ./start.sh

How to run from packaged Docker image

We've prebuild Docker image stored as mappuji/last-mile-delivery in DockerHub. Where you can run it like this

$ docker-compose -f docker-compose.yml -f docker-compose.prod.yml

This run exactly the same thing with running it from source except we use prebuilt image that already pushed to DockerHub.

Design Documentation

The architectural design of the system can be open at empeje.github.io/last-mile-delivery.

Maintaining Documentation

  1. You can maintain the documentation by adding mermaid-js diagram DSL in the docs/index.html

  2. Upload the GitHub pages using

    $ yarn deploy:docs

Development Infrastructure Checklist

Metrics Notes Implemented
Code Quality Standardization and static check using ESLint ✓ Yes
Unit Testing Unit level testing for models ✓ Yes
Integration Testing Integration level testing e.g. API ✓ Yes
End-to-end Testing Blackbox testing, running real service with real ext. service NA
Auto-reload in Dev File watcher that auto reload whenever changes occurs ✓ Yes
Continuous Int. Continuous integration using Travis CI for public repository ✓ Yes

Production Checklist

Metrics Notes Implemented
Codebase One codebase tracked in revision control, many deploys ✓ Yes
Dependencies Explicitly declare and isolate dependencies ✓ Yes
Config Store config in the environment ✓ Yes
Backing services Treat backing services as attached resources ✓ Yes
Build, release, run Strictly separate build and run stages ✓ Yes
Processes Execute the app as one or more stateless processes ✓ Yes
Port binding Export services via port binding ✓ Yes
Concurrency Scale out via the process model ✓ Yes
Disposability Maximize robustness with fast startup and graceful shutdown ✓ Yes
Dev/prod parity Keep development, staging, and production as similar as possible ✓ Yes
Logs Treat logs as event streams ✓ Yes
Admin processes Run admin/management tasks as one-off processes NA

Deployment Using Heroku Docker

Update your Heroku CLI

This meant to update your Heroku CLI to support setting up via heroku manifest setup

$ heroku update beta
$ heroku plugins:install @heroku-cli/plugin-manifest

Create your Heroku app

$ heroku create your-app-name --manifest

Create Clear DB add-ons

$ heroku addons:create cleardb:ignite
# command below will return
# CLEARDB_DATABASE_URL: mysql://<username>:<password>@<url>/<database_name>?reconnect=true
$ heroku config | grep CLEARDB_DATABASE_URL # copy the information to config

# Set database configuration
heroku config:set PORT=8080
heroku config:set LOG_FORMAT=simple
heroku config:set SQL_DATABASE=YOUR_HEROKU_DATABASE
heroku config:set SQL_HOST=YOUR_HEROKU_DATABASE_HOST
heroku config:set SQL_PASSWORD=YOUR_HEROKU_DATABASE_PASSWORD
heroku config:set SQL_USERNAME=YOUR_HEROKU_DATABASE_USERNAME
heroku config:set SQL_DIALECT=mysql
heroku config:set SQL_OPERATOR_ALIASES=false
heroku config:set SQL_SEEDER_STORAGE=sequelize
heroku config:set SQL_SEEDER_STORAGE_TABLE_NAME=SequelizeData
heroku config:set GOOGLE_MAPS_API_KEY=YOUR_GOOGLE_MAPS_API_KEY

Deploy your app

$ git push heroku master