asset_monitoring_app_server

1.65.0 • Public • Published

Asset Monitoring Application Service

This repository contains the source code for the server configuration and setup for the IMI Asset Monitoring Application Server. The server listens on a port 4000.

The Asset Monitoring platform aims to leverage IoT device sensors on IMI's flow control products for near real-time monitoring and predictive maintenance. By shifting from reactive to proactive methods, utilizing sensor data, it provides timely insights and alarms, anticipating system failures and optimizing maintenance schedules. This enhances system efficiency and longevity while ensuring accessible information for all users.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Before we get started, we're going to need to make sure we have a few things installed and available on our machine.

Node >= 18.18.0

Minimum

MacOS
curl "https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p')}.pkg" > "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/"

Other

See the installation guides available @ nodejs.org:

https://nodejs.org/en/download/package-manager/

Docker

Docker installed on your system. If you haven't installed Docker yet, you can download and install it from the official Docker website: https://www.docker.com/get-started

Docker Compose (MacOS)

brew install docker-compose

Starting the local database environment

cd prisma/local && docker-compose up -d

Ensure your container is up and running. List the containers to get the port

docker-compose ps

will log:

NAME          IMAGE                 COMMAND                 SERVICE
xx-database   postgres:13-alpine   "docker-entrypoint.s…"   database   xx minutes ago   Up xx minutes   0.0.0.0:65491->5432/tcp

Check the container's IP address, run:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <NAME>

this will be the HOST value on your DATABASE_URL.

Check the container 's Port number, run:

docker inspect -f '{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{$conf}} {{end}}' <NAME>

this will be the PORT value on your DATABASE_URL.

Add the postgres connection URL to the environment variable DATABASE_URL with the format specified in the .env.example

postgresql://USER:PASSWORD@HOST:PORT/DATABASE

Generate Prisma

npm run db:migrate
npm run db:generate
npm run db:seed
npm run db:studio

Installing

Below is a series of step by step instructions that tell you how to get a development env running.

Create a local clone of the repository

git clone https://imicci@dev.azure.com/imicci/Asset_Monitoring_Project/_git/AM-APP-SERVER

Enter the cloned repositories' directory

cd AM-APP-SERVER

Install the projects dependencies

npm i

Create a .env file based on the .env.example template (at the time of writing, no additional env vars are required)

Export the contents of the created .env file to the current terminal session.

set -o allexport; source .env; set +o allexport

Start the projects development server

npm run start

The project should now be available at http://localhost:4000

Tests

To run the projects unit test simply navigate into the projects root directory.

Then run:

npm run test

The test results should appear in your terminal.

Deployment

Deployments are handled by Azure pipelines, below is an overview of how the deployments work:

  1. Dependencies are installed with npm i
  2. Unit tests are run with npm run test
  3. Application is built npm run build
  4. Static assets are deployed to Amazon S3 and the cloudfront distribution cache is invalidated.

Environment Variables

These are the environment variables required to successfully deploy the application.

Repository Variables

key description
API_BASE_URL Base URL for the API
ENVIRONMENT Environment of the application
PORT Port number for the application
LORIAT_API_KEY API key for LORIAT integration
LORIAT_API_URL URL for LORIAT API
DATABASE_URL URL for the database connection
SSL_CERT_BASE64 Base64 encoded SSL certificate
NO_REPLY_DOMAIN Domain used for no-reply emails
COMMUNICATION_SERVICES_CONNECTION_STRING Connection string for communication services
JWT_SECRET Secret key used to sign and verify JSON Web Tokens (JWT) for user authentication.
REDIS_HOST_NAME Hostname or IP address of the Redis server used for caching and session storage.
REDIS_PORT Port number on which the Redis server is running.
REDIS_ACCESS_KEY Access key or password used to authenticate connections to the Redis server.
REDIS_USERNAME Username for Redis authentication (used in secure environments).
REFRESH_TOKEN_SECRET Secret key for signing and verifying refresh tokens for token renewal.
AZURE_STORAGE_CONNECTION_STRING Connection string for accessing Azure Storage account resources.
AccountKey Primary or secondary key for the Azure Storage account.
EndpointSuffix Custom domain suffix for Azure Storage endpoints (e.g., core.windows.net).
AZURE_STORAGE_ACCOUNT_NAME Name of the Azure Storage account used for storing application data.
AZURE_STORAGE_ACCOUNT_KEY Access key for the Azure Storage account.
MEDIA_CONTAINER_NAME Name of the container in Azure Storage where media files are stored.
BROKER_HOST Hostname or IP address of the message broker used for communication.
MQTT_PORT Port number for connecting to the MQTT broker.
MQTT_USERNAME Username for authenticating with the MQTT broker.
MQTT_PASSWORD Password for authenticating with the MQTT broker.
AUTH0_AUDIENCE Identifier of the API audience configured in Auth0.
AUTH0_ISSUER_BASE_URL Base URL of the Auth0 issuer, typically in the format https://<your-domain>.auth0.com/.
AUTH0_MANAGEMENT_API_CLIENTID Client ID for accessing the Auth0 Management API.
AUTH0_MANAGEMENT_API_CLIENT_SECRET Secret key for accessing the Auth0 Management API.
FRONTEND_DOMAIN URL of the frontend application (used for configuring allowed origins).

Deployment Variables

Each of the below keys need to be applied to each deployment (dev, uat, prod) and their values will be dependant on the environment.

key description
API_BASE_URL Base URL for the API
ENVIRONMENT Environment of the application
PORT Port number for the application
LORIAT_API_KEY API key for LORIAT integration
LORIAT_API_URL URL for LORIAT API
DATABASE_URL URL for the database connection
SSL_CERT_BASE64 Base64 encoded SSL certificate
NO_REPLY_DOMAIN Domain used for no-reply emails
COMMUNICATION_SERVICES_CONNECTION_STRING Connection string for communication services
JWT_SECRET Secret key used to sign and verify JSON Web Tokens (JWT) for user authentication.
REDIS_HOST_NAME Hostname or IP address of the Redis server used for caching and session storage.
REDIS_PORT Port number on which the Redis server is running.
REDIS_ACCESS_KEY Access key or password used to authenticate connections to the Redis server.
REDIS_USERNAME Username for Redis authentication (used in secure environments).
REFRESH_TOKEN_SECRET Secret key for signing and verifying refresh tokens for token renewal.
AZURE_STORAGE_CONNECTION_STRING Connection string for accessing Azure Storage account resources.
AccountKey Primary or secondary key for the Azure Storage account.
EndpointSuffix Custom domain suffix for Azure Storage endpoints (e.g., core.windows.net).
AZURE_STORAGE_ACCOUNT_NAME Name of the Azure Storage account used for storing application data.
AZURE_STORAGE_ACCOUNT_KEY Access key for the Azure Storage account.
MEDIA_CONTAINER_NAME Name of the container in Azure Storage where media files are stored.
BROKER_HOST Hostname or IP address of the message broker used for communication.
MQTT_PORT Port number for connecting to the MQTT broker.
MQTT_USERNAME Username for authenticating with the MQTT broker.
MQTT_PASSWORD Password for authenticating with the MQTT broker.
AUTH0_AUDIENCE Identifier of the API audience configured in Auth0.
AUTH0_ISSUER_BASE_URL Base URL of the Auth0 issuer, typically in the format https://<your-domain>.auth0.com/.
AUTH0_MANAGEMENT_API_CLIENTID Client ID for accessing the Auth0 Management API.
AUTH0_MANAGEMENT_API_CLIENT_SECRET Secret key for accessing the Auth0 Management API.
FRONTEND_DOMAIN URL of the frontend application (used for configuring allowed origins).

Built With

Details of the tech stack that has been used.

Structure

Diagrams

All the diagrams related to this project are in this SRS document

Contributing

Please read CONTRIBUTING.md for details on the SovTech standard for commit messages and the accepted pull request process.

Versioning

We use SemVer for versioning. Versioning occurs automatically in the pipelines using Semantic Release. For the versions available, see the tags on this repository.

TODO: Implement SemVer

Changelog

A running changelog can be found here: CHANGELOG.md

Licenses

Place the result of npx license-checker --summary here

├─ MIT: 457
├─ ISC: 13
├─ Apache-2.0: 7
├─ BSD-3-Clause: 6
├─ BSD-2-Clause: 4
├─ 0BSD: 2
├─ UNLICENSED: 1
├─ CC-BY-4.0: 1
└─ BSD: 1

Troubleshooting

Below are a few common issues users experience - including an overview of their possible cause and solutions.

Meta

Version Author Date
0.0.1 Yatin Badal yatin@sovtech.com 17/03/2020
0.0.2 Daniel Harten daniel@sovtech.com 15/06/2022
0.0.3 Daniel Harten daniel@sovtech.com 31/05/2023
0.0.4 Kuda Mhizha kudakwaishe.mhizha@sovtech.com 24/05/2024
0.0.5 Nicanor Korir nicanor.korir@scrums.com 15/01/2025

Readme

Keywords

none

Package Sidebar

Install

npm i asset_monitoring_app_server

Weekly Downloads

31

Version

1.65.0

License

ISC

Unpacked Size

2.38 MB

Total Files

338

Last publish

Collaborators

  • kouujaa