RezinaLMS-BackEnd/docs/environment-variables-guide.md

24 KiB

LMS external services, API keys, and environment setup

This guide identifies the external infrastructure and third-party APIs used by the Rezina LMS: what each service provides, what you need to provision, and which credentials belong in .env. The environment-variable reference follows the service overview. It reflects the current Go implementation in internal/config/config.go, cmd/main.go, and the integration services. Examples contain placeholders only.

External services required by the LMS

For anonymous course previews, demo learning content, and role-specific test credentials, see Public catalog and demo setup.

For the course → chapter → lesson structure, chapter quizzes, and database rollout, see Learning hierarchy. Apply migration 000003_chapters_and_quizzes before starting the updated backend.

Not every integration is mandatory for every deployment. PostgreSQL and MongoDB support the running backend. AfroMessage and Resend credentials are required by the current startup validation. MinIO, video hosting, conversion, payments, social login, and push notifications are needed when their corresponding LMS features are used.

External service Role in this LMS Requirement What to provision / obtain
PostgreSQL Stores LMS application data, including users, learning content, progress, subscriptions, and payments. Core infrastructure. A PostgreSQL database with the application schema, database user/password, and a reachable connection URL.
MongoDB Stores backend application/activity logs. Initialized during startup; logger initialization failure stops startup. A reachable MongoDB deployment and connection URI, with access to the logging database. Can be self-hosted or managed.
MinIO Object storage for uploaded files and media; supplies signed upload/download URLs. Required for the MinIO-backed file features; optional at startup when disabled. A running MinIO deployment or compatible storage endpoint, bucket, access identity, and secret. This is a storage service you provision, not an API key alone.
AfroMessage Sends SMS messages for backend messaging flows. API key required at startup; working sender configuration required for delivery. Provider account, API bearer token, authorized sender name, and sender identifier if applicable.
Resend Sends email, including team invitations and password reset messages. API key and sender required at startup. Provider account, API key, and an authorized sender email/domain.
Vimeo Hosts and manages learning videos through the backend video integration. Feature dependent. A Vimeo account with API access appropriate to the video operations used by the LMS, and an access token.
CloudConvert Optimizes images and compresses videos. Feature dependent. A CloudConvert account and API key for conversion jobs.
Chapa Processes subscription/payment flows, direct charges, and payment callbacks/webhooks. Required when exposing Chapa payment features. Merchant account, secret key, webhook secret, other keys required by the selected payment flow, and callback/return URLs.
ArifPay Supports direct/legacy payment flows. Required when exposing ArifPay payment features. Merchant API key, API endpoint, beneficiary bank/account information, and notification/outcome URLs.
Google OAuth Allows learners to sign in with Google. Feature dependent. OAuth application credentials: allowed client ID(s), plus client secret and registered redirect URL for the code flow.
Apple Sign In Validates Apple sign-in identity tokens. Feature dependent. Apple application identifiers matching the allowed token audiences, such as the bundle ID or Services ID.
Firebase Cloud Messaging (FCM) Sends push notifications to registered learner devices. Feature dependent. Firebase project and server service-account JSON; client apps must use the corresponding project.

Redis, Kafka, Fixer, SantimPay, and Telebirr have configuration or legacy code, but they are not initialized as active integrations by the current application entrypoint. They are not additional services you need to provision simply to run this backend. See the caveats below before planning to use them.

What to prepare for each service

Database services

For PostgreSQL, provision the database, apply the repository's database migrations/setup, and set DB_URL. For MongoDB, set MONGODB_URL; the logger uses database logdb and collection applogs. These are separate database services with different purposes. Neither requires a third-party SaaS subscription if self-hosted.

MinIO file storage

Provision the storage service before enabling the integration. The backend connects to the object storage API endpoint, such as storage.example.com:9000, rather than the MinIO browser console. Set the following:

MINIO_ENABLED=true
MINIO_ENDPOINT=storage.example.com:9000
MINIO_ROOT_USER=REPLACE_WITH_STORAGE_ACCESS_ID
MINIO_ROOT_PASSWORD=REPLACE_WITH_STORAGE_SECRET
MINIO_BUCKET_NAME=rezina
MINIO_USE_SSL=true

The backend checks for the bucket and creates it when absent. The supplied identity needs permission for the bucket operations used by the application; bucket initialization failure stops startup. Signed URLs are returned to clients, so the configured endpoint must also be reachable by the clients that upload/download files. Set MINIO_USE_SSL to match the endpoint's TLS configuration. The variable names above are what the current backend loads; legacy aliases are listed later.

