This is a starter repository for the recipes webapp project of CompSci 235 in Semester 2, 2025.
This repository contains a partial implementation of the domain model. It contains unit tests which can be run through pytest. It also contains a simple Flask application that renders content of a Recipe object instance from our domain model on a blank HTML page. You'll be expanding the domain model implementation, and you have the freedom to add, modify or remove test cases as needed.
Installation via requirements.txt
Windows
$ cd <project directory>
$ py -3 -m venv venv
$ venv\Scripts\activate
$ pip install -r requirements.txtMacOS
$ cd <project directory>
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txtWhen using PyCharm, set the virtual environment using 'File or PyCharm'->'Settings' and select your project from the left menu. Select 'Project Interpreter', click on the gearwheel button and select 'Add Interpreter'. Click the 'Existing environment' radio button to select the virtual environment.
Running the application
From the project directory, and within the activated virtual environment (see venv\Scripts\activate above):
$ flask runAfter you have configured pytest as the testing tool for PyCharm (File - Settings - Tools - Python Integrated Tools - Testing), you can then run tests from within PyCharm by right-clicking the tests folder and selecting "Run pytest in tests".
Alternatively, from a terminal in the root folder of the project, you can also call 'python -m pytest tests' to run all the tests. PyCharm also provides a built-in terminal, which uses the configured virtual environment.
The project directory/.env file contains variable settings. They are set with appropriate values.
FLASK_APP: Entry point of the application (should always bewsgi.py).FLASK_ENV: The environment in which to run the application (eitherdevelopmentorproduction).SECRET_KEY: Secret key used to encrypt session data.TESTING: Set to False for running the application. Overridden and set to True automatically when testing the application.WTF_CSRF_SECRET_KEY: Secret key used by the WTForm library.
The data files are modified excerpts downloaded from:
https://www.kaggle.com/datasets/irkaal/foodcom-recipes-and-reviews/
Display: The browse page shows a Health Star Rating (HSR) for each recipe. If nutrition data is missing, it shows “Health star rating unavailable.”
Computation (per serving):
HSR [0.0, 5.0]
HSR = clamp( 5.0 − (sugar/10 + satFat/5 + sodium/600 + calories/400, capped at 3.5)
+ (fiber/5 + protein/20, capped at 1.5) )
Then round to 1 decimal.
Rationale (brief):
-
We subtract negative nutrients (sugar, saturated fat, sodium, calories) and add positive ones (fibre, protein).
-
We cap total negatives at 3.5 and positives at 1.5 to avoid extreme values .
-
Clamp = bound the final result to [0.0, 5.0].
The app supports two repository modes:
REPOSITORY=memory(default): in-memory repo populated from CSV (A1/A2).REPOSITORY=database: createsrecipes.db(SQLite) on first run and populates it fromrecipe/adapters/data/recipes.csv.
python -m venv .venv
source .venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
export REPOSITORY=database
export SQLALCHEMY_DATABASE_URI=sqlite:///recipes.db
flask run