3. Application Runtimes: PHP 8.3 FPM, Flutter Web & IoT Converter Backends / MQTT
Repository:
VPS Infrastructure (planovi-vps)• Rule Prefix:BR-APP• Documented Rules: 5 • Open[TEAM_WHY_NEEDED]Questions: 3
Business Purpose & Actors
- Problem solved: Hosts all non-Supabase application runtimes on the VPS: one consolidated PHP 8.3 FPM + Nginx container serving both PROD and DEV marketing websites and all 4 PHP microservices (
dealflow,scheduler,offers,agreements), two Python 3.13 FastAPI backends (converters-api-prod,converters-api-dev) for IoT converter fleet management and mTLS device certificate signing, and a hardened Mosquitto 2 MQTT broker (mosquitto-dev) for IoT telemetry ingestion. - Actors: Public website visitors (
planovi.app), embedded iframe clients (dealflow/scheduler/agreements/offers), IoT technicians & admins (cloud.planovi.app/dev-cloud.planovi.app), and RP2350 IoT gateways publishing MQTT telemetry.
All Features & End-to-End Flows
- Consolidated PHP 8.3 FPM + Internal Nginx (
php-app/Dockerfile,php-app/nginx-php.conf):- Single container starts
php-fpm -D && nginx -g 'daemon off;'(php-app/Dockerfile:35). - Mounts
/opt/vps-apps:/var/www/apps(docker-compose.yml:288). - Internal Nginx dispatches by
Hostheader across 10 virtual hosts (php-app/nginx-php.conf:4-191):planovi.app,www.planovi.app->/var/www/apps/webpage/prod(try_files $uri $uri/ /index.php?$query_string;)dev-webpage.planovi.app->/var/www/apps/webpage/devdealflow.planovi.app/dev-dealflow.planovi.app->/var/www/apps/microservices/{prod,dev}/dealflow(fallback/inquiry.php?$query_string, indexinquiry.php offer.php index.php index.html)scheduler.planovi.app/dev-scheduler.planovi.app->/var/www/apps/microservices/{prod,dev}/scheduler(indexindex.php index.html default.php)offers.planovi.app/dev-offers.planovi.app->/var/www/apps/microservices/{prod,dev}/offersagreements.planovi.app/dev-agreements.planovi.app->/var/www/apps/microservices/{prod,dev}/agreements- Unmapped
default_server->301 https://planovi.app(php-app/nginx-php.conf:194-198).
- Single container starts
- Converter FastAPI Backends (
converters-api-prod&converters-api-dev,docker-compose.yml:337-368,395-435):- Built via inline Dockerfile from
/opt/vps-apps/converters/{prod,dev}(python:3.13-slim, installscloud/requirements.txt, copiescloud/, runsuvicorn cloud.app:app --host 0.0.0.0 --port 8000). - Connects asynchronously via
asyncpgtosupabase-db:5432(PROD) orsupabase-db-dev:5432(DEV) after DB passesservice_healthy. - Mounts
/opt/vps-stack/cloudflare-ssl:/etc/planovi/certs:ro(for Device CA signing keyplanovi-device-ca.keyand certplanovi-device-ca.pem) and/opt/vps-apps/converters/{prod,dev}/firmware:/app/firmware:ro(for serving OTA firmware binaries). - DEV (
converters-api-dev) additionally enables MQTT ingress (ASLANDI_MQTT_INGRESS_ENABLED="1") connecting over mTLS tomosquitto-dev:8883using client cert/etc/planovi/certs/planovi-mqtt-ingress.crt&.key, plus SD-card encryption key (ASLANDI_CARD_MASTER_KEY_B64) and edge shared token (ASLANDI_EDGE_SHARED_TOKEN).
- Built via inline Dockerfile from
- Hardened Mosquitto MQTT Broker (
mosquitto-dev,docker-compose.yml:369-394):- Runs as non-root UID/GID
1883:1883,read_only: true,cap_drop: [ALL],no-new-privileges:true, ephemeraltmpfsat/mosquitto/data(mode=0700). - Binds host loopback
127.0.0.1:18883:8883and internalvps-network:8883. - Mounts
/opt/vps-stack/mosquitto-dev/mosquitto.conf,/opt/vps-apps/converters/dev/cloud/config/aslandi.acl, and/opt/vps-stack/cloudflare-ssl:/mosquitto/certs:ro.
- Runs as non-root UID/GID
- Orphaned Flutter Web Container (
flutter-web,docker-compose.yml:295-307):- Runs
nginx:alpinemounting/opt/vps-apps/flutter-app/prod/build/web:/usr/share/nginx/html:ro, listed inproxy.depends_on, but never targeted by anyproxy_passinproxy/conf.d/*.conf.
- Runs
Hard Business Rules, Validations, Calculations & Edge Cases
- BR-APP-01 (PHP OPcache Tuning):
php-app/Dockerfile:16-23pinsopcache.memory_consumption=128,opcache.interned_strings_buffer=8,opcache.max_accelerated_files=4000,opcache.revalidate_freq=2(2-second cache revalidation aftergit reset --harddeploys without needing PHP-FPM restart),opcache.fast_shutdown=1,opcache.enable_cli=1. - BR-APP-02 (Dealflow Entrypoint Fallback): Requests to non-file paths on
dealflow.planovi.appanddev-dealflow.planovi.apprewrite to/inquiry.php?$query_string, whereas all other PHP vhosts rewrite to/index.php?$query_string(php-app/nginx-php.conf:53,128). - BR-APP-03 (Mosquitto Container Hardening):
mosquitto-devenforces read-only rootfs, zero Linux capabilities (cap_drop: ALL),no-new-privileges:true, non-root user1883:1883, and host port binding strictly restricted to127.0.0.1:18883(docker-compose.yml:372-388). - BR-APP-04 (Converter Startup Dependency Gate):
converters-api-prodwaits forsupabase-dbservice_healthy;converters-api-devwaits forsupabase-db-devservice_healthyANDmosquitto-devservice_started(docker-compose.yml:365-367,431-435). - BR-APP-05 (PROD vs DEV Converter Feature Parity Gap):
converters-api-devreceives MQTT mTLS ingress env vars,ASLANDI_EDGE_SHARED_TOKEN, andASLANDI_CARD_MASTER_KEY_B64;converters-api-prodreceives none of these (docker-compose.yml:355-359vs413-425).
State Machines & Data Lifecycle
php-appis stateless except for writable bind-mounted directories inside/opt/vps-apps(e.g.,dealflow/data/*.jsonwritten byform-writer.phpas UID82www-data).mosquitto-devpersists nothing across restarts (/mosquitto/dataistmpfs).converters-api-{prod,dev}state lives in PostgreSQL (supabase-db/supabase-db-dev); OTA firmware images are read-only mounts from/opt/vps-apps/converters/{prod,dev}/firmware.
Technical Contract
- Inputs:
php-app:80(fromvps-proxy),converters-api-{prod,dev}:8000(fromvps-proxy/api/v1/),mosquitto-dev:8883(fromvps-proxy:8883&converters-api-dev). - Mounts:
/opt/vps-apps,/opt/vps-stack/cloudflare-ssl,/opt/vps-stack/mosquitto-dev/mosquitto.conf.
Cross-Repository Dependencies
php-app -> planovi-webpage & planovi-microservices| Bind mount/opt/vps-apps/{webpage,microservices}/{prod,dev}| Serves live PHP files deployed byvps-deployer.converters-api-{prod,dev} -> planovi-converter| Build context/opt/vps-apps/converters/{prod,dev}+ firmware bind mount | Runscloud.app:app.mosquitto-dev -> planovi-converter| Bind mount/opt/vps-apps/converters/dev/cloud/config/aslandi.acl| Enforces MQTT topic ACLs.
Why It Works This Way
- Bind-mounted
/opt/vps-apps+opcache.revalidate_freq=2: Enables sub-second zero-downtime PHP deploys viagit reset --hardinvps-deployerwithout rebuildingphp-app. - Inline Dockerfile for
converters-api-*: Keeps Python build specification insideplanovi-vpswhile pulling application source from/opt/vps-apps/converters/{prod,dev}. [TEAM_WHY_NEEDED: Is the orphaned flutter-web container in docker-compose.yml:295-307 safe to remove now that vps-proxy serves /opt/vps-apps/flutter-app/{prod,dev}/build/web directly?][TEAM_WHY_NEEDED: When converters-api-prod transitions to MQTT ingress and SD-card encryption, will a dedicated mosquitto-prod service and prod ASLANDI_* env vars be added to docker-compose.yml?][TEAM_WHY_NEEDED: php-app/Dockerfile:27 runs COPY index.php /var/www/html/index.php, but php-app/index.php is listed in .gitignore:22 — should COPY index.php be removed from the Dockerfile or tracked as a stub?]
Debugging, Logs & Common Failure Modes
- Symptom:
docker compose build php-appfails with"/index.php": not found-> Root Cause:php-app/index.phpis gitignored (.gitignore:22) but copied inphp-app/Dockerfile:27-> Verify:ls -la /opt/vps-stack/php-app/index.php-> Fix: Create stubphp-app/index.phpor remove line 27 fromphp-app/Dockerfile. - Symptom:
converters-api-devfails to connect to MQTT -> Root Cause: Missing/opt/vps-stack/cloudflare-ssl/planovi-mqtt-ingress.{crt,key}or/opt/vps-stack/mosquitto-dev/mosquitto.conf-> Verify:docker logs --tail 50 mosquitto-dev && docker logs --tail 50 converters-api-dev-> Fix: Verify cert files andaslandi.aclpermissions (1883:1883readable). - Symptom: PHP
file_put_contentspermission denied indealflow/data-> Root Cause: Alpine PHP-FPM runs as UID82(www-data), whilegit reset --hardruns asroot-> Verify:ls -ld /opt/vps-apps/microservices/dev/dealflow/data-> Fix:chown -R 82:82 /opt/vps-apps/microservices/{dev,prod}/dealflow/data.