Communication services: AfroMessage and Resend

Obtain the AfroMessage API token and sender details from the account used to send LMS SMS messages. Configure AFRO_SMS_API_KEY, AFRO_SMS_BASE_URL, AFRO_SMS_SENDER_NAME, and, when applicable, AFRO_SMS_IDENTIFIER_ID.

Obtain a Resend API key and authorized email sender for LMS emails. Configure RESEND_API_KEY and RESEND_SENDER_EMAIL. Invitation and password reset emails also need the frontend page URLs listed in the application-links section below. A valid API key alone does not configure those destinations.

Media services: Vimeo and CloudConvert

Configure VIMEO_ENABLED=true with VIMEO_ACCESS_TOKEN to initialize video hosting. Configure CLOUDCONVERT_ENABLED=true with CLOUDCONVERT_API_KEY to initialize image/video processing. These are separate services from MinIO: MinIO stores objects, Vimeo supplies video hosting, and CloudConvert performs conversion/optimization jobs. The entrypoint leaves Vimeo or CloudConvert disabled if its key is missing, even when its enable flag is set.

Payment providers: Chapa and ArifPay

Prepare merchant credentials for each payment provider whose flows the LMS will expose. Configure the provider API endpoint, authentication keys, and the backend notification/callback URLs. Configure the user-facing success, cancellation, or return URLs separately. The complete variable lists are in the payments section below. The code initializes both Chapa and ArifPay services, but does not validate their credentials during configuration loading; exercise the intended payment flow before treating the integration as ready.

Identity providers and mobile push

For Google sign-in, configure the client IDs accepted by the backend and the OAuth code-flow credentials when that flow is used. For Apple sign-in, configure APPLE_SIGN_IN_CLIENT_IDS; the current backend validates token audiences and does not load an Apple private key.

For push notifications, provide Firebase service-account JSON through FCM_SERVICE_ACCOUNT_KEY_FILE or FCM_SERVICE_ACCOUNT_KEY. This is a server credential containing a private key, rather than the Firebase API key embedded in a mobile/web client. Device registration and a matching Firebase project are also needed for delivery.

Service setup checklist

  1. Provision PostgreSQL and MongoDB, prepare the application database, and supply their connection URLs.
  2. Obtain AfroMessage and Resend credentials and configure sender identities; these are enforced by startup validation.
  3. Provision MinIO and enable it if the deployment needs the backend's object storage features.
  4. Add Vimeo and CloudConvert accounts/keys for the video hosting and media processing features being used.
  5. Add merchant credentials and public callback URLs for the payment providers being exposed.
  6. Add Google/Apple identity configuration and Firebase credentials if social sign-in and push notifications are part of the deployment.
  7. Supply the backend's own settings, including the JWT signing secret and frontend link URLs, using the reference below. These settings are not separate external services.

Loading configuration

The app loads .env from its working directory using godotenv.Load(). Existing process environment variables take precedence. A missing .env is allowed when variables are supplied by the deployment environment. new.env is not loaded automatically.

Required at startup means the configuration loader rejects a missing value. Feature dependent means the value is needed when using that integration, even if the loader accepts an empty value. Successful configuration loading does not verify API credentials.

Required startup settings

Variable Purpose / accepted value
ENV Nonempty environment name. Use development for text logs; other values use JSON logs.
PORT Integer from 1 to 65535, for example 8080.
DB_URL PostgreSQL connection URL, including database credentials. The database must be reachable at startup.
JWT_KEY Secret used to sign HS256 access tokens. Generate a strong random secret for each environment.
ACCESS_EXPIRY Positive integer: access-token lifetime in seconds, for example 3600.
REFRESH_EXPIRY Positive integer: refresh-token lifetime in seconds, for example 604800.
LOG_LEVEL Exactly debug, info, warn, or error.
REPORT_EXPORT_PATH Nonempty report export directory, for example ./exports. Required even though report-worker initialization is currently commented out.
AFRO_SMS_API_KEY AfroMessage API bearer token. Required even if SMS is not being used.
RESEND_API_KEY Resend email API key. Required even if email is not being used.
RESEND_SENDER_EMAIL Sender identity used for outgoing email. Must be nonempty; use a sender authorized for the Resend account.

