andreafspeziale / motorway-challenge

πŸš— Motorway simulation challenge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Motorway challenge

The challenge can be found in the docs folder.

Notes:

  • No authentication in place (OAuth 2.0 standard using grant_type=client_credentials would be a good fit)
  • Drivers will always prefer the shortest path to go from A to B (using Dijkstra algorithm)
  • One Device per Driver
  • Fixed cost per Km
  • The BillModule which computes the cost of the travels for a specific user in a specific period is integreted in the same server. It would be better to have it as a standalone application which can be separately deployed, eventually scheduled and horizontally scaled

Migration network sample

network

The following data is available at t0 in order to play with Postman as suggested in the next sections:

  • DeviceId: e3ab8c16-78ef-47db-8e4f-d0173126ffe0
  • NodeAId: 6cacc7e2-7f71-4240-a4d0-dddb189338df
  • NodeBId: 76310119-0623-41e8-bb88-4a4e1597ce03
  • NodeCId: 1f8642d8-7252-431d-b209-87ff535c692a
  • NodeDId: d43d0c98-9f68-4809-be85-2c36f7517aa3

ER diagram

er-diagram

Out of the Box

Requirements

Quickstart

$ docker compose -f docker-compose.runner.yml up
  • Add -d to start all containers in detached mode (you won't see any logs).
  • Add --build to rebuild the Docker image used by the docker compose.

Visit http://localhost:3000/swagger for APIs documentation (host and port according to environment variables).

In order to run also the tests without having Node.Js on your local machine:

$ docker compose -f docker-compose.tester.yml up

Postman

Once the server is running, play with the APIs using Postman. All you have to do is:

Hope you have fun!

Development

Requirements

Quickstart

$ npm install
$ cp env/.env.development .env
$ docker compose up --remove-orphans
$ npm run start:dev
  • --remove-orphans will eventually remove orphan containers created during the "Out of the Box" section

In order to create a new migration:

$ npx typeorm migration:create -n MigrationName -d src/migrations/development

Test

$ docker compose -f docker-compose.test.yml up --remove-orphans
$ npm run test

Environment variables

Environment

  • NODE_ENV

Required: true
Description: node environment.
Values: [development, production, test]

Server

  • HOST

Required: false
Description: domain name of the network host or its IP address.

  • PORT

Required: true
Description: port number to connect to.

Logger

  • LOGGER_LEVEL

Required: true
Description: console logger level.
Values: [silent, error, warn, info, http, verbose, debug]

  • LOGGER_PRETTY

Required: false
Description: boolean to enable/disable logs formatting.

  • LOGGER_REDACT

Required: false
Description: string of keys separated by comma that hold sensitive data to hide in the log output.

Database

  • DB_HOST

Required: true
Description: domain name of the database host or its IP address.

  • DB_PORT

Required: true
Description: port number to connect to the database.

  • DB_DATABASE

Required: true
Description: database name.

  • DB_SCHEMA

Required: false
Default: public
Description: database schema.

  • DB_MIGRATIONS_FOLDER

Required: true
Description: migration folder name.

  • DB_USERNAME

Required: true
Description: database username.

  • DB_SSL_ENABLED

Required: true
Description: database SSL connection.

  • DB_PASSWORD

Required: only when DB_SSL_ENABLED is false
Description: database password.

  • DB_SSL_CA

Required: only when DB_SSL_ENABLED is true
Description: database SSL ca.

  • DB_SSL_CERT

Required: only when DB_SSL_ENABLED is true
Description: database SSL cert.

  • DB_SSL_KEY

Required: only when DB_SSL_ENABLED is true
Description: database SSL key.

About

πŸš— Motorway simulation challenge


Languages

Language:TypeScript 97.6%Language:JavaScript 1.7%Language:Dockerfile 0.5%Language:Shell 0.1%