- This Project for scraping Hotels rate per night and store there history for rate comparing
- Every day, there is an ingestion service that runs at 1AM EST. for whole hotel rate from today to next year ( Using Cron Job and Queue )
- There is a Dashboard has Line Chart and Paginated Table to Show the Changes in rate for every hotel for specified date
- I have assumed That Hotel Scraping has no relation to the number of customers exists
#How ot works
- Scrape Hotels data every day at 1 AM EST using Laravel Scheduler
- Dispatch Job to create a Queue for number of hotels per Queue pre-defined ( Currently Defined By 2 For Testing Purpose )
- After Fetch The Data I Have Created 2 Tables to handle this in most cases I can merge this 2 tables if not needed :
- hotel_stay_rates
- hotel_stay_rates_histories
- The Reason of creating 2 tables to make DB faster while at normal case we will communicate with hotel_stay_rates to get the latest rate for the hotel instead of search at from application start date and protect from table and column lock for any reason
- When we fetch data it updates the rates or create if not exist at hotel_stay_rates table then clone all updates using one query to hotel_stay_rates_histories ( In Queue )
- Then we can search for all related history for single date of stay using foreign_key (old_uuid) could be renamed to parent_id and get the history for this Hotel
- I decided to keep hotel name instead of passing the hotel id to reduce joining between tables while we are handle a big dataset
- Docker
- Docker Compose
- The SSH keys set for your GitHub account
- OrbStack recommend for Mac users
- if you are using Docker Desktop for Linux, you should execute the following command. If you are not using Docker Desktop for Linux, you may skip this step:
docker context use default1- Go to the cloned directory:
cd bi-tool2- Clone Env Config
cp .env.example .env3- if you have Composer installed with PHP 8.2 you can just run
composer installOr you run this command to install the composer dependencies using small docker image
docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd):/var/www/html" \
-w /var/www/html \
laravelsail/php82-composer:latest \
composer install --ignore-platform-reqs4- run this command to use sail command:
alias sail='[ -f sail ] && sh sail || sh vendor/bin/sail'5- this will build all needed containers:
sail build --no-cache6- this will create and start the containers:
sail up -d7- run this command to setup the seeders and all needed migrations to your system
make setup##Dashboard
While my main stack is laravel is used Filament php Dashboard to support with simple FE side
you can access it using
http://localhost/adminDefault Users
##Api I have made sample for api you can download it from postman folder at repo
https://api.postman.com/collections/2661015-3e508dd2-f7d6-439c-828b-5b059bdd7e4d?access_key=PMAT-01HDD9X5F33PK8FCA3X72AYTZM##Structure All application files will be under app folder we have the following
-
Console
- Contains Custom Commands to be called like php artisan ScrapeHotelsCommand
- Contains Kernel that where we can configure schedules and import the commands
-
Data - it contains Data Classes
- Data classes are used to return well-structured data for a payload.
- Data classes are very useful to transfer data between the system components in a maintainable way
-
DTOs
- DTO (Data Transfer Object) is a simple utility and a small component that can be used to transfer data between the outside world to the inside world of either the Domain or the Module.
-
Exception - Here where we create our custom exceptions
-
Handlers - Used to make an action without need any feedback delete action for example or run a statement
-
Http
- Controllers ( Contains the controllers that use to handle outside requests and the presentation of data and communicating with routes,services to make the request )
- Middleware ( Convenient mechanism for inspecting and filtering HTTP requests entering the application like how we use it at Auth )
- Requests ( Where we create the expected requests and define their rules )
- Kernel ( The place where we define the middlewares )
-
Jobs - Here we create the jobs needed to be dispatched in the Queues.
-
Models - Contains all of your Eloquent model classes
-
Presenters
- Instead of outputting all the model fields and their loaded relationship,
- We can basically format that to an agreed structure that will output only the needed data and also rename fields
- To be more convenient than the original names in models or datasets
- We use AbstractPresenter to make Presenter support both Collection or single item
-
Providers - Service providers are the central place to configure the application
-
Repositories - provides an abstraction layer between the application logic and the data persistence layer
- We can say this is a middle man the handle the communication between Services and the Models
-
Services - Services are the basic classes to run logic.
-
Database
- Migration - Migrations are like version control for your database, allowing your team to modify and share the application's database schema
- Factories - define database records in a predictable and easily replicable way
- Seeders - the ability to seed your database with data using seed classes
-
Routes - The route is a way of creating a request URL for your application
- Setting Server Timezone to EST
- Install Cron Job
- Initialize Scheduler ( That schedule for laravel use cronjob )
- Installing PHP 8.2 CLI With PHP Extensions
- Install Composer
- Install Node
- Install MySql Client
- Copy php.ini ( Has php configurations ) and supervisord.conf ( Described Below ) to image
The main purpose of using Supervisord that make sure that process never die and all programs assigned always alive like:
- [program:php] run the php service at port 80
- [program:cron] run the cron job
- [program:laravel-worker] run laravel worker for Queue system
you can find more about it
https://filamentphp.com/docsI Have installed telescope for tracing and debugging purpose you can reach it using
http://localhost/telescopeYou Can See My Expalnation using loom link below https://www.loom.com/share/ae46f01413cb46e5870aa3c8e655f19a
This is a sample to produce the technical abilities please don't hasitate to ask me if there is any info needed