Architecture
File-Based Routing
Housr API v1 uses flat PHP files as endpoints. There is no framework router. Each .php file in the api/ directory is a directly accessible HTTP endpoint.
URL mapping: A request to https://api.uk.housr.com/api/login.php maps to the file api/login.php.
Nginx is configured to pass all .php requests to PHP-FPM. The key Nginx directive that makes the bootstrap work:
fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/api/include/bootstrap.php";This means api/include/bootstrap.php is automatically executed before every PHP file, providing database connections, environment variables, Sentry init, and global variables like $link, $billsLink, $key, $USA, etc.
Request Flow
Client Request
|
v
Nginx (port 80)
|
v
PHP-FPM (port 9000)
|
v
auto_prepend: api/include/bootstrap.php
|-- loads .env via configdb.php
|-- sets up DB connections ($link, $billsLink)
|-- sets global JWT vars ($key, $issued_at, $issuer)
|-- sets $USA flag from $_ENV['USA']
|-- initializes Sentry
|
v
Endpoint file (e.g., api/login.php)
|-- sets CORS headers
|-- includes JWT libs
|-- includes utility files as needed
|-- reads $_POST / $_GET / $_SERVER['HTTP_AUTHORIZATION']
|-- performs business logic (DB queries, API calls)
|-- echoes JSON responseBootstrap Chain
api/include/bootstrap.php- Entry point. Loads composer autoloader, then configdb.php, core.php, and exceptionHandler.php. Initializes Sentry.api/include/configdb.php- Parses.envfile into$_ENV. Defines DB constants (DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_NAME). Creates$link(main DB) and$billsLink(bills DB, UK only) connections viadb_connect().api/include/core.php- Sets timezone to UTC. Defines JWT variables ($key,$issued_at,$issuer). Sets$USAand$databaseglobals.api/include/dbcon.php- Alternative bootstrap that sets up Firebase (Realtime DB + Cloud Messaging) via Kreait SDK. Used by notification-related endpoints.
Utility Pattern
Shared logic lives in api/utils/. Endpoint files include utilities with include_once or require_once:
include_once './utils/jwtUtils.php';
include_once './utils/sendEmail.php';
include_once './utils/hubspotUtils.php';Key utility files:
| File | Purpose |
|---|---|
jwtUtils.php | getUserId($jwt), getOptionalUserId($jwt) - JWT decoding |
dbFunctions.php | findById(), findByColumn(), findAllByColumn(), findByCondition(), updateValue(), deleteByCondition() |
notificationUtils.php | sendNotification() (FCM via Kreait), sendText() (SMS via Twilio) |
sendEmail.php | sendEmail() via Mailgun |
sendSMS.php | sendSMS() via Twilio |
hubspotUtils.php | HubSpot CRM operations (contacts, deals, companies) |
featureFlagUtils.php | isFeatureEnabled($featureName) - checks feature_flags table |
apiKeyChecker.php | checkAPIKey() - for external API key auth |
billQuoteUtils.php | Bills quoting logic |
billsPriceUtils.php | Bills pricing calculations |
otpUtils.php | OTP generation and SMS sending |
loggingUtils.php | Request logging with unique request IDs |
Authentication Methods
Endpoints use two patterns for receiving JWTs:
- POST body (legacy, most endpoints):
$jwt = $_POST["jwt"] - Authorization header (newer endpoints):
$jwt = $_SERVER['HTTP_AUTHORIZATION']
Some endpoints also support API key auth via apiKeyChecker.php for external/portal access.
External Endpoints
The api/external/ directory contains endpoints meant for external consumers (the Housr website, brand portal). These are routed via Nginx rewrites:
location /api/external/ {
rewrite ^/api/external/(.*)$ /api/external/$1.php last;
}The Entrata subdirectory has its own routing:
location /api/external/entrata/ {
try_files $uri $uri/ /api/external/entrata/index.php$is_args$args;
}Subdirectories
| Directory | Purpose |
|---|---|
api/roomie/ | Roomie (flatmate matching) feature endpoints |
api/us/ | US-only endpoints (moderation, landlord reviews) |
api/propertyFeed/ | Property feed integrations with subdirs per provider |
api/external/ | External-facing endpoints (Finix payments, Entrata, perks) |
api/websiteEnquiries/ | Website viewing enquiry handling |
api/include/ | Bootstrap files, DB config, email templates |
api/utils/ | Shared utility functions |
api/libs/ | Vendored libraries (php-jwt, AWS SDK) |