The French version of this README is available here: README_FR.md.
Follow the official documentation, or simply run:
pip install pre-commit
Then, in the project's root directory (13_empreinte_souffrance), install the pre-commit hooks:
pre-commit install
Pyenv is a tool that allows you to manage multiple Python versions easily.
For more information, visit pyenv.
You can then select the Python version you want to use with the following commands:
pyenv install 3.13
pyenv global 3.13
Follow one of the several installation methods that are described in uv's documentation.
Navigate to the backend directory and run:
uv sync --all-groups
This will create a .venv virtual environment in the backend folder.
To ensure your IDE automatically uses the virtual environment and finds the project dependencies, you need to configure it.
Open the command palette (Ctrl/Cmd + Shift + P), search for Python: Select Interpreter, then choose Enter interpreter path and type:
For Windows:
backend/.venv/Scripts/Python.exe
For macOS and Linux:
backend/.venv/bin/python
Go to Settings, then Python Interpreter, click on Add Interpreter, select Existing venv, and choose uv, then specify the path to the Python executable in .venv:
For Windows:
backend/.venv/Scripts/Python.exe
For macOS and Linux:
backend/.venv/bin/python
If you have configured your IDE, your shell should automatically use the virtual environment, allowing you to run commands that depend on it like this:
pytest
pre-commit run --all-files
If this is not the case, or if you encounter an issue, you can use uv run to execute a command (if you are in the backend directory).
uv run your_command
Some examples used in this project:
uv run pytest
uv run pre-commit run --all-files
uv run pre-commit run --all-files
Follow the official documentation here.
Navigate to the backend directory and run:
task translations-compile
If you add new translatable strings to the project, use:
task translations-all
to generate and update translations.
If you're on Windows, you must run these commands in a Git Bash.
Navigate to the backend directory and run:
task tests
Navigate to the backend directory and run:
uv run pytest
Navigate to the backend directory and run:
task run-server
Example: http://127.0.0.1:8000/off/v1/knowledge-panel/1?lang=fr
The backend/ directory contains the main implementation of the backend application.
app/api/: Defines API endpoints.app/api/open_food_facts/: Defines the API that interacts with OFF.- In the future, there will also be a directory for our site's API.
app/business/: Handles business logic (*).app/config/: Contains configuration files.app/locales/: Manages localization and translations.app/models/: Defines data models.
The business and models directories should follow the same structure as the API directory. So, if you add business logic for the OFF API, it should go in app/business/open_food_facts. The same applies to models.
If there is shared business logic (e.g., a score calculator), it can be placed in app/business/common, for example.
(*) Business logic represents all the rules, processing, and calculations specific to the application's functional domain. It defines how data is manipulated and decisions are made to meet user needs, independently of the interface or data storage.
The tests/ directory contains unit tests to ensure project stability.
The directory structure mirrors that of the backend. Example: If you're testing a route from backend/app/api/open_food_facts/routes.py, your test should be placed in:
tests/app/api/open_food_facts/test_routes.py
Test files should start with test_, and test function names should also start with test_ to be detected by pytest.
The scripts/ directory contains various utility scripts for the project.
This project uses uv to manage dependencies (pyproject.toml and uv.lock).
Taskfile.yml: Defines automated tasks (e.g., running the server or generating translations).tox.ini: Configuration for running tests with Tox..pre-commit-config.yaml: Configuration for pre-commit hooks.