laravelAssesment

laravel assesment eConceptual

Stars
0
Committers
2

Assumption

  • You are running scheduler when you start the project which creates entry of reliance stock in database.

Prerequisites

  • PHP 8.0 or higher
  • Composer
  • Redis
  • MySQL (via XAMPP or standalone)
  • Node.js and npm
  • Rapid API KEY

Generate API Key

  1. Go to (rapidapi.com)[https://rapidapi.com/]
  2. Sign up with google or other sign up options.
  3. Go inside finance section.
    image
  4. Select Real time finance data.
  5. Click on subscribe to test and select the plan.I am selecting free basic which has 100 requests hard limit.
    image
  6. After Selecting you will get back to previous screen and you will be able to see your key and test endpoint option.
    Screenshot 2024-07-18 121409
  7. Now go to .env and paste it there with key X_RapidAPI_Key.

Installation Steps

  1. Clone the repository
git clone https://github.com/Mukkawar-Shlok/laravelAssesment.git
  1. Environment Configuration
    • Copy .env.example to .env.
    • Update .env with your database, Redis configurations and Rapid Api Key.
  2. Install PHP dependencies
    composer install
    
  3. Install Node.js dependencies
    npm install
    
  4. Run database migrations
    php artisan migrate
    

Running the Application

  1. Start the Laravel development server
    php artisan serve
    
  2. In a separate terminal, run the scheduler
    php artisan schedule:work
    

Routes

Method URI Description
GET / Returns the landing page of Laravel to check if Laravel is running correctly.
GET /reliance/price Fetches data directly from the database (for testing database functionality).
GET /reliance/redis/price Retrieves Reliance stock price from Redis cache if available, otherwise from the database.
GET /reliance_stock/history/{interval} Returns historical stock data based on specified parameters.
GET /reliance_stock/history/{interval} Returns historical stock data based on specified parameters.
GET /clear_redis_cache Clears the Redis cache.

Notes on /reliance_stock/history/{interval}

Notes on /reliance_stock/history/{interval}

  • {interval}: Required parameter. Valid values are:
  • 1D - 1 day
  • 5D - 5 days
  • 1M - 1 month
  • 3M - 3 month
  • 6M - 6 months
  • YTD - year-to-date
  • 1Y - 1 year
  • 2Y - 2 years
  • 5Y - 5 years
  • 10Y - 10 years
  • MAX - all times

This endpoint attempts to retrieve data in the following order:

  1. From Redis cache (if available)
  2. From the database (if not in cache)
  3. From the external API (if not in database)

Additional Notes

  • This project doesn't utilize Vue.js or React, so the Node.js dependencies are optional.
  • Make sure to configure your database settings in the .env file before running migrations.
  • For any issues or questions, please open an issue in the GitHub repository.

Deployment On Forge with AWS EC2

Step 1: Sign Up and Connect to GitHub

  1. Sign up for an account on Forge.
  2. Connect your Forge account with GitHub. Authorize GitHub to connect with your repository.
    Connect with GitHub

Step 2: Select Service Provider

  1. Select your service provider (e.g., AWS).
    image
  2. Follow the instructions for AWS EC2 settings. For other providers, refer to the documentation.

Step 3: Set Up AWS IAM User

  1. Go to the IAM dashboard of AWS.
    image
  2. Create a new user for this project.
    image
  3. Assign necessary policies: AmazonEC2FullAccess and AmazonVPCFullAccess. Create a group with these policies or attach them directly to the user.
    image
  4. Create access keys for connecting to Forge.
    image
  5. Select third-party services and store the access key and secret key.
    image
  6. Paste the keys into Forge.
    image

Step 4: Create and Configure Server

  1. Start a free trial or subscribe to a package.
  2. Create a new server and select AWS.
    image
  3. Fill in the details: CPU, RAM, Region, PHP version, MySQL version, Server OS, Database Name, etc.
  4. Copy server credentials: Sudo password and Database Password.
  5. Check the EC2 instance for the new server.
  6. Wait for status checks to turn green (usually two status checks).
  7. Add security group to the instance.
    image
  8. Add inbound rules as shown in the documentation.
    image
  9. Get your system's IP address:
    • For Windows:
      nslookup -type=TXT o-o.myaddr.l.google.com ns1.google.com
      
    • For Mac:
      dig -4 TXT +short o-o.myaddr.l.google.com @nsl.google.com
      
  10. Update the security group with the new security group.
  11. Forge will install dependencies required to run the Laravel project.

Step 5: Deploy Your Application

  1. Access the server address to see the Forge landing page.
    image
  2. Install the application:
    image
  3. Connect to your Git repository:
    • Paste the repository link.
    • Select the branch of the repository.
    • Enable "Install Composer dependencies."
      image
  4. Set up CI/CD pipeline:
    • Enable quick deploy to deploy your application automatically on new commits.
      image
  5. Access your application through the server IP.
  6. Success! Your Laravel application is now deployed.

Setting enviorment on forge

You can add your enviorment inside enviorment tab of your server on forge but as most of the services like MySql, Redis comes with it you don't need to add remote redis or database but if your requirement says otherwise you can always go there and change it. image

Checking logs of laravel on forge

you can go into logs tab to check the logs and errors of the server. image

Related Projects