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 runningphp -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 requiresblog-post.php,/sitemap.xmlβsitemap.php,/statusβstatus.php,/documentationor/docsβdocumentation.php, thenexit. Unmatched paths fall through and render the homepage (index.php:33-600) with HTTP200(no 404 for unknown virtual paths!).
- Trigger: Nginx routes non-static paths to
- Flow B β Apache/LiteSpeed Rewrite Engine (
.htaccess:21-39):- Trigger: Incoming HTTP request on Apache/LiteSpeed.
- Guard:
Options -Indexesblocks 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:/docsis NOT rewritten in.htaccessand collides with the physicaldocs/directory (HTTP403due toOptions -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.phpfiles (file_exists(__DIR__ . $uri . '.php')). Unmatched directory paths such as/login/returnfalseso PHP built-in server serveslogin/index.php.
- Trigger:
- Flow D β Per-Environment Config Override (
config.example.php:1-50):- Trigger: Any PHP script calling
require_once 'config.php'. - Processing:
config.phpdetects 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>.phpif present, and merges it viaarray_replace_recursiveoverSITE_CONFIGand per-environment defaults.
- Trigger: Any PHP script calling
- Flow E β Dormant MySQL Stub (
db.php:1-22):- Trigger:
index.php:38executesrequire_once 'db.php'. - Processing: Defines
$host = '127.0.0.1',$db = 'planovi_db',$user = 'root',$pass = '',$dsn,$options, enters an emptytry/catchwithnew PDO(...)commented out. Produces zero side effects.
- Trigger:
3. Hard Business Rules, Validations, Calculations & Edge Cases
- BR-CFG-01 (Environment Detection Contract): Production config (
../config/prod.php) applies toplanovi.appandwww.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_loginis'/login/'on production and'https://dev-panel.planovi.app'on dev. Defaultfeatures.show_pricing_buttonsisfalseon production andtrueon 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 inconfig.php(config.example.php:27-28,includes/waitlist.php:7). - BR-CFG-04 (Unknown Virtual Path Fallthrough in Nginx Mode): Because
index.php:4-31falls through to render the landing page on any unmatched path, arbitrary invalid URLs routed by Nginx toindex.phpreturn HTTP200with the homepage HTML instead of HTTP404(index.php:4-42). - BR-CFG-05 (Static Asset & Sensitive File Exposure Gap):
.htaccess:12-14blocks.sql,.md,.lock,.bak,.config, and dotfiles, but does not deny.sh(deploy.sh,scripts/sync-brand.sh),config.example.php, orllms.txt. On Nginx,.htaccessis ignored entirely (depends on external VPS Nginx rules). - BR-CFG-06 (Route Parity Divergence for
/docs):/docsand/docs/route todocumentation.phpinindex.php:28androuter.php:40, but have no rewrite rule in.htaccess:21-39where physical directorydocs/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_recursiveconfig merge; dot-path lookup viasite_config()andsite_url(). - Side Effects: Includes target PHP script; exposes global
site_config()/site_url()helpers;index.phpalso sets$is_home_page = trueand loads dormantdb.php.
6. Cross-Repository Dependencies
| Caller β Callee | Protocol & Auth | Exact 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-webpage | FastCGI / PHP-FPM | Routes 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(commit9a7c32e): Added specifically so Nginx / Docker reverse proxies that do not read Apache.htaccesscan serve/blog,/blog/{slug},/status,/documentation,/docs, and/sitemap.xmlcleanly. - Root-absolute asset paths (
/css/...,/js/...,/assets/...): Enforced in commit9a7c32eso nested routes like/blog/my-slugand/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 Message | Root Cause in Code | How to Verify | Fix |
|---|---|---|---|
/docs returns 403 Forbidden on Apache/LiteSpeed | .htaccess:6 sets Options -Indexes and lacks a rewrite for ^docs/?$, colliding with docs/ folder | curl -I https://planovi.app/docs | Link to /documentation or add explicit rewrite rule / remove docs/ from webroot deploy |
Local php -S localhost:8080 returns 404 for /blog | Server started without router.php | Check invocation command | Run 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 |