Systematically extract hardcoded values to configuration — environment variables, constants module, and Terraform variables
Systematically extract all hardcoded values from the codebase.
# Environment-specific values
grep -rn "hardcoded-project\|hardcoded-dataset" backend/app/ terraform/
# Magic numbers
grep -rn "datetime(20\|= [0-9][0-9][0-9]" backend/app/ | grep -v test | grep -v __pycache__
# Hardcoded URLs
grep -rn "https://.*sayari\|https://.*googleapis" backend/app/
# User-specific paths
grep -rn "/Users/" .
# Hardcoded lists
grep -rn "\['" backend/app/ | grep -v test | grep -v __pycache__ | grep -v import
| Category | Destination |
|---|---|
| Environment-specific (project ID, dataset, region) | Environment variables via config.py |
| Business defaults (codes, products, countries, dates) | app/core/constants.py |
| Scoring thresholds | or per-org config |
app/core/constants.py| External URLs | Environment variables with defaults in config.py |
| Terraform values | terraform/variables.tf |
Create backend/app/core/constants.py:
"""Business logic constants — extracted from hardcoded values."""
DEFAULT_COUNTRIES_OF_INTEREST: list[str] = [] # Populate per project
DEFAULT_SCORE_THRESHOLD: int = 70
DEFAULT_RESULTS_PER_PAGE: int = 50
# ... add project-specific constants
Update backend/app/core/config.py:
class Settings(BaseSettings):
PROJECT_ID: str # No default — must be set
BIGQUERY_DATASET: str
SAYARI_API_BASE_URL: str = "https://api.sayari.com"
# ... add all environment-driven settings
Ensure terraform/variables.tf has all hardcoded values as variables. No project IDs, regions, or service names should appear as literals in main.tf.
# Should return 0 matches for any known hardcoded values
grep -rn "KNOWN_HARDCODED_VALUE" backend/app/ | wc -l
# Run quality gate to ensure nothing broke
cd backend && python -m pytest tests/ -v --tb=short
cd backend && python -c "from app.main import app; print('Import OK')"