MONGODB_URL is read separately by the logging layer. Configure a reachable MongoDB URI; cmd/main.go exits if MongoDB logger initialization fails. Logs use database logdb and collection applogs.

Third-party credential checklist

Service Credentials / identifiers to obtain When needed
AfroMessage AFRO_SMS_API_KEY, sender name, and optional sender identifier API key is startup-required; remaining settings support SMS delivery.
Resend RESEND_API_KEY, authorized RESEND_SENDER_EMAIL Startup-required; sends email, including invitations and password resets.
Google OAuth OAuth client ID(s), client secret, registered redirect URL Google sign-in. Client secret and redirect URL support the authorization-code flow.
Apple Sign In Allowed bundle ID / Services ID audience values Apple sign-in token validation; this configuration does not load an Apple private key.
Firebase Cloud Messaging Firebase service-account JSON with private key Push notifications. Use the same Firebase project as the client app.
Vimeo VIMEO_ACCESS_TOKEN Enabled Vimeo video integration.
CloudConvert CLOUDCONVERT_API_KEY Enabled media conversion integration.
MinIO / compatible object storage Access identity and secret, endpoint, bucket Enabled file storage; may be self-hosted.
Chapa Secret API key and webhook secret; public/encryption keys where used Chapa checkout, payment verification, webhooks, and direct charges.
ArifPay ARIFPAY_API_KEY, beneficiary bank/account details ArifPay direct/legacy payment flows.
SantimPay / Telebirr Merchant credentials described below Configuration is present, but no service is initialized for either in the current entrypoint.
Fixer FIXER_API_KEY Legacy currency configuration; initialization is currently commented out.

Keep API tokens, signing keys, database passwords, storage secrets, OAuth client secrets, and Firebase JSON out of committed documentation. Use separate credentials for development and production.

SMS and email

Variable Purpose / default
AFRO_SMS_BASE_URL Base URL used by the current SMS sender, which appends /api/send. Set explicitly, for example https://api.afromessage.com.
AFRO_SMS_SENDER_NAME Sender passed by the current SMS implementation. Set explicitly to the account's sender name.
AFRO_SMS_IDENTIFIER_ID Optional sender identifier, sent as the from parameter.
AFRO_SMS_HOST_URL Separate legacy config field; defaults to https://api.afromessage.com. It does not supply the current sender's AFRO_SMS_BASE_URL.
AFRO_SMS_RECEIVER_PHONE_NUMBER Loaded receiver setting; current SendSMS receives the destination as a method argument.
RESEND_API_KEY, RESEND_SENDER_EMAIL Required email credentials described above.

The loader defaults the top-level SMS sender field to Rezina, but the active SMS sender reads the nested field, which has no such default. Set AFRO_SMS_SENDER_NAME explicitly.

Variable Purpose / default
GOOGLE_OAUTH_CLIENT_ID Google client ID or comma-separated allowed IDs. The first nonempty ID initializes the OAuth code flow.
GOOGLE_OAUTH_WEB_CLIENT_ID Additional Google web client audience accepted during ID-token validation.
GOOGLE_OAUTH_CLIENT_SECRET Secret for Google OAuth authorization-code exchange.
GOOGLE_OAUTH_REDIRECT_URL Redirect URL registered for the Google OAuth application.
APPLE_SIGN_IN_CLIENT_IDS Comma-separated allowed Apple token audiences, such as bundle IDs or Services IDs.
TEAM_INVITE_BASE_URL Frontend invitation acceptance URL; required for invitation generation.
TEAM_PASSWORD_RESET_BASE_URL Team password reset page. If empty, the service attempts to derive it from the invitation URL.
TEAM_INVITE_EXPIRY_HOURS Positive integer hours; defaults to 168, including for invalid input.
LEARNER_APP_BASE_URL Learner application base URL used for notification links. Trailing slashes are trimmed.
LEARNER_WEB_CHECKOUT_BASE_URL Learner web checkout base used when generating subscription checkout links.
PASSWORD_RESET_BASE_URL Loaded password reset URL setting; confirm the relevant flow consumes it before relying on it.
APP_VERSION Optional application version string.

Push notifications

Variable Purpose
FCM_SERVICE_ACCOUNT_KEY Firebase service-account JSON, including its private key. This is JSON credential content, not a Firebase client API key.
FCM_SERVICE_ACCOUNT_KEY_FILE Alternative path to a service-account JSON file. When nonempty, its contents override FCM_SERVICE_ACCOUNT_KEY. An unreadable file fails configuration loading.

