Skip to content

7. Live System Status Dashboard

Repository: Webpage (planovi-webpage) • Rule Prefix: BR-STS • Documented Rules: 6 • Open [TEAM_WHY_NEEDED] Questions: 2

1. Business Purpose & Actors

  • Problem solved: Displays public real-time operational health and active maintenance windows for core PLANOVI platform modules (Dashboard, AI Agent, Modbus Gateway, Billing, Database) to customers and stakeholders.
  • Actors: Cooperative administrators, end users checking service availability (/status or /status.php), Supabase public schema tables managed by planovi-backend / ops.

2. All Features & End-to-End Flows

  • Flow A — Status Fetch & Rendering (status.php:1-252):
    • Trigger: GET /status (or /status.php).
    • Data Fetch: Calls GET {supabase.url}/rest/v1/app_modules?select=*,app_modules_maintenance(*) with supabase.key (10s timeout, no Accept-Profile header → targets public schema).
    • Fallback: If empty($modules) && !$fetchError (unconfigured Supabase or empty 200 [] table), populates 5 hardcoded Polish mock modules (DASHBOARD, AI_AGENT, MODBUS_GATEWAY, BILLING, DATABASE) with empty maintenance arrays.
    • Status Aggregation (status.php:79-99): Iterates all modules and their nested app_modules_maintenance rows; any row with truthy is_under_maintenance sets $hasMaintenance = true and appends to $activeMaintenances. $allOperational = !$hasMaintenance.
    • Render: Global status banner (role="status", aria-live="polite", green operational vs amber #f59e0b maintenance), responsive .status-grid of module cards (each showing first active maintenance message + formatted start_time/end_time in d.m.Y H:i), and bottom section listing either active maintenance details or a static 90-day “no incidents” message.

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

  • BR-STS-01 (False-Operational Bug on Upstream API Failure): When Supabase returns non-2xx or times out, status.php:33 sets $fetchError = true while $modules remains []. Line 38 skips mock fallback (!$fetchError is false), lines 79-99 compute $hasMaintenance = false → $allOperational = true, and the page renders “All Systems Operational” with zero component cards and no error notice!
  • BR-STS-02 (Public Schema Coupling): Unlike all other queries in this repo (website schema), status.php:13-21 omits Accept-Profile: website and relies on public.app_modules and public.app_modules_maintenance (with a PostgREST foreign-key join) being readable by supabase.key.
  • BR-STS-03 (Single Active Maintenance Display per Module Card): Each module card breaks on the first maintenance record where !empty($m['is_under_maintenance']) (status.php:156-164), whereas the global $activeMaintenances list collects all active records across all modules (status.php:84-95).
  • BR-STS-04 (Static 90-Day Incident History): When $activeMaintenances is empty, status.php:228-234 unconditionally displays "No recent incidents or maintenance events reported in the last 90 days." — it does not query historical closed maintenance windows.
  • BR-STS-05 (Hardcoded Polish Strings in EN View): Fallback module names (status.php:42-73), default fallback title 'Moduł' (line 166), and active maintenance timestamps 'Początek:' / 'Szacowany koniec:' (lines 221-222) remain in Polish even when $current_lang === 'en'.
  • BR-STS-06 (Non-Canonical URL & Back Link): <link rel="canonical"> points to https://planovi.app/status.php (status.php:110) rather than /status, and the back button links to index.php (line 238).

4. State Machines & Data Lifecycle

Per-module binary display state derived from app_modules_maintenance[].is_under_maintenance:

  • operational (!isMaint → green badge #32CA42 / #22A830)
  • under_maintenance (isMaint === true → amber badge #f59e0b) Global banner state: operational iff zero modules are under_maintenance; otherwise maintenance.

5. Technical Contract (Inputs → Processing → Side Effects)

  • Endpoint: GET /status (or /status.php).
  • DB Tables Read (owned by planovi-backend, public schema): public.app_modules (id, display_name, module_name, internal_module_code) joined with public.app_modules_maintenance (is_under_maintenance, maintenance_message, start_time, end_time, updated_at).
  • Side Effects: Read-only HTTP GET to Supabase PostgREST (10s timeout); no writes or caching.

6. Cross-Repository Dependencies

Caller → CalleeProtocol & AuthExact Endpoint / Contract
planovi-webpage (status.php) → planovi-backend SupabaseHTTPS PostgREST (apikey + Authorization: Bearer, public schema)GET /rest/v1/app_modules?select=*,app_modules_maintenance(*)

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

  • Direct reuse of public.app_modules: Mirrors the exact maintenance gate tables used by the Flutter application so operators toggle maintenance in one database table and both app gates and the public status page reflect it immediately.
  • [TEAM_WHY_NEEDED: When Supabase is unreachable ($fetchError === true), should status.php display a "Status temporarily unavailable / Degraded" banner and HTTP 503 instead of falsely reporting "All Systems Operational"?]
  • [TEAM_WHY_NEEDED: Does public.app_modules_maintenance store historical closed records (is_under_maintenance = false) that status.php should display in the 90-day incident history box?]

8. Debugging, Logs & Common Failure Modes

Symptom / Error MessageRoot Cause in CodeHow to VerifyFix
Page says “All Systems Operational” but component grid is completely empty$fetchError = true (Supabase 401/403 RLS denial, missing FK relationship, or timeout >10s) (status.php:27-38)curl -i -H "apikey: <key>" "<url>/rest/v1/app_modules?select=*,app_modules_maintenance(*)"Verify RLS SELECT policy for anon on both public.app_modules and public.app_modules_maintenance and FK constraint
Page always shows 5 hardcoded Polish modules even when DB has different modulessupabase.url contains YOUR_PROJECT_ID, is empty, or public.app_modules has 0 rows (status.php:12,38)Query SELECT count(*) FROM public.app_modulesPopulate public.app_modules and verify supabase.url/key