Skip to content

1. Routing, Configuration & Environment Bootstrap

Repository: Webpage (planovi-webpage) β€’ Rule Prefix: BR-CFG β€’ Documented Rules: 6 β€’ Open [TEAM_WHY_NEEDED] Questions: 2

1. Business Purpose & Actors

  • Problem solved: Serves clean, extension-less URLs across three heterogeneous hosting stacks (Apache/LiteSpeed, Nginx reverse proxy with front-controller fallback, and local PHP built-in CLI server) while separating per-environment feature flags, URLs, and server-side secrets outside the public web root.
  • Actors: Anonymous web visitors, search crawlers (/sitemap.xml, /llms.txt), developers running php -S, VPS web server operators.

2. All Features & End-to-End Flows

  • Flow A β€” Production/Staging Nginx Front-Controller (index.php:1-31):
    • Trigger: Nginx routes non-static paths to index.php.
    • Validation/Dispatch: Extracts path via parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH), strips trailing / (rtrim). Matches /blog β†’ blog.php, ~^/blog/([a-zA-Z0-9_\-]+)$~ β†’ sets $_GET['slug'] and requires blog-post.php, /sitemap.xml β†’ sitemap.php, /status β†’ status.php, /documentation or /docs β†’ documentation.php, then exit. Unmatched paths fall through and render the homepage (index.php:33-600) with HTTP 200 (no 404 for unknown virtual paths!).
  • Flow B β€” Apache/LiteSpeed Rewrite Engine (.htaccess:21-39):
    • Trigger: Incoming HTTP request on Apache/LiteSpeed.
    • Guard: Options -Indexes blocks directory listing; <FilesMatch> denies .git, .env, .user.ini, .htaccess, .htpasswd, and extensions .sql, .md, .lock, .bak, .config; explicitly grants (pl|en)\.json$.
    • Rewrite: ^sitemap\.xml$ β†’ sitemap.php; ^blog/([a-zA-Z0-9_\-]+)/?$ β†’ blog-post.php?slug=$1; ^blog/?$ β†’ blog.php; ^status/?$ β†’ status.php; ^documentation/?$ β†’ documentation.php ([L,QSA]). Note: /docs is NOT rewritten in .htaccess and collides with the physical docs/ directory (HTTP 403 due to Options -Indexes).
  • Flow C β€” Local Dev Router (router.php:1-57):
    • Trigger: php -S localhost:8080 router.php.
    • Dispatch: Existing non-directory files return false (served natively). Explicit routes handle /sitemap.xml, /blog/{slug}, /blog/?, /status/?, /docs/?, /documentation/?, /, /index.php, and extension-less .php files (file_exists(__DIR__ . $uri . '.php')). Unmatched directory paths such as /login/ return false so PHP built-in server serves login/index.php.
  • Flow D β€” Per-Environment Config Override (config.example.php:1-50):
    • Trigger: Any PHP script calling require_once 'config.php'.
    • Processing: config.php detects environment from host (planovi.app, www.planovi.app β†’ prod.php; dev-webpage.planovi.app, localhost, or any other host β†’ dev.php), loads <web root>/../config/<env>.php if present, and merges it via array_replace_recursive over SITE_CONFIG and per-environment defaults.
  • Flow E β€” Dormant MySQL Stub (db.php:1-22):
    • Trigger: index.php:38 executes require_once 'db.php'.
    • Processing: Defines $host = '127.0.0.1', $db = 'planovi_db', $user = 'root', $pass = '', $dsn, $options, enters an empty try/catch with new PDO(...) commented out. Produces zero side effects.

