Skip to main content

Overview

The Product Distribution Dashboard uses environment variables to configure database connections, external data sources, frontend integration, and scheduling. The application supports multiple Spring profiles (dev and prod) with profile-specific configurations.

Spring Profiles

The active profile is controlled by the SPRING_PROFILES_ACTIVE environment variable:
SPRING_PROFILES_ACTIVE=dev  # Development profile
SPRING_PROFILES_ACTIVE=prod # Production profile
Default profile is dev if not specified.

Environment Variables Reference

Core Application

VariableRequiredDefaultDescription
SPRING_PROFILES_ACTIVENodevActive Spring profile (dev/prod)
PORTNo8080Server port for the backend application

Database Configuration (Dev Profile)

VariableRequiredDefaultDescription
SPRING_DATASOURCE_URLYes-JDBC URL for PostgreSQL database
SPRING_DATASOURCE_USERNAMEYes-Database username
SPRING_DATASOURCE_PASSWORDYes-Database password
Example (Dev):
SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/product_distribution_db
SPRING_DATASOURCE_USERNAME=product_distribution
SPRING_DATASOURCE_PASSWORD=product_distribution

Database Configuration (Prod Profile)

VariableRequiredDefaultDescription
DATABASE_HOSTYes-PostgreSQL server hostname
DATABASE_PORTYes-PostgreSQL server port
DATABASE_NAMEYes-Database name
DATABASE_USERNAMEYes-Database username
DATABASE_PASSWORDYes-Database password
Example (Prod):
DATABASE_HOST=prod-postgres.example.com
DATABASE_PORT=5432
DATABASE_NAME=product_distribution_db
DATABASE_USERNAME=prod_user
DATABASE_PASSWORD=secure_password
The production profile constructs the JDBC URL as:
jdbc:postgresql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}?sslmode=require&reWriteBatchedInserts=true

Frontend Integration

VariableRequiredDefaultDescription
APP_FRONTEND_URLYes-Frontend application URL for CORS configuration
Example:
APP_FRONTEND_URL=http://localhost:4200
This variable configures CORS to allow requests from your frontend application.

External Data Sources

VariableRequiredDefaultDescription
DATA_PRODUCTS_URLNoGitHub raw URLURL for products JSON data
DATA_STORES_URLNoGitHub raw URLURL for stores JSON data
DATA_WAREHOUSES_URLNoGitHub raw URLURL for warehouses JSON data
Defaults:
DATA_PRODUCTS_URL=https://raw.githubusercontent.com/raulHerediaHorcajo/product-distribution/main/data/current/products.json
DATA_STORES_URL=https://raw.githubusercontent.com/raulHerediaHorcajo/product-distribution/main/data/current/stores.json
DATA_WAREHOUSES_URL=https://raw.githubusercontent.com/raulHerediaHorcajo/product-distribution/main/data/current/warehouses.json

Scheduler Configuration

VariableRequiredDefault (Dev)Default (Prod)Description
SCHEDULER_DISTRIBUTION_CRONNo3 * * * * *0 0 2 * * *Cron expression for distribution scheduler
Dev Profile: Runs every minute at 3 seconds past the minute (for testing) Prod Profile: Runs daily at 2:00 AM Cron Expression Format:
second minute hour day month weekday
Examples:
  • 0 0 2 * * * - Every day at 2:00 AM
  • 0 0 */6 * * * - Every 6 hours
  • 0 30 8 * * MON-FRI - Weekdays at 8:30 AM

Docker Compose Configuration

When running with Docker Compose, the following environment variables are configured:
services:
  backend:
    environment:
      SPRING_PROFILES_ACTIVE: dev
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/product_distribution_db
      SPRING_DATASOURCE_USERNAME: product_distribution
      SPRING_DATASOURCE_PASSWORD: product_distribution
      APP_FRONTEND_URL: http://localhost:4200

Profile-Specific Behavior

Development Profile

  • Simple database URL configuration via SPRING_DATASOURCE_URL
  • Frequent scheduler execution (every minute) for testing
  • No SSL requirement for database connections

Production Profile

  • Parameterized database connection (host, port, database name)
  • SSL required for database connections (sslmode=require)
  • Batch insert optimization enabled (reWriteBatchedInserts=true)
  • HikariCP connection pooling configured
  • Hibernate batch processing enabled
  • Daily scheduler execution at 2:00 AM
  • Server binds to all interfaces (0.0.0.0)

Warehouse Selection Strategy

The warehouse selection strategy is configured in application.properties (not an environment variable):
distribution.strategy.warehouse-selection=distanceWithToleranceStrategy
Available strategies:
  • distanceOnlyStrategy - Orders warehouses by distance only
  • distanceWithToleranceStrategy - Considers distance tolerance and product stock
See the Strategies page for detailed information.

Environment Setup Examples

Local Development

export SPRING_PROFILES_ACTIVE=dev
export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/product_distribution_db
export SPRING_DATASOURCE_USERNAME=product_distribution
export SPRING_DATASOURCE_PASSWORD=product_distribution
export APP_FRONTEND_URL=http://localhost:4200

Production Deployment

export SPRING_PROFILES_ACTIVE=prod
export DATABASE_HOST=prod-db.example.com
export DATABASE_PORT=5432
export DATABASE_NAME=product_distribution_db
export DATABASE_USERNAME=prod_user
export DATABASE_PASSWORD=${SECRET_DB_PASSWORD}
export APP_FRONTEND_URL=https://dashboard.example.com
export SCHEDULER_DISTRIBUTION_CRON="0 0 2 * * *"

Validation

The application will fail to start if required environment variables are missing. Check the logs for error messages like:
Could not resolve placeholder 'SPRING_DATASOURCE_URL' in value "${SPRING_DATASOURCE_URL}"
This indicates a missing required environment variable for the active profile.

Build docs developers (and LLMs) love