This is the back end of Puppy monitoring application. It is responsible for managing the database, monitoring websites and computing statistics and alerts.
Learn more in PUPPY.md
Table of Contents:
- Launch the back in development environment
- Api documentation
- Architecture of the back end
The back run on two docker containers (see docker-compose.yml file):
- The MongoDB database container
- The Node.js server container
To run the back:
- Install Docker and Docker Compose, if it is not already done
- Install Node.js, if it is not already done
- Make sure the ports 27017 (for the database) and 8080 (for the server) are available on your computer
- Open a terminal at the back folder
- Run
npm install
to install dependencies - Run
docker-compose up
to lauch the back
Warning: The docker-compose up
command is replaced by docker-compose.exe up
You can use Docker for Windows on Windows 10 Profesionnal or Enterprise 64-bit. For the other versions, you can use Docker Toolbox.
There is an api documentation generated by apiDocjs. To generate the apidoc:
- Open a terminal at the back folder
- If apidoc is not already installed, run
npm install apidoc -g
to install it globally - Run
apidoc -i src/ -o apidoc/
to generate the documentation in folder apidoc - Open
apidoc/index.html
in a Web browser to see the generated api documentation
This back end uses Node.js and the module Express for the server and the routes. The database is in MongoDB. Mongoose is the ORM used in order to communicate with the database.
index.js is the file that docker run when it starts the back. Appart from index.js, everything happens in the folder src/.
Routes and socket are set up in src/app.js file.
The Mongoose schemas can be found in the file src/database/schemas.js. The connection with the MongoDB database is set in src/database/database.js The various model entities are set up in src/database/database.js
Every entity is managed in its own folder (for exemple src/website/ for websites). In almost all these folders, there is: -The entityController.js file, which implements the functions that communicate with the database -The entityRouter.js file, which creates the routes for the api
Periodically repeated tasks (e.g.: website ping, statistics computing, alert sending) are handled by Managers. These objects manage Node.js intervals, which are timers that call a function periodically. The Managers are responsible for creating and cleaning intervals.
There are request related functions (handling error, validating parameters, ...) in src/misc/ folder.