A simple toy system for the 2023 exam of the course PA1417 Basic System Verification at BTH. It currently consists of a backend implemented in Flask and is connected to a MongoDB database. A frontend is anticipated according to the requirements, but not yet implemented.
This repository is structured as follows:
- backend: Directory containing the backend
- src: Source code of the backend
- test: Location for all test files
- .env: Environment variables
- Dockerfile: Definition of a docker image
- main.py: Main starting point of the backend, to be started with
python -m main
- pytest.ini: Pytest configuration
- requirements.txt: Libraries required by the backend, to be installed via
pip install -r requirements.txt
- documentation: Markdown-files containing the context and requirements specification.
- context-specification.md: The context of the system, describing why the system needs to be achieved.
- requirements-specification.md: The requirements of the system, describing what needs to be achieved.
While not essential for the PA1417 exam, you can setup and run the system to familiarize yourself with its functionality.
To set up the system, you have two choices: you can either run the system locally or run the dockerized version.
Make sure that Python 3.10 and MongoDB are available on your system. Then, perform the following steps for preparation:
- Make sure that the data base path data\db exists in the root folder of this repository.
- Install the requirementens in the backend folder by running
python -m pip install -r requirements.txt
.
Finally, get the system running with the following commands (each executed in its own shell):
- To start the data base, run
mongod --port 27017 --dbpath data\db
from the root folder in a console with admin rights (make sure that the direction of the slashes matches your operating system). - To start the the server, run
python -m main
from the backend folder.
Make sure that Docker is available on your system. Then, perform the following steps:
- With Docker Desktop running, execute
docker-compose up
from the root folder in a console with admin rights.
Once the system is running, you can interact with it for example using Postman. Verify that the system is running by executing GET http://localhost:5000/
which should return a heartbeat in the form of a version string { "version" : "v0.5.0" }
.
The database stores pantry items, which you can view via GET http://localhost:5000/items/all
. At the beginning, the database is empty and this REST call should return an empty array []
. Populate the database by running POST http://localhost:5000/populate
, which will take the dummy data and adds them to the database. Now, GET http://localhost:5000/items/all
should list several items. You can create further items via POST http://localhost:5000/items/create
, where the body must contain the name, quantity, and unit field.
Finally, you can explore the main functionality of the system by running GET http://localhost:5000/receipes
(containing the diet and usage_mode fields in the body as specified in the method description), which generates a random receipe. For example, calling the aforementioned request with diet = normal
and usage_mode = optimal
should - if the populate function had been run - return a receipe for banana bread, while changing diet = vegan
should return a receipe for whole grain bread.
You can retrace the database by connecting to it using MongoDB Compass. Connect on the url mongodb://localhost:27017/
(if you are using a local setup) or mongodb://root:root@localhost:27017/
(if you are using a dockerized setup). In the tinychef database, you will find the item collection, where all the items are stored.