Configuration
Relevant source files
The following files were used as context for generating this wiki page:
- config/broadcasting.php
- config/database.php
- config/polar.php
- config/sanctum.php
- config/whatsapp.php
- app/Services/TemplateService.php
- resources/views/dashboard/index.blade.php
- resources/views/dashboard/messages.blade.php
- resources/views/dashboard/whatsapp-account.blade.php
- resources/views/layouts/app.blade.php
- resources/views/welcome.blade.php
The qashierwise-be application utilizes Laravel's configuration system to manage application settings. Configuration files are located in the config/ directory and allow developers to set parameters for databases, external services, broadcasting, and authentication. Most configuration values are sourced from environment variables (.env file), enabling different settings for development, staging, and production environments without changing the codebase.
This document outlines the key configuration areas of the application, including WhatsApp integration, subscription management with Polar, database connections, real-time event broadcasting, and API authentication with Sanctum. Understanding these configurations is crucial for setting up, maintaining, and extending the application's functionality.
WhatsApp Service Configuration
The application integrates with the WhatsApp Business API for messaging and profile management. Configuration is managed in config/whatsapp.php and consumed by services like TemplateService.
Sources: config/whatsapp.php, app/Services/TemplateService.php:12-18
Key Parameters
The following table details the environment variables used to configure the WhatsApp service.
| Parameter | Environment Variable | Description |
|---|---|---|
| API Version | WHATSAPP_API_VERSION | The version of the Facebook Graph API to use. Defaults to v22.0. |
| Access Token | WHATSAPP_ACCESS_TOKEN | The access token for authenticating with the WhatsApp Business API. |
| Business Account ID | WHATSAPP_BUSINESS_ACCOUNT_ID | The ID of the WhatsApp Business Account (WABA). |
| Phone Number ID | WHATSAPP_PHONE_NUMBER_ID | The ID of the specific phone number used for sending messages. |
| App ID | WHATSAPP_APP_ID | The Facebook App ID used for Embedded Signup. |
| App Secret | WHATSAPP_APP_SECRET | The Facebook App Secret for server-to-server calls. |
| Verify Token | WHATSAPP_VERIFY_TOKEN | The token used to verify webhook requests from Meta. |
Sources: config/whatsapp.php:5-11
Usage in Services
The TemplateService class is a prime example of how this configuration is used. It initializes its properties from config/whatsapp.php to build the correct API URLs and authenticate requests to the Facebook Graph API.
The diagram below shows how the TemplateService is initialized with WhatsApp credentials.
The whatsapp-account.blade.php view also relies on the WHATSAPP_APP_ID to initialize the Facebook SDK for the Embedded Signup flow, demonstrating how backend configuration directly impacts frontend functionality.
Sources: resources/views/dashboard/whatsapp-account.blade.php:328-333
Subscription & Payment Configuration (Polar)
The application uses Polar.sh for subscription management. The configuration is stored in config/polar.php and is essential for processing payments and managing subscription statuses.
Sources: config/polar.php
Key Parameters
| Parameter | Environment Variable | Description |
|---|---|---|
| Secret Key | POLAR_SECRET_KEY | The secret API key for authenticating with the Polar.sh API. |
| Webhook Secret | POLAR_WEBHOOK_SECRET | The secret used to verify incoming webhooks from Polar.sh. |
Sources: config/polar.php:5-8
Checkout Flow
The frontend initiates the checkout process, which is handled by the backend using the Polar configuration. The pricingSection component in welcome.blade.php calls the /api/subscription/checkout endpoint. The backend then uses the POLAR_SECRET_KEY to create a checkout session with Polar.sh and returns a URL for the user to complete the payment.
This sequence diagram illustrates the checkout process.
Database Configuration
Database settings are defined in config/database.php. The application supports multiple database systems, with the default connection determined by the DB_CONNECTION environment variable.
Sources: config/database.php
Connection Flow
The application reads the DB_CONNECTION variable from the .env file to determine which database driver to use. It then uses the corresponding connection details (host, port, username, password) from the .env file to establish a connection.
The diagram below shows the flow of database configuration resolution.
Supported Drivers
The application is pre-configured to support the following database drivers:
sqlitemysqlpgsql(PostgreSQL)sqlsrv(SQL Server)
The default connection is set to mysql.
Sources: config/database.php:13, config/database.php:35-77
Real-time Event Broadcasting
The application uses event broadcasting for real-time features, such as updating the message view when a new message is received. The configuration is located in config/broadcasting.php, with Pusher set as the default driver.
Sources: config/broadcasting.php
Key Parameters (Pusher)
| Parameter | Environment Variable | Description |
|---|---|---|
| Driver | BROADCAST_DRIVER | The broadcasting driver. Defaults to pusher. |
| Pusher App ID | PUSHER_APP_ID | Your Pusher application ID. |
| Pusher App Key | PUSHER_APP_KEY | Your Pusher application key. |
| Pusher App Secret | PUSHER_APP_SECRET | Your Pusher application secret. |
| Pusher Cluster | PUSHER_APP_CLUSTER | The cluster for your Pusher application. |
Sources: config/broadcasting.php:17, config/broadcasting.php:48-55
Broadcasting Flow
When a server-side event (e.g., a new WhatsApp message is processed) is dispatched, Laravel sends it to the configured broadcast driver (Pusher). The frontend, which has initialized Laravel Echo and connected to Pusher, listens for this event on a specific channel and updates the UI accordingly.
The sequence diagram below illustrates this flow for a new message.
API Authentication (Sanctum)
API authentication is handled by Laravel Sanctum, which provides a lightweight system for issuing API tokens to users. The configuration is managed in config/sanctum.php.
Sources: config/sanctum.php
Key Parameters
| Parameter | Environment Variable | Description |
|---|---|---|
| Expiration | SANCTUM_EXPIRATION | The number of minutes before a token expires. If null, tokens do not expire. |
| Guard | ['web'] | The authentication guards Sanctum will use to authenticate SPA requests. |
| Stateful Domains | SANCTUM_STATEFUL_DOMAINS | Domains that will use cookie-based SPA authentication. |
Sources: config/sanctum.php:23-32
Authenticated API Request Flow
The frontend dashboard pages store the authentication token in localStorage. For every API request to the backend, this token is included in the Authorization header as a Bearer token. The backend uses Sanctum's middleware to validate the token and authenticate the user before processing the request.
This sequence diagram shows a typical authenticated API call from the dashboard.