The PTSafe backend is created in order to support the main functionalities that are covered in the PTSafe mobile application (can be found here in PTSafe mobile). It consists of two main backend framework developed on top of Flask and NodeJS, and it is connected to the data source Amazon Web Services (AWS) RDS. While the Flask API is utilised to expose the crowd detection model, the NodeJS-Express API is utilised to expose the main data source for the application. To support the deployment process, both backend APIs are served in Heroku link Platform-as-a-service (PaaS) hosting service.
The back-end part of the application is established by using a NodeJS API framework called ExpressJS. It is expected at this point that all API endpoint creation is generated by using a functional programming paradigm rather than Object-Oriented Principle (OOP) to speed up the development process.
Second, the NodeJS API is built by strictly following the Model-View-Controller approach (although the View part is changed by Routes). By implementing this approach, the data sources are mapped first in a form of models, and all the JSON responses generated are mapped into each model’s parameter. After that, the logical part of the application is implemented inside controllers, which each controller calls each respective models for each API endpoint. After that, the controllers are registered inside several API routes, and it will be eventually exposed to the public in a form of URL.
Meanwhile, the main back-end API is also built by following the SOLID design principle, particularly the single responsibility principle. It is reflected on the current software architecture code that implements different controller classes for different types of API endpoints.
The object detection back-end is built with a python API framework called Flask. To create this back-end, the functional programming paradigm is also utilised, which takes the computer vision model generated by the AI division and exposed it in a form of API endpoints. There is no specific software architecture principle being involved in this back-end, as currently it only has one specific endpoint to receive the image from the mobile application and feed it into the model.
- dotenv (v16.0.0)
- body-parser (v1.19.2)
- cors (v2.8.5)
- nodemon (v2.0.15)
- mysql2 (v2.3.3)
- uuid (v8.3.2)
- tensorflow-cpu (v2.8.0)
- pillow (v9.0.1)
- numpy (v1.22.3)
- gunicorn (v20.0.4)
- urllib3 (v1.26.9)
- flask (v2.0.3)
- werkzeug (v2.0.3)
Endpoint | Request Method | Request param | Request body | functionalities |
---|---|---|---|---|
https://ptsafe-backend.herokuapp.com/v1/credential/findByUserNameAndPassword | GET | username,password | none | To login as administrator if necessary (will be enabled prior to the expo) |
https://ptsafe-backend.herokuapp.com/v1/news/findAll | GET | none | none | Get all tech and crime news |
https://ptsafe-backend.herokuapp.com/v1/news/findByNewsLabel | GET | newslabel | none | Get all news based on a news label |
https://ptsafe-backend.herokuapp.com/v1/credential/findByUserNameAndPassword | GET | username,password | none | To login as administrator if necessary (will be enabled prior to the expo) |
https://ptsafe-backend.herokuapp.com/v1/news/create | POST | none | newstitle, newslabel, newscontent, imageurl, newsurl | Create a new news |
https://ptsafe-backend.herokuapp.com/v1/comment/create | POST | none | newsid, commenttitle, commentcontent | Create a new comment for a specific news |
https://ptsafe-backend.herokuapp.com/v1/comment/findByNewsId | GET | newsid | none | Get comments for a specific news id |
https://ptsafe-object-detection-api.herokuapp.com/v1/predict | POST | none | file (.jpg, .png) | Get prediction of how many people in the picture |
Some steps are required to run this application locally on your computer machine:
- Install NPM package here
- Install NodeJS [here] (https://nodejs.org/en/)
- Fork this repository to your local machine
- Navigate to the nodejs folder
- Create a .env file with all credentials being put inside. For further details about the credentials can contact the developers in charge on building this API.
- Run
npm install
- Run this code to install all dependencies
npm install cors nodemon body-parser express mysql2 dotenv uuid
Some required steps are as follows (assumed you already have your python):
- run
python3 -m pip install --upgrade pip
to upgrade the pip package installer - Install Flask
- Navigate to the flask folder and run the app.py
- master (will be merged with the iteration-1 branch after Industry Mentors meeting)
- iteration-1 (with subbranches under this main branch)