3. Hard Business Rules, Validations, Calculations & Edge Cases

  • BR-CFG-01 (Environment Detection Contract): Production config (../config/prod.php) applies to planovi.app and www.planovi.app; all other hosts (dev-webpage.planovi.app, localhost, etc.) load ../config/dev.php (config.example.php:6-10).
  • BR-CFG-02 (Environment-Default Feature Flags & Login Routing): Default links.panel_login is '/login/' on production and 'https://dev-panel.planovi.app' on dev. Default features.show_pricing_buttons is false on production and true on dev (config.example.php:17-24).
  • BR-CFG-03 (Out-of-Webroot Secret Isolation for Waitlist): waitlist.* keys are read exclusively from the out-of-webroot server config file, never committed in config.php (config.example.php:27-28, includes/waitlist.php:7).
  • BR-CFG-04 (Unknown Virtual Path Fallthrough in Nginx Mode): Because index.php:4-31 falls through to render the landing page on any unmatched path, arbitrary invalid URLs routed by Nginx to index.php return HTTP 200 with the homepage HTML instead of HTTP 404 (index.php:4-42).
  • BR-CFG-05 (Static Asset & Sensitive File Exposure Gap): .htaccess:12-14 blocks .sql, .md, .lock, .bak, .config, and dotfiles, but does not deny .sh (deploy.sh, scripts/sync-brand.sh), config.example.php, or llms.txt. On Nginx, .htaccess is ignored entirely (depends on external VPS Nginx rules).
  • BR-CFG-06 (Route Parity Divergence for /docs): /docs and /docs/ route to documentation.php in index.php:28 and router.php:40, but have no rewrite rule in .htaccess:21-39 where physical directory docs/ exists.

4. State Machines & Data Lifecycle

Stateless per-request routing and configuration resolution. External config files are read on each PHP request (no in-process opcode/APCu config caching beyond PHP OPcache).

5. Technical Contract (Inputs β†’ Processing β†’ Side Effects)

  • Inputs: HTTP REQUEST_URI, HTTP_HOST, out-of-webroot PHP array file (../config/{dev,prod}.php).
  • Processing: Path normalization/regex matching; array_replace_recursive config merge; dot-path lookup via site_config() and site_url().
  • Side Effects: Includes target PHP script; exposes global site_config() / site_url() helpers; index.php also sets $is_home_page = true and loads dormant db.php.

6. Cross-Repository Dependencies

Caller β†’ CalleeProtocol & AuthExact Endpoint / Contract
planovi-webpage (components/navbar.php:41) β†’ planovi-flutter-app (dev)HTTPS browser redirect (unauthenticated)links.panel_login default on dev: https://dev-panel.planovi.app
Hostinger VPS Nginx / deployer β†’ planovi-webpageFastCGI / PHP-FPMRoutes virtual URLs to index.php; mounts ../config/{dev,prod}.php outside web root

7. Why It Works This Way (Decisions, Trade-offs & Workarounds)

  • Front-controller added to index.php (commit 9a7c32e): Added specifically so Nginx / Docker reverse proxies that do not read Apache .htaccess can serve /blog, /blog/{slug}, /status, /documentation, /docs, and /sitemap.xml cleanly.
  • Root-absolute asset paths (/css/..., /js/..., /assets/...): Enforced in commit 9a7c32e so nested routes like /blog/my-slug and /login/ resolve assets from site root rather than relative to /blog/.
  • [TEAM_WHY_NEEDED: Why is the dormant MySQL PDO stub db.php still required in index.php:38 when all persistence uses Supabase REST API? Can db.php be safely removed?]
  • [TEAM_WHY_NEEDED: Should unknown virtual routes reaching index.php return HTTP 404 instead of rendering the homepage with HTTP 200?]

8. Debugging, Logs & Common Failure Modes

Symptom / Error MessageRoot Cause in CodeHow to VerifyFix
/docs returns 403 Forbidden on Apache/LiteSpeed.htaccess:6 sets Options -Indexes and lacks a rewrite for ^docs/?$, colliding with docs/ foldercurl -I https://planovi.app/docsLink to /documentation or add explicit rewrite rule / remove docs/ from webroot deploy
Local php -S localhost:8080 returns 404 for /blogServer started without router.phpCheck invocation commandRun php -S localhost:8080 router.php
Waitlist returns 503 (err_unavailable)Missing ../config/dev.php or ../config/prod.php or missing one of the 4 waitlist.* keys (includes/waitlist.php:79-84)Check PHP error log for [waitlist] missing server config key:Create ../config/<env>.php from config.example.php and populate all 4 waitlist.* keys