Full Back End REST microservice for the management of a back office panel and front end website for a e-commerce platform.
The project is developed in PHP with the Laravel 12 framework and is designed to be used in conjunction with the Front End and Back office webapplications and communicate with each other through REST API. The code features a image conversion system, caching and compression of data, and a log management system.
It also integrates a translation service using google translate API for the back office and a docker system to run the application without having to install dependencies locally or to run the application in a production environment.
|
|
- Install DB and dependencies
- Console commands
- Branch rules and structure
- CI/CD Github actions
- Docker
- Image Conversion
- Caching Data
- Log Management
- Image Conversion
composer install / update
php artisan migrate / migrate:fresh // add :fresh if the db and tables already exist
php artisan db:seed
php artisan storage:link
php artisan serve
php artisan test
php artisan cache:clear
php artisan route:clear
php artisan route:cache
php artisan down
php artisan up
The project is integrated with GitHub Actions for CI/CD. The pipeline is triggered on every push to the deploy_prod/deploy_test branch. The pipeline includes the following steps:
- Version and changelog extraction: The version and changelog are extracted from the package.json file to be used in the release process.
- Replace .env file: The .env file is replaced with the .env.production or .env.test file based on the branch.
- Test: The project is tested using the test script.
- Deploy: The modified build is deployed to the production/test branch.
- Github release: The project is released on GitHub using the release script and tagged with version numbers.
The deployment process is automated through scripts that can be used via artisan commands.
Start the production pipeline on GitHub Actions.
php artisan deploy prod
Start the test pipeline on GitHub Actions.
php artisan deploy test
The project uses docker to run the application and perform other operations without having to install the necessary dependencies locally. The script generates several instances:
- Apache
- PHP (PROJECT) (VOLUME COMPOSER)
- MYSQL WITH PERSISTENCE (DB volume)
Start the project with docker on windows environments
php artisan docker:{mode}
Start the project with docker on linux environments
php artisan docker:{mode}
- development
- test
- prod
The back office uses the text translation service offered by Google Cloud.
The service is Cloud translate API (Cloud translation - BASIC)
It has a limit of 500,000 characters per month and has a maximum number of characters per request.
The service uses an API KEY for authentication, which is saved in the .env.production and env.test files in the root of the project.
The backoffice converts all incoming images that are not . svg or already in this format to the . webp format.
The compression/quality ratio is configured and editable in app/utils/ConvertImageUtils.php
The Back End applies the following middleware to all answers that it returns:
CacheResponse
Search in the cache for the response, if it does not find it, compress with zlib and insert it. Resists cached response if present before running other middleware
CompressResponse
Compresses the response in gzip format
CacheControl
Apply a 6-hour eTag with code 304 (the cache is kept on the client until it expires)
The cache is enabled in a production environment and is selectively reset based on the modified entities. can be deactivated with the parameter CACHE_ENABLE in the file . env/.env.test/.env.production*.
Logs are split into files daily and are maintained for a defined number of days (5-7 days) The configuration of logs, maintenance times and more is present in the file /config/logging.php
Structure of LOG folders:
fe_config
- Log front end configurationentity
- Log entities- ``products` - product logs, basket and scheduler elimination
- โfaqโโ
- ```etc... (same logic)`
- โcacheโ`s - Log caching and compression response
- ``security` - Log security and login
search
- Log ricerca
The images are processed by the ConvertImageUtils controller which performs several steps:
- Conversion of images to .webp (excluding svg)
- Resizing images within the maximum dimensions
- Application of watermark with the logo on images
The settings for these processes are in the .env files (.env.test, .env.production) present in the root of the repository or the application on plesk The values are modifiable directly from modifying the .env file.
-
processImageForEntity: Manages processes on the image based on the entity. Apply resizing, thumbnail creation, and adding watermark based on the entity.
-
processSingleImage: Handles uploading, saving and converting images to the. webp format (excluding .svg or .webp images).
-
resizeImage: Resize images to the maximum size provided in the env while maintaining the aspect ratio and only acting if the image exceeds the defined size.
-
createThumbnail: Generate thumbnails from the original image, resizing it to the defined measurements while maintaining the aspect ratio.
-
applyWatermark: Apply the logo as a watermark on product images, bottom right with maximum width and height measurements.
The properties of the file . env are as follows:
Property | Description |
---|---|
IMAGE_COMPRESSION_RATIO |
Defines the level of compression for images converted to WebP format(Default = 75). |
BANNER_IMAGE_MAX_WIDTH |
Maximum width value per image banner home page |
BANNER_IMAGE_MAX_HEIGHT |
Maximum height value per image banner home page |
SHOWPAGE_IMAGE_MAX_WIDTH |
Maximum width per image page of trade fairs. |
SHOWPAGE_IMAGE_MAX_HEIGHT |
Maximum height per image page of trade fairs. |
IMAGE_MAX_WIDTH |
Maximum width value for general resize. |
IMAGE_MAX_HEIGHT |
Maximum height value for general resize. |
CONTACTS_THUMBNAIL_WIDTH |
Maximum width value for thumbnails contacts. |
CONTACTS_THUMBNAIL_HEIGHT |
Maximum height value for thumbnails contacts. |
FAIRS_IMAGE_MAX_WIDTH |
Maximum width value for fair images. |
FAIRS_IMAGE_MAX_HEIGHT |
Maximum height value for fair images. |
FAIRS_THUMBNAIL_LOGO_WIDTH |
Maximum width value for trade fair thumbnails. |
FAIRS_THUMBNAIL_LOGO_HEIGHT |
Maximum height value for trade fair thumbnails. |
FAIRS_THUMBNAIL_IMAGE_WIDTH |
Maximum width value for trade fair thumbnails. |
FAIRS_THUMBNAIL_IMAGE_HEIGHT |
Maximum height value for trade fair thumbnails. |
PRODUCTS_IMAGE_MAX_WIDTH |
Maximum width value for product images. |
PRODUCTS_IMAGE_MAX_HEIGHT |
Maximum width value for product images. |
PRODUCTS_THUMBNAIL_WIDTH |
Maximum high value for product thumbnails. |
PRODUCTS_THUMBNAIL_HEIGHT |
Maximum width value for thumbnails product images. |
WATERMARK_ENABLE |
Enables or impedes watermark application. |
WATERMARK_WIDTH |
Defines the value of the watermark width (px or %) (Default = 10%). |
WATERMARK_HEIGHT |
Defines the watermark height value (px or %) (Default = 10%). |