.env file for configuration, which is automatically loaded at startup using godotenv/autoload. Copy backend/.env.example to backend/.env and configure the values for your environment.
Core Configuration
Application environment mode. Used to determine the MongoDB database name (
{APP_ENV}-backend) and control environment-specific behavior.Common values:development- Local developmentstaging- Staging environmentproduction- Production environment
EnvIsProd() helper function checks if this equals "production".Port number for the HTTP server to listen on.Example:
8080Database Configuration
MongoDB connection string. Can be a local MongoDB instance or a cloud provider like MongoDB Atlas.Examples:
- Local:
mongodb://localhost:27017 - Atlas:
mongodb+srv://username:[email protected]/
Redis connection string for caching and session storage.Example:
redis://localhost:6379While defined in the configuration, Redis integration may require additional implementation for session management.
Security
Secret key used for session management and signing. Should be a long, random string.Generate a secure key:
Payment Integration (Paypack)
Client ID for Paypack payment gateway integration. Required if using mobile money payment features.Used for authenticating with the Paypack API at
https://payments.paypack.rw/api/auth/agents/authorize.Client secret for Paypack payment gateway. Required if using Paypack features.Enables functionality:
- Cash-in (collecting payments)
- Cash-out (disbursements)
- Transaction status polling
Email Integration (Plunk)
API key for Plunk email service (https://useplunk.com). Despite the name suggesting a boolean, this should contain your Plunk API key.Used by the
SendEmailWithPlunk() function to send transactional emails.Notifications (Telegram)
Telegram bot token for sending notifications. Obtain from @BotFather on Telegram.Format:
123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11Telegram chat ID where the bot should send messages. Can be a user ID, group ID, or channel ID.Used by the
SendTelegramMessage() function for real-time notifications and alerts.Example Configuration
Here’s a complete example.env file for local development:
Accessing Environment Variables
Environment variables are accessed through helper functions inbackend/configs/env.go:
Security Best Practices
- Never commit the
.envfile to version control - Use different values for each environment (development, staging, production)
- Rotate secrets regularly, especially SESSION_KEY and API credentials
- Use environment-specific API keys (test keys for development, production keys for production)
- Restrict access to production environment variables
- Use a secrets management service in production (AWS Secrets Manager, HashiCorp Vault, etc.)