Prefer a mounted credential file to embedding multiline JSON in .env. Missing credentials leave push delivery unavailable without making them a required startup setting.

Media and object storage

Variable Purpose / default
VIMEO_ENABLED Enable Vimeo with exactly true or 1; otherwise disabled.
VIMEO_ACCESS_TOKEN Vimeo access token for the integration.
CLOUDCONVERT_ENABLED Enable CloudConvert with exactly true or 1; otherwise disabled.
CLOUDCONVERT_API_KEY CloudConvert API key.
MINIO_ENABLED Enable object storage with exactly true or 1; otherwise disabled. Initialization also requires a nonempty endpoint.
MINIO_ENDPOINT Storage host and optional port, for example localhost:9000; do not include a URL scheme.
MINIO_ROOT_USER Preferred storage access identity; overrides MINIO_ACCESS_KEY when nonempty.
MINIO_ROOT_PASSWORD Preferred storage secret; overrides MINIO_SECRET_KEY when nonempty.
MINIO_BUCKET_NAME Preferred bucket name; overrides MINIO_BUCKET when nonempty. Final default: rezina.
MINIO_ACCESS_KEY, MINIO_SECRET_KEY, MINIO_BUCKET Backward-compatible aliases for the settings above.
MINIO_USE_SSL Enable TLS with exactly true or 1; defaults to false.

When enabled with an endpoint, the app checks/creates the bucket during startup; initialization failures stop the app. MINIO_BROWSER_REDIRECT_URL is not read by this Go backend and belongs to MinIO server/browser configuration.

Payments

Chapa

Variable Purpose / default
CHAPA_SECRET_KEY Secret used to authorize API requests.
CHAPA_WEBHOOK_SECRET Secret for webhook verification.
CHAPA_PUBLIC_KEY Loaded public payment key.
CHAPA_ENCRYPTION_KEY Key used by direct-charge encryption.
CHAPA_BASE_URL Defaults to https://api.chapa.co/v1.
CHAPA_CALLBACK_URL Backend payment callback URL.
CHAPA_RETURN_URL User-facing return URL after payment.
CHAPA_RECEIPT_URL Loaded receipt URL setting.
CHAPA_TRANSFER_TYPE, CHAPA_PAYMENT_TYPE Loaded transfer/payment type settings.

These values are not required by the configuration loader. Supply the credentials and URLs needed by the Chapa flows you expose. Callback URLs should target the deployed backend; return URLs should target the intended client page.

ArifPay

Variable Purpose
ARIFPAY_API_KEY, ARIFPAY_BASE_URL Provider API credentials and endpoint.
ARIFPAY_CANCEL_URL, ARIFPAY_ERROR_URL, ARIFPAY_SUCCESS_URL User-facing payment outcome URLs.
ARIFPAY_C2B_NOTIFY_URL, ARIFPAY_B2C_NOTIFY_URL Backend notification URLs for the respective flows.
ARIFPAY_BANK, ARIFPAY_BENEFICIARY_ACCOUNT_NUMBER Beneficiary bank and account.
ARIFPAY_DESCRIPTION, ARIFPAY_ITEM_NAME Payment description and item label.

The loader sets quantity to 1, language to EN, expiry to a date three hours ahead, and payment methods in code; these are not environment variables.

SantimPay and Telebirr configuration caveats

The loader reads SANTIMPAY_SECRET_KEY, SANTIMPAY_MERCHANT_ID, SANTIMPAY_BASE_URL, SANTIMPAY_NOTIFY_URL, and SANTIMPAY_CANCEL_URL. Although the struct has a success URL field, no corresponding environment variable is loaded.

It also reads TELEBIRR_BASE_URL, TELEBIRR_APP_SECRET, TELEBIRR_FABRIC_APP_ID, TELEBIRR_MERCHANT_CODE, and TELEBIRR_CALLBACK_URL. Current implementation issue: TELEBIRR_FABRIC_APP_ID overwrites the app-secret field instead of populating the fabric-app-ID field. Setting both variables cannot fix this; code changes are needed before relying on this configuration.

Neither provider has a service initialized in the current cmd/main.go; obtaining their keys alone does not enable payments.

Database pool and auxiliary infrastructure

Variable Purpose / default
DB_MAX_CONNS Maximum PostgreSQL pool connections; 25.
DB_MIN_CONNS Minimum PostgreSQL pool connections; 5.
DB_MAX_CONN_LIFETIME_MINUTES Connection lifetime in minutes; 30.
DB_MAX_CONN_IDLE_MINUTES Idle lifetime in minutes; 5.
DB_HEALTH_CHECK_SECONDS Health check interval in seconds; 30.
REDIS_ADDR Loaded Redis address; no Redis client is initialized by the current entrypoint.
KAFKA_BROKERS Comma-separated broker addresses; producer initialization is currently commented out.
FIXER_API_KEY, FIXER_BASE_URL, BASE_CURRENCY Loaded currency settings; exchange-rate initialization is currently commented out.

Pool settings fall back to defaults for missing, nonnumeric, or nonpositive values. Keep minimum connections no greater than maximum connections.

Background workers

Variable Default Purpose
ACCOUNT_DELETION_PURGE_ENABLED true Purge accounts due for permanent deletion.
ACCOUNT_DELETION_PURGE_INTERVAL 1h Purge interval.
ACCOUNT_DELETION_PURGE_BATCH_SIZE 100 Batch size; capped at 1000.
PAYMENT_EXPIRY_WORKER_ENABLED true Expire overdue payments.
PAYMENT_EXPIRY_WORKER_INTERVAL 15m Payment expiry scan interval.
SUBSCRIPTION_EXPIRY_REMINDER_WORKER_ENABLED true Send subscription expiry reminders.
SUBSCRIPTION_EXPIRY_REMINDER_WORKER_INTERVAL 24h Reminder scan interval.
INACTIVE_SUBMODULE_CONTENT_PURGE_ENABLED false Permanently purge inactive submodule content after retention.
INACTIVE_SUBMODULE_CONTENT_PURGE_INTERVAL 24h Content purge interval.
INACTIVE_SUBMODULE_CONTENT_RETENTION_DAYS 30 Positive integer retention period in days.

For worker switches, empty values use the defaults above; explicit true or 1 enables them, and other nonempty values disable them. Intervals use Go duration syntax such as 30m, 1h, or 24h; invalid or nonpositive durations fall back to defaults. Invalid batch sizes and retention periods also fall back to defaults.

Complete configuration example

See .env.example for all currently loaded settings, optional integrations, legacy configuration, and demo-seed settings. It uses the repository Docker database ports for a backend running on the host. Replace credential placeholders before starting the app. Your existing .env is not overwritten.

Minimal configuration example

This example covers startup configuration and the currently used SMS fields. Replace placeholders, prepare the PostgreSQL schema, and provide reachable databases before starting the app. It does not enable payments, social login, storage, or push notifications.

ENV=development
PORT=8080
DB_URL=postgres://USER:PASSWORD@localhost:5432/rezina?sslmode=disable
MONGODB_URL=mongodb://localhost:27017
JWT_KEY=REPLACE_WITH_A_STRONG_RANDOM_SECRET
ACCESS_EXPIRY=3600
REFRESH_EXPIRY=604800
LOG_LEVEL=info
REPORT_EXPORT_PATH=./exports

AFRO_SMS_API_KEY=REPLACE_WITH_AFROMESSAGE_TOKEN
AFRO_SMS_BASE_URL=https://api.afromessage.com
AFRO_SMS_SENDER_NAME=REPLACE_WITH_AUTHORIZED_SENDER
RESEND_API_KEY=REPLACE_WITH_RESEND_API_KEY
RESEND_SENDER_EMAIL=REPLACE_WITH_AUTHORIZED_EMAIL

VIMEO_ENABLED=false
CLOUDCONVERT_ENABLED=false
MINIO_ENABLED=false

Legacy names and configuration limits

  • TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, and TWILIO_SENDER_PHONE_NUMBER appear in new.env but are not read by the current Go backend. SMS uses AfroMessage.
  • ARIFPAY_NOTIFY_URL is not loaded; use the separate ARIFPAY_C2B_NOTIFY_URL and ARIFPAY_B2C_NOTIFY_URL names.
  • SANTIMPAY_Base_URL in new.env differs from the loader's SANTIMPAY_BASE_URL. Use the exact uppercase spelling for portable deployments.
  • DBResetReseedEnabled, DBResetReseedToken, and DBSeedDir are assigned directly in code (true, empty token, and db/data). No environment variables control those fields in the current loader.
  • Commented-out provider configuration in config.go is not active configuration and does not require API keys.

Source references