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: 3 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 (almost 2 years 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.
[](https://www.python.org/)
[](https://www.djangoproject.com/)
[](https://www.django-rest-framework.org/)
[](https://python-poetry.org/)
[](https://docs.pytest.org/en/7.4.x/)
[](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


### Products
### Product detail


### Comparison groups

### Compared products
### Profile
### Settings

### 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:

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`