Skip to content

yisrael35/rest_imj

Repository files navigation

Management events system

About the project

This project was built for The Israel Museum, Jerusalem.
The technology stack:

For the DB I used MySQL Link
For the FrontEnd I used React with Redux and Material UI Link
For the BackEnd I used REST-API and WebSocket (NodeJS) - current repository
For the deployment I used AWS-EC2 Link
For the documentation I used wiki.js Link
To menage all the project I used Monday and Git
The project goal is to build a Management events system for IMJ.

IMJ Server Architecture

General documentation on the structure of the IMJ project

Required files to run the project

  1. .env - required variables in ./_env
  2. db structure and data - ./sql/structure/imj_db.mwb || ./sql/migration/last_dump.sql

Client API

Production: https://www.yisraelbar.xyz Local: http://localhost:3000

Server API

Production:

  1. Rest: https://rest-api.yisraelbar.xyz
  2. WebSocket: wss://ws-api.yisraelbar.xyz

Local:

  1. Rest: http://localhost:3001
  2. WebSocket: ws://localhost:3020

Docker

Run the project - Simply by running the commend: docker-compose up Stop the project: docker-compose down --rmi all

LOGIN

To make any request REST / WS you will have to get a token from here There 3 types of Tokens:

  1. Platform - used for all the requests (valid for 1d)
  2. Login -(NOTE - NOT available yet) used for 2FA, after you enter username and password another validation is required: email/sms (valid for 20m)
  3. Reset Password - (valid for 20m)

Payload token for example:

{
  "user": { "id": 1, "level": 1 },
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiY295NWR5d0gyM0dQdHpjaFB2ZGs2Y0ZpWGVqenlXcmNBQUJqWVN0SWMzWT0iLCJhbGdvcml0aG0iOiJIUzI1NiIsImlhdCI6MTY0ODE1OTIxNSwiZXhwIjoxNjQ4MjQ1NjE1fQ.EwRKw_6WVGcpU6n2SSMyAawUz0YPVmWDB6xZcScqSbM"
}

The token been created with

DB

Configurations & Connectivity

The project works with db in mysql, where the db name is: imj_db When the project starts to run he tries to init db connections from .env file The values:

DB_HOST = localhost
DB_USERNAME = root
DB_PASSWORD = password
DB_NAME = imj_db

DB - helper

All call's to db (execution of sql queries) done by db_helper file ./utils/db_helper For example:

const product = await db_helper.get(query.get_product_by_id(product_id))

SQL

migration

contains queries to update the dbs

structure

contains DB structure: imj_db

queries

contains all queries to mysql db

Channels

WS

All about the WS in the project you will find in our ws-documentation wiki-ws

Sessions

After the connection to the WS a unique session will be created in order to identity the connection and handle all of his requests. Session example:

{ user: { id: 1, level: 1 }, authenticate: true }

REST

All the rest is this project are been declare in index.js and the implementation is in the ./api/ folder, The available EndPoints:

  1. auth
  2. bid
  3. client
  4. cost
  5. csv
  6. event
  7. event_type
  8. forgot_password
  9. location
  10. pdf
  11. schedule_event
  12. supplier
  13. user
  14. utils

Each EndPoint divide to three parts:

  1. auth.routes.js
  2. auth.controller.js
  3. auth.service.js

More info in our Wiki

Worker

Some of the tasks in the project are highly consuming cpu usage and in order to not block the Node main loop - we created workers for those tasks. The task that using a worker: csv - in order to create a csv files for different tables in the db/ and client display

Helper File

We using ./utils/helper.js in order to validate phone number/ emails/ passwords etc' using regex.

RabbitMQ - QUEUES

We using Rabbit-MQ in order to handle our loges in the project. We using a single connection in order to connect to the queues, each queue use ./utils/message_broker.js that's produce (DP - Singleton) object of the queue For more info about RabbitMQ click here The queue path in the project: ./utils/log_queue.js

Files (assets)

The Folder ./files/ is contain all the files that user will upload or create(csv/pdf) while he used the website, in order to download the files the client side need to call to follow path: http://example.com/assets/file_name.pdf

For example:

http://localhost:3001/assets/csv_1648217122426.csv

Cron Jobs

It runs a job/task periodically on a given schedule in our server, and one of the benefit of this is that we able change the task or replace it without stopping the server. Our cron job is: ./cron_job/clean_files.js and every night in: 00:00 it delete all the files that created during the day. (in order to clean the server from unused files)

Messaging

SMS

The sms in our project is in use to for 2FA, sms path in the project: ./utils/send_sms.js We using twilio package to send the sms. sms-twilio

email

The emails in our project is used for forgot password/ send files/ 2FA The package that we used: sendgrid/mail

Document generation

csv

We using csv files in order to produce reports and db tables data. The package that we used: csv-writer

pdf

We using the following package in order to create FDP files for bids. The package that we used: pdfkit

👀 All rights reserved to Yisrael Bar
🌱 How to reach me:
My Linkedin
If you want to see more of my projects:
My GitHub

Created by: Yisrael Bar

About

Backend of imj

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published