Skip to content
📦 ARCHIVED SNAPSHOT (v1.0) You are viewing historical business logic and documentation for VPS Infrastructure v1.0 (frozen on 2026-11-23, commit b3a7ad3). Switch to Latest →

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

  1. 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 Host header 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/dev
      • dealflow.planovi.app / dev-dealflow.planovi.app -> /var/www/apps/microservices/{prod,dev}/dealflow (fallback /inquiry.php?$query_string, index inquiry.php offer.php index.php index.html)
      • scheduler.planovi.app / dev-scheduler.planovi.app -> /var/www/apps/microservices/{prod,dev}/scheduler (index index.php index.html default.php)
      • offers.planovi.app / dev-offers.planovi.app -> /var/www/apps/microservices/{prod,dev}/offers
      • agreements.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).
  2. 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, installs cloud/requirements.txt, copies cloud/, runs uvicorn cloud.app:app --host 0.0.0.0 --port 8000).
    • Connects asynchronously via asyncpg to supabase-db:5432 (PROD) or supabase-db-dev:5432 (DEV) after DB passes service_healthy.
    • Mounts /opt/vps-stack/cloudflare-ssl:/etc/planovi/certs:ro (for Device CA signing key planovi-device-ca.key and cert planovi-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 to mosquitto-dev:8883 using 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).
  3. 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, ephemeral tmpfs at /mosquitto/data (mode=0700).
    • Binds host loopback 127.0.0.1:18883:8883 and internal vps-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.
  4. Orphaned Flutter Web Container (flutter-web, docker-compose.yml:295-307):
    • Runs nginx:alpine mounting /opt/vps-apps/flutter-app/prod/build/web:/usr/share/nginx/html:ro, listed in proxy.depends_on, but never targeted by any proxy_pass in proxy/conf.d/*.conf.

Hard Business Rules, Validations, Calculations & Edge Cases

  • BR-APP-01 (PHP OPcache Tuning): php-app/Dockerfile:16-23 pins opcache.memory_consumption=128, opcache.interned_strings_buffer=8, opcache.max_accelerated_files=4000, opcache.revalidate_freq=2 (2-second cache revalidation after git reset --hard deploys 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.app and dev-dealflow.planovi.app rewrite 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-dev enforces read-only rootfs, zero Linux capabilities (cap_drop: ALL), no-new-privileges:true, non-root user 1883:1883, and host port binding strictly restricted to 127.0.0.1:18883 (docker-compose.yml:372-388).
  • BR-APP-04 (Converter Startup Dependency Gate): converters-api-prod waits for supabase-db service_healthy; converters-api-dev waits for supabase-db-dev service_healthy AND mosquitto-dev service_started (docker-compose.yml:365-367,431-435).
  • BR-APP-05 (PROD vs DEV Converter Feature Parity Gap): converters-api-dev receives MQTT mTLS ingress env vars, ASLANDI_EDGE_SHARED_TOKEN, and ASLANDI_CARD_MASTER_KEY_B64; converters-api-prod receives none of these (docker-compose.yml:355-359 vs 413-425).

State Machines & Data Lifecycle

  • php-app is stateless except for writable bind-mounted directories inside /opt/vps-apps (e.g., dealflow/data/*.json written by form-writer.php as UID 82 www-data).
  • mosquitto-dev persists nothing across restarts (/mosquitto/data is tmpfs).
  • 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 (from vps-proxy), converters-api-{prod,dev}:8000 (from vps-proxy /api/v1/), mosquitto-dev:8883 (from vps-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 by vps-deployer.
  • converters-api-{prod,dev} -> planovi-converter | Build context /opt/vps-apps/converters/{prod,dev} + firmware bind mount | Runs cloud.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 via git reset --hard in vps-deployer without rebuilding php-app.
  • Inline Dockerfile for converters-api-*: Keeps Python build specification inside planovi-vps while 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-app fails with "/index.php": not found -> Root Cause: php-app/index.php is gitignored (.gitignore:22) but copied in php-app/Dockerfile:27 -> Verify: ls -la /opt/vps-stack/php-app/index.php -> Fix: Create stub php-app/index.php or remove line 27 from php-app/Dockerfile.
  • Symptom: converters-api-dev fails 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 and aslandi.acl permissions (1883:1883 readable).
  • Symptom: PHP file_put_contents permission denied in dealflow/data -> Root Cause: Alpine PHP-FPM runs as UID 82 (www-data), while git reset --hard runs as root -> Verify: ls -ld /opt/vps-apps/microservices/dev/dealflow/data -> Fix: chown -R 82:82 /opt/vps-apps/microservices/{dev,prod}/dealflow/data.