Skip to content

Environment Configuration Guide for iDrv5-MyFR8

The iDrv5-MyFR8 application now uses a centralized configuration system that loads settings from environment files.

The iDrv5-MyFR8 application now uses a centralized configuration system that loads settings from environment files. This provides a single source of truth for database connections and other application settings.

Used for local development and testing.

Used for production deployments.

The application uses a single DATABASE_URL environment variable for all database connections. This eliminates the need for hardcoded database URLs throughout the codebase.

  1. Copy the development template:

    Terminal window
    cp .env.dev .env.dev.local
  2. Update the DATABASE_URL in .env.dev:

    DATABASE_URL=postgresql://postgres:YOUR_PASSWORD@YOUR_HOST:5432/YOUR_DATABASE
  3. Run the application:

    Terminal window
    FLASK_ENV=development python main.py
  1. Create production environment file:

    Terminal window
    cp .env.example .env
  2. Update the DATABASE_URL in .env:

    FLASK_ENV=production
    FLASK_DEBUG=False
    DATABASE_URL=postgresql://myfr8_user:your_secure_password@localhost:5432/idrv5_myfr8
    SESSION_SECRET=your_super_secure_session_secret_here_minimum_32_characters
    JWT_SECRET_KEY=your_jwt_secret_key_here_minimum_32_characters
  3. Run the application:

    Terminal window
    FLASK_ENV=production python main.py

The utils/config.py file contains a centralized configuration class that:

  • Automatically loads the appropriate environment file based on FLASK_ENV
  • Validates required configuration variables
  • Provides type-safe access to configuration values
  • Handles database connection parameters
from utils.config import config
# Access database URL
database_url = config.database_url
# Access other settings
app_name = config.system_name
debug_mode = config.flask_debug
  • DATABASE_URL: PostgreSQL connection string
  • SESSION_SECRET: Secret key for session management
  • JWT_SECRET_KEY: Secret key for JWT tokens
  • FLASK_ENV: Environment mode (development/production)
  • FLASK_DEBUG: Debug mode (True/False)
  • SYSTEM_NAME: Application name
  • COMPANY_NAME: Company name
  • SERVER_NAME: Server domain name
  • PREFERRED_URL_SCHEME: URL scheme (http/https)
  • UPLOAD_FOLDER: File upload directory
DATABASE_URL=postgresql://postgres:password@localhost:5432/idrv5_myfr8
DATABASE_URL=postgresql://username:password@your-rds-endpoint.amazonaws.com:5432/database_name
DATABASE_URL=postgresql://myfr8_user:password@db:5432/idrv5_myfr8
Terminal window
# For development
export FLASK_ENV=development
python main.py
# For production
export FLASK_ENV=production
python main.py

The system automatically selects:

  • .env.dev for development
  • .env for production
  1. Never commit environment files containing real credentials to version control
  2. Use strong, unique secrets for production deployments
  3. Regularly rotate secrets in production
  4. Use SSL/TLS for database connections in production
  1. “DATABASE_URL not configured”

    • Ensure the appropriate environment file exists
    • Check that DATABASE_URL is set in the environment file
  2. “Missing required environment variables”

    • Verify all required variables are present in the environment file
  3. Database connection errors

    • Check database server is running
    • Verify connection parameters are correct
    • Ensure database user has proper permissions

Enable debug logging to see which environment file is being loaded:

import logging
logging.basicConfig(level=logging.DEBUG)

The new system replaces hardcoded database URLs in:

  • models/database.py
  • utils/database.py
  • utils/database_context.py
  • API files

All database connections now use the centralized configuration system.

FLASK_ENV=development
FLASK_DEBUG=True
DATABASE_URL=postgresql://postgres:dev_password@localhost:5432/idrv5_dev
SESSION_SECRET=dev_session_secret_32_characters_min
JWT_SECRET_KEY=dev_jwt_secret_32_characters_min
SYSTEM_NAME=iDrv5-MyFR8
COMPANY_NAME=MyFR8 Logistics
FLASK_ENV=production
FLASK_DEBUG=False
DATABASE_URL=postgresql://myfr8_user:secure_prod_password@prod-db.example.com:5432/idrv5_myfr8
SESSION_SECRET=super_secure_session_secret_64_characters_minimum_for_production
JWT_SECRET_KEY=super_secure_jwt_secret_64_characters_minimum_for_production
SYSTEM_NAME=iDrv5-MyFR8
COMPANY_NAME=MyFR8 Logistics
SERVER_NAME=your-domain.com
PREFERRED_URL_SCHEME=https
UPLOAD_FOLDER=/opt/idrv5-myfr8/static/uploads