Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fctl3314/healthnutrition-backend
Django / DRF based app for comparing the nutritional value of products.
https://github.com/fctl3314/healthnutrition-backend
celery crud-api ddd django django-rest-framework docker documentation jwt python
Last synced: about 2 months ago
JSON representation
Django / DRF based app for comparing the nutritional value of products.
- Host: GitHub
- URL: https://github.com/fctl3314/healthnutrition-backend
- Owner: FCTL3314
- License: apache-2.0
- Created: 2023-05-09T10:09:00.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-01-07T11:44:34.000Z (about 1 year ago)
- Last Synced: 2024-01-07T12:24:41.593Z (about 1 year ago)
- Topics: celery, crud-api, ddd, django, django-rest-framework, docker, documentation, jwt, python
- Language: Python
- Homepage: https://fctl3314.github.io/HealthNutrition-Frontend/
- Size: 784 KB
- Stars: 19
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Health Nutrition - Backend
Django / DRF based app for comparing the nutritional value of products.
[![Python](https://img.shields.io/badge/Python-3.11.2-3777A7?style=flat-square)](https://www.python.org/)
[![Django](https://img.shields.io/badge/Django-4.2.1-103E2E?style=flat-square)](https://www.djangoproject.com/)
[![Rest-framework](https://img.shields.io/badge/Rest--framework-3.14.0-7F2D2D?style=flat-square)](https://www.django-rest-framework.org/)
[![Poetry](https://img.shields.io/badge/Poetry-1.5.1-0992E1?style=flat-square)](https://python-poetry.org/)
[![Pytest](https://img.shields.io/badge/Pytest-Passed-2dad3f?style=flat-square)](https://docs.pytest.org/en/7.4.x/)
[![Black](https://img.shields.io/badge/Style-Black-black?style=flat-square)](https://black.readthedocs.io/en/stable/)
# 📖 Table of contents
📃 Description
This Django application provides a **comprehensive API** for **comparing nutritional values of food products**, aiding
users in **making informed dietary decisions**.
This API empowers developers to integrate **nutritional comparison functionality** into various applications, enabling
users to **search for food items**, **explore nutritional categories**, **view detailed product information**, and
ultimately **make health-conscious dietary choices**. It simplifies the process of **comparing nutritional values across
different food items**, enhancing the user's experience with meal planning and supporting them in **achieving their
nutritional goals**.
> [!NOTE]
> #### The project was created for educational purposes, simulating fictitious products without real value.
#### Frontend part: https://github.com/FCTL3314/StoreTracker-Frontend
🌄 Demonstration
### Product categories
### Aminations
![compared-products-deleting](https://github.com/FCTL3314/HealthNutrition-Backend/assets/97694131/5bcd3aac-50cc-4437-ab04-06a9ee23aabc)
![comparison-group-deleting](https://github.com/FCTL3314/HealthNutrition-Backend/assets/97694131/705abcf4-c9e6-44fd-ad0c-7e950140231c)
### Products
### Product detail
![firefox_9HVqv9g46p](https://github.com/FCTL3314/HealthNutrition-Backend/assets/97694131/3dcdead2-64eb-4b22-bb8e-c846958ca437)
![firefox_hrfbO4yzoT](https://github.com/FCTL3314/HealthNutrition-Backend/assets/97694131/81282636-c244-4d6d-97fd-22eecc1e6285)
### Comparison groups
![firefox_TgwCqy76Wf](https://github.com/FCTL3314/HealthNutrition-Backend/assets/97694131/a1a2741f-f6b9-4589-bf52-a236a1532b97)
### Compared products
### Profile
### Settings
![firefox_TwCMDgqiKa](https://github.com/FCTL3314/HealthNutrition-Frontend/assets/97694131/0cb08f01-3266-4942-938b-cf75354d1049)
### Authorization
### Responsive design
🔥 Features
* **RESTful API**
* **Domain Driven Design**
* **CI/CD**
* **Comments reply / Tree structure (Django MPTT)**
* **Custom objects ordering (Like Drag & Drop sort)**
* **Celery / Postponed Tasks**
* **Email Verification**
* **JWT Authentication / Authorization**
* **Code Documentation**
* **Tests (PyTest)**
❕ Peculiarities
### Architecture:
* Project services are divided into 2 levels:
* **Domain** - Services that are in no way dependent on the current infrastructure, that is, the framework.
* **Infrastructure** - Services that can call domain services and interact with the project infrastructure.
### Abbreviations:
* **EV - EmailVerification**
💽 Local installation
1. #### Clone or download the repository.
2. #### Activate the Poetry virtual environment: `poetry shell`
3. #### Install dependencies: `poetry install`
4. #### Create an .env file or rename .env.dist in .env and populate it only with development variables:
![Env-Variables-Example](https://github.com/FCTL3314/StoreTracker-Backend/assets/97694131/c31d86db-7bec-4693-8e97-d649c6e7184f)
5. #### Run docker services for development: `docker-compose -f docker/local/docker-compose.yaml up`
6. #### Apply migrations: `python manage.py makemigrations` and `python manage.py migrate`
7. #### Run the development server: `python manage.py runserver`
🐳 Deployment on a server
### Initial Deployment:
1. #### Clone or download the repository and go to its directory.
2. #### Create an **.env** file or rename **.env.dist** in **.env** and populate it with all variables from **.env.dist** file.
3. #### Create a **nginx.conf** file in the docker/production/nginx/conf.d/ directory and fill it with the code below:
```nginx configuration
upstream core {
server django-gunicorn:8000;
}
server {
listen 80;
server_name example.com www.example.com;
server_tokens off;
client_max_body_size 20M;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /opt/HealthNutrition-Backend/static/;
}
location /media/ {
alias /opt/HealthNutrition-Backend/media/;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot/;
}
location / {
proxy_pass http://core;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
```
#### **Change example.com and www.example.com to your domains.**
4. #### Grant executable rights to the **entrypoint.sh** and *celery_entrypoint.sh* script: `chmod +x docker/production/entrypoint.sh && chmod +x docker/celery_entrypoint.sh`
5. #### Start the services: `docker-compose -f docker/local/docker-compose.yaml -f docker/production/docker-compose.yaml up -d`
### Obtaining an ssl certificate:
1. #### Access nginx container: `docker exec -it bin/sh`
2. #### Get ssl certificate: `certbot --nginx`
3. #### Done ! Now you can exit from nginx container: `exit`
### Configure CI/CD:
1. Generate ssh keys in your local computer: `ssh-keygen -t rsa -b 4096 -C "[email protected]"`
2. Copy the content of your private and public keys to clipboard:
* Linux: Copy the result of commands:
* `cat ~/.ssh/id_rsa`
* `cat ~/.ssh/id_rsa.pub`
* Windows: Copy the contents of the files:
* `C:/users/user/.ssh/id_rsa`
* `C:/users/user/.ssh/id_rsa.pub`
3. Create GitHub repository secrets:
* SSH_HOST: Your remote server host / IP.
* SSH_LOGIN: Your remote server login / username.
* SSH_PORT: Your remote server port.
* SSH_PRIVATE_KEY: Copied SSH private key.
4. Access your remote host and add your public key there:
* Execute `nano ~/.ssh/authorized_keys` and paste your copied public key to the next line.
⚒️ Testing
1. #### Complete all the steps in the 💽 Local installation section
2. #### Run tests: `pytest .`
🪝 Pre-Commit hooks
1. #### Install: `pre-commit install`
2. #### Check: `pre-commit run --all-files`