8. Flutter Fleet Admin Panel
Repository:
Converters (planovi-converter)• Rule Prefix:BR-ADMIN• Documented Rules: 6 • Open[TEAM_WHY_NEEDED]Questions: 2
1. Business Purpose & Actors
Provides the Planovi operations team with a Zone 1 responsive web/mobile control center (cloud.planovi.app / dev-cloud.planovi.app) to monitor infrastructure and fleet health, provision new RP2350 converters via USB/UF2 workflows, assign converters to customer organizations and buildings, fulfill production/service converter orders, inspect live 3-phase telemetry charts and per-packet receipt diagnostics, issue remote commands (including remote Wi-Fi recovery and live metric triggers), download signed firmware builds, and export audit logs.
- Actors: Planovi Operations / Fleet Administrators & Manufacturing Engineers (desktop web browser
>= 900 pxor mobile drawer< 900 px).
2. All Features & End-to-End Flows
- Navigation Shell (
admin/lib/screens/main_navigation_shell.dart,widgets/sidebar.dart):- Pure in-memory 6-tab shell (
AnimatedSwitcher,200 ms, no URL routing/deep links):0: Dashboard,1: Converters(drills intoConverterDetailScreen),2: Orders,3: Firmware & Guide,4: Activity Log,5: Settings. Collapsible dark graphite sidebar (234 px/72 px;< 900 pxuses darkAppBar+260 pxDrawer), inline SVG icons (immune to MaterialIcons font caching), PL/EN switcher.
- Pure in-memory 6-tab shell (
- Dashboard (
dashboard_screen.dart): Parallel loads/status,/converters/stats/overview,/activity-logs(top 5) with silent 15-secondTimer.periodicrefresh. Shows scrolling red marquee (14 scycle) when any system component!= online, 4 KPI cards,infrastructurevsapplicationcomponent cards, and latest 5 activity logs. - Fleet List & Provisioning Wizard (
converter_list_screen.dart,widgets/converter_dialogs.dart):- Server-side org dropdown (
all/unassigned/reserved/org UUID) + client-side search & status chips; switches desktop table to mobile cards at< 880 px. Displays 2×2 live telemetry chips (preserving historical values when offline). ConverterFormDialogdrives a 5-step USB provisioning state machine (form->preparing[950 ms] ->baking[1250 ms] ->connectUsb[BOOTSEL 3-step guide, copyableprovision_device.pyCLI command,.UF2download, 1500 ms polling onGET converters/$iduntilonline, manual “Check Status Now”, “Finish Registration” ->POST confirm-flash] ->readyToUse), plus Edit (PUT) and 2-step checkbox-confirmed Delete (DELETE).
- Server-side org dropdown (
- Converter Detail & Telemetry Monitor (
converter_detail_screen.dart):- Check Live Metrics: Queues
trigger_telemetryand pollstelemetry-diagnostics(limit=1)+commandsevery 3 s up to 65 s waiting for a new sequence orAPPLIED. - Silent 8-Second Auto-Polling (commit
2bdc8a6):_evaluateAutoPolling()runsTimer.periodic(8s)ONLY while a command with statusPENDING/SENTis younger than 10 minutes (_isRecentActiveCommand) ORconfigSyncPending == true; automatically cancels otherwise. - 4 Tabs: (0) Overview (metadata, desired cloud endpoint/interval presets
[10, 30, 60, 300], SD/FIFO, live Wi-Fi RSSI color-coded-60/-70/-80 dBm, remote commands incl. OTA release picker & Wi-Fi credential modal, recent logs), (1) Monitor (4 KPI boxes, customCanvas_MultiSeriesTelemetryPainterwith 6 parameter groups, meter filter, period stepper,4h/today/7d/1mranges, crosshair tooltip, 3-phase AC table, connected meters), (2) Telemetry Diagnostics (5 KPIs, active meters, paginated25/page receipts with detail modal showing decoded Modbus registers), (3) Commands (full history table + cancel button forPENDING).
- Check Live Metrics: Queues
- Converter Orders (
converter_orders_screen.dart): Filtersopen/completed/allandproduction/service, updates status inline viaPATCH converter-orders/$id, and offers “Create & Assign Converter” for open production orders (prefillingConverterFormDialog, then patching order toready+converter_serial). - Firmware & Guide (
firmware_guide_screen.dart): Visualizes RP2350 4 MiB Flash layout + OTP0x0500..0x0501, serves latest.UF2download, provides 3 copyable procedure tabs (Initial USB+OTP, Service USB A/B, Remote Cloud OTA), and lists DB + server-build releases with copyable SHA-256 and.UF2/.BINdownload links. - Activity Log & Settings (
activity_log_screen.dart,settings_screen.dart): Filterable log table (ALL/INFO/OK/WARN/ERROR+ un-debounced search) with CSV download (LocalStorageHelper.openUrl); Settings persistsproxy_endpoint,allow_failover,refresh_rate_sec(5..60 s),keep_history(7/30/90/365 d), anddefault_language.
3. Hard Business Rules, Validations, Calculations & Edge Cases
BR-ADMIN-01(API Base URL Resolution Without--dart-define):ApiService._baseUrl(admin/lib/services/api_service.dart) resolveskIsWeb && host != 'localhost' && host != '127.0.0.1'to${scheme}://${host}${port}/api/v1/; otherwise hardcodes'http://localhost:8000/api/v1/'. Dio enforces4 sconnect and4 sreceive timeouts.BR-ADMIN-02(Zero Client-Side Authentication):ApiServicesends noAuthorizationheader, JWT, or cookie.AuthService(admin/lib/services/auth_service.dart) is unreferenced dead mock code. Access control depends entirely on upstream Nginx IP allowlisting (deploy/nginx.admin.planovi.conf).BR-ADMIN-03(Bounded Conditional Auto-Polling):ConverterDetailScreenpolls silently every8 sstrictly whenconfigSyncPending == trueor an activePENDING/SENTcommand was created< 10 minutesago (_isRecentActiveCommand);DashboardScreenpolls every15 s(hardcoded, ignoringAdminSettings.refreshRateSec);ConverterFormDialogpolls every1500 msduringconnectUsb.BR-ADMIN-04(Remote Wi-Fi Modal Validation):converter_detail_screen.dartenforces SSID1..32chars and password either empty (open) or8..63chars before queuingupdate_wifi_credentials.BR-ADMIN-05(100% PL/EN Dictionary Parity & Persistence):I18n(admin/lib/services/i18n_service.dart) defaults to'pl', persists selection in browserlocalStorage['planovi_language_preference'](viaweb_storage_web.dart/ in-memory stubweb_storage_stub.dart), and maintains473keys in both'pl'and'en'verified byadmin/test/i18n_service_test.dart.BR-ADMIN-06(Zone 1 Theme & Tabular Numerics):admin/lib/theme.dartenforces light zinc canvas (#FAFAFA/#FFFFFF/#F4F4F5), dark graphite chrome (#09090B/#121215/#18181B), solid#32CA42buttons with#09090Bforeground (brandOnSolid),#22A830green text on light backgrounds,FontFeature.tabularFigures(), andsurfaceTintColor: Colors.transparent.
4. State Machines & Data Lifecycle
stateDiagram-v2
[*] --> form: Open Add / OS Upload dialog
form --> preparing: Submit -> POST prepare-usb-provisioning (950ms anim)
preparing --> baking: 1250ms firmware bake animation
baking --> connectUsb: Show BOOTSEL + CLI + UF2 download + 1.5s status poll
connectUsb --> readyToUse: Converter reports online OR user clicks Finish -> POST confirm-flash
readyToUse --> [*]
5. Technical Contract (Inputs -> Processing -> Side Effects)
- Consumed Backend Endpoints:
GET/PUT/DELETE converters,GET converters/stats/overview,GET converters-next-serial,POST converters/prepare-usb-provisioning,POST converters/$id/{confirm-flash,desired-config,commands},GET converters/$id/{telemetry-diagnostics,monitor,commands},DELETE converters/$id/commands/$cmdId,GET converters/firmware/{info,latest-uf2,download/*},GET firmware/releases(fallbackconverters/firmware/releases),GET organizations,GET/PATCH converter-orders,GET status,GET activity-logs(+/export-csv),GET/PUT settings. - Browser APIs:
window.localStorage(planovi_language_preference),window.open(CSV/UF2 downloads),window.fetchmonkey-patch inadmin/web/index.htmlforcingcache: 'no-cache'on Flutter font/asset manifests.
6. Cross-Repository Dependencies
admin/->cloud/api/*| Same-origin HTTPS/api/v1/*(orhttp://localhost:8000/api/v1/locally), unauthenticated | JSON REST.- Brand assets in
admin/assets/brand/synced fromPA-IDEAS/planovi-docsviascripts/sync-brand.sh.
7. Why It Works This Way (Decisions, Trade-offs & Workarounds)
- Inline SVG Sidebar Icons (
sidebar.dart:182): Intentionally avoids MaterialIcons glyphs in the navigation rail to eliminate browser font-cache rendering glitches;admin/web/index.htmladditionally bypasses HTTP cache onMaterialIcons-Regular.otfandFontManifest.json. - Confirmed Bugs & Tech Debt:
- 5 Missing I18n Keys Rendered Raw:
chart_legend_pv(converter_detail_screen.dart:2213),chart_legend_cons(:2214),th_time(:2267),modal_close(:2330,sidebar.dart:152),no_components_found(dashboard_screen.dart:706) are referenced in widgets without dictionary entries (and76keys ini18n_service.dartare unused). - Hardcoded Untranslated Strings: Polish literals in
converter_detail_screen.dart(lines 1195, 2164–2204, 2255–2297, 2631, 2654),converter_list_screen.dart:708,converter_dialogs.dart:322,1677,1683; English-onlyStatusPill(status_pill.dart). - Production Response Logging:
ApiServiceattachesLogInterceptor(request: true, responseBody: true, error: true)unconditionally, printing full responses (including USB provisioningaes_key_hex& client private keys!) to browser DevTools console. - Ignored / Fake UI Data:
DashboardScreenignoresAdminSettings.refreshRateSec(hardcoded15 s);ConverterDetailScreenhardcodes'HTTPS Standalone mTLS (:443)'(:1202) and static"Bus Channel 0 · Baud 9600 · 0 CRC Errors"(:2087);ActivityLogScreenfires search API calls on every keystroke without debounce;SettingsScreenomits controls forstatusAlertsEnabled,requireMfa, andapiTokenPreview. - Dead Code:
AuthService,sampleConverters(converter.dart:361-583),ApiService.{fetchFacilities,createConverter,uploadFirmwareRelease},window.requestPicoUsbDevice(admin/web/index.html:48-71),google_fontsinpubspec.yaml; deprecateddart:htmlinweb_storage_web.dart.
- 5 Missing I18n Keys Rendered Raw:
[TEAM_WHY_NEEDED: ConverterDetailScreen:2087 displays a static string "Bus Channel 0 · Baud 9600 · 0 CRC Errors" instead of real device Modbus diagnostics, and hardcodes dev-telemetry.planovi.app defaults. Should these be wired to real telemetry/status fields?][TEAM_WHY_NEEDED: Is Supabase Auth (TODOs in auth_service.dart) planned for cloud.planovi.app, or will admin access remain behind Nginx IP allowlist / Cloudflare Access?]
8. Debugging, Logs & Common Failure Modes
| Symptom / Error Message | Root Cause in Code | How to Verify / Exact Command | Fix |
|---|---|---|---|
Raw strings modal_close / chart_legend_pv / no_components_found appear in UI | 5 i18n keys missing from I18n._localizedValues (admin/lib/services/i18n_service.dart) | Search I18n.t('modal_close') etc. in admin/lib/ | Add the 5 missing keys to both 'pl' and 'en' maps |
Local flutter run -d chrome fails with DioException connection refused | ApiService._baseUrl hardcodes http://localhost:8000/api/v1/ on localhost | Check DevTools console (logged by LogInterceptor) | Start FastAPI backend on port 8000 (uvicorn cloud.app:app --port 8000) |
| Order status dropdown update fails with 500 error | ConverterOrdersScreen calls PATCH converter-orders/$id hitting AttributeError bug in cloud/api/converters.py:635-648 | Check network tab response on PATCH /api/v1/converter-orders/<uuid> | Fix backend ConverterOrderUpdateRequest field names |
flutter test fails on i18n parity | Unmatched key added to 'pl' or 'en' in i18n_service.dart | cd admin && flutter test | Keep 'pl' and 'en' key sets strictly identical |