# Application Services
This section describes all application services CEX uses. We also note that all these services are described on the Official Laravel Documentation (opens new window) page as well.
# 1. Redis
We use Redis to interact with Websocket and Event Broadcaster, which will be described right after this section. If you don't have Redis installed locally, you can check this tutorial (opens new window) to install it.
# 2. Websockets
As you may know, in many modern web applications, WebSockets are used to implement realtime, live-updating user interfaces. When some data is updated on the server, a message is typically sent over a WebSocket connection to be handled by the client. WebSockets provide a more efficient alternative to continually polling your application's server for data changes that should be reflected in your UI.
We use powerful Soketi (UWebSocket) package written in C++ to handle server realtime data updates and retrieve them to the user interface. It just delivers message from the server to client in 6 milliseconds of internal latency, which is pretty fast.
- Install the package globally
apt install -y git python3 gcc build-essential
npm install -g @soketi/soketi
soketi start
By default, this will start a server at 127.0.0.1:6001 with the following application credentials:
App ID: app-id
App Key: app-key
Secret: app-secret
The credentials are used to authenticate your frontend and backend applications in order to be able to send messages and receive them in real time.
When you move to production, you have to change variables in .env file.
PUSHER_HOST="yourdomain_for_socket" # e.g. socket.yourdomain.com
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_ID=app-id #secure random string
PUSHER_APP_KEY=app-key #secure random string
PUSHER_APP_SECRET=app-secret #secure random string
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_HOST="${PUSHER_HOST}"
MIX_PUSHER_SCHEME="${PUSHER_SCHEME}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MIX_PUSHER_PORT="${PUSHER_PORT}"
After, you need to run it as a supervisor command.
For more information, you can visit official documentation (opens new window) of Soketi package
# 3. Queue Service
Thankfully, Laravel allows you to easily create queued jobs that may be processed in the background. By moving time-intensive tasks to a queue, your application can respond to web requests with blazing speed and provide a better user experience.
You need to launch the command php artisan horizon
and keep it running. Alternatively, you can use Supervisor to handle the jobs. See Official Laravel Documentation (opens new window)
# 4. Cron Scheduler
Laravel's scheduler command offers a fresh approach to managing scheduled tasks on your server. The scheduler allows you to fluently and expressively define your command schedule within your Laravel application itself.
You need to launch the command php artisan schedule:work
and keep it running. Alternatively, you can use open crontab
command and add the following line:
* * * * * cd PATH_TO_YOUR_PROJECT && php artisan schedule:run >> /dev/null 2>&1
# 5. Google and X OAuth Keys Setup
Step 1: Set up a Google Cloud project https://console.cloud.google.com
Visit the Google Cloud console and log in with your Google account.
Click on the “Select a Project” dropdown in the top navigation bar. In the popup, click on “New Project” to create a new project and provide the requested details. Then click on Create project.
Once you create the project, open the console’s left side menu and select APIs & Services > Credentials.
On the Credentials page, click Create Credentials > OAuth Client ID.
If this is your first time creating a client ID, it will ask you to configure the consent screen. You can configure your consent screen by clicking Configure Consent Screen. If you have already configured the consent screen, you can skip this step.
- Select External if your app is for public use, or Internal if it’s limited to users within your Google Workspace organization.
Fill out the required details, like the app name, user support email, and any branding information. Click Save and Continue.
After configuring the consent screen, return to the Credentials page and select OAuth Client ID again.
Choose the Application Type as Web Application and provide a name for client credentials (for example, My CEX Platform Login).
Under Authorized Redirect URIs, add the callback URL for your application: Example: https://YOURDOMAIN-URL/login/google/callback
Click on Create, and Google will generate a Client ID and Client Secret for your project. Save these credentials, as they will be required in the next steps.
Set Keys in .env file
GOOGLE_CLIENT_ID=''
GOOGLE_CLIENT_SECRET=''
GOOGLE_REDIRECT_URI=https://YOURDOMAIN-URL/login/google/callback
Step 2: Set up X (ex Twitter)
First we need to create Twitter App and get ID and Secret. So, let's follow bellow steps as well:
Go to Twitter Developer App to click here: https://developer.twitter.com/en/portal/projects-and-apps
Create a project and get API Keys
Set Keys in .env file
TWITTER_CLIENT_API_KEY=''
TWITTER_CLIENT_API_SECRET_KEY=''
TWITTER_CALLBACK_URL=https://YOURDOMAIN-URL/auth/twitter/callback