Skip to Content
API v1Regional Logic

Regional Logic (UK vs US)

The $USA Flag

The entire UK/US branching in the API is controlled by a single environment variable:

// Set in api/include/core.php (loaded by bootstrap) $USA = json_decode($_ENV['USA']);

When $_ENV['USA'] is "true", $USA evaluates to truthy. When absent or falsy, the API runs in UK mode.

Many endpoint files also set this locally:

$USA = array_key_exists('USA', $_ENV) && json_decode($_ENV['USA']);

Deployment-Level Separation

UK and US run as completely separate deployments. Each has its own:

  • AWS Copilot environment (prod = UK, us-prod = US)
  • Database (housr_database_prod vs housr_database_us_prod)
  • Firebase project
  • API domain (api.uk.housr.com vs api.us.housr.com)

The $USA flag is set per-environment in copilot/api/manifest.yml:

# UK environments: no USA variable (defaults to falsy) prod: variables: DB_DATABASE: housr_database_prod # US environments: USA = true us-prod: variables: DB_DATABASE: housr_database_us_prod USA: true

Key Differences by Region

Bills Database

UK mode connects to a second database for bills:

if (!(array_key_exists('USA', $_ENV) && json_decode($_ENV['USA']))) { $billsLink = db_connect($_ENV['DB_DATABASE_BILLS']); }

US mode has no bills database connection.

Pricing

  • UK: price_pw (price per week), bills calculated separately using bills_included_prices table
  • US: price_pm (price per month), no bills calculation

The houses.php listing endpoint calculates price_pw_unlimited (rent + bills) for UK properties. For US, this is always null.

House Listing Sort Order

  • UK: Sorted by preference points (commute, inTheMix, housrHub, seshOrStudy scores), then tier, then priority
  • US: Sorted by distance from campus, then priority, with optional distanceFromCampus filter

Property Details

  • UK-only fields: housr_rating, garden, large_communal_space, recently_renovated, UoB approved status
  • US-only fields: square_footage, building_name, number_available, crm_block_id, crm_name, apply_now_link, property_operator_phone, amenities (pets, balcony, gym, pool, etc.), building details, lease terms by academic year

Viewing Requests

  • UK: Sends emails to the specific agent, viewing reward is pizza
  • US: Sends emails to all agents in the same company, viewing reward is coffee; integrates with Entrata for tour scheduling

SMS/Notifications

  • US: SMS sent from phone number +14027611623
  • UK: SMS sent with sender ID Housr

Auth

  • US: SSO via SimpleSAMLphp (university IdP), Mailchimp integration on first login, HubSpot contact creation
  • UK: Standard email/password, social auth

Moderation

The api/us/ directory contains US-only moderation endpoints:

  • getModerationStatus.php
  • updateModerationStatus.php
  • addModerator.php / removeModerator.php
  • rateLandlord.php
  • getLandlordReviewData.php
  • subscribedToPlus.php

Portal URLs

  • UK: housrportal.co.uk
  • US: portal.myhousr.com

Email

Mailgun uses different domains and API endpoints:

  • UK: EU endpoint (api.eu.mailgun.net), domain mg.housr.co.uk, from noreply@housr.co.uk
  • US: Default endpoint, domain mg.us.housr.com, from noreply@mg.us.housr.com

HubSpot Properties

Different CRM fields per region:

  • UK: concierge_stage, customer_journey_stage, house_rented
  • US: us_concierge_stage

Branding

  • UK: “Housr”, “letting agent”, “viewing”
  • US: “myhousr”, “property operator”, “tour”

Branching Pattern

The typical pattern in endpoint files:

$USA = array_key_exists('USA', $_ENV) && json_decode($_ENV['USA']); if ($USA) { // US-specific query/logic $sql = "SELECT ... price_pm ..."; } else { // UK-specific query/logic $sql = "SELECT ... price_pw ..."; }

Some files have entire SQL queries duplicated between US and UK branches (e.g., houses.php), while others have smaller conditional blocks within shared logic.

Last updated on