aiBatteryLifeCycle / docs /frontend.md
NeerajCodz's picture
feat: full project β€” ML simulation, dashboard UI, models on HF Hub
f381be8

Frontend Documentation

Technology Stack

Technology Version Purpose
Vite 7.x Build tool & dev server
React 19.x UI framework
TypeScript 5.9.x Type safety
Recharts 3.7.x Interactive 2D charts (BarChart, LineChart, AreaChart, RadarChart, ScatterChart, PieChart)
lucide-react 0.575.x Icon system β€” no emojis in UI
TailwindCSS 4.x Utility-first CSS
Axios 1.x HTTP client

Project Structure

frontend/
β”œβ”€β”€ index.html
β”œβ”€β”€ vite.config.ts          # Vite + /api proxy
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ package.json
└── src/
    β”œβ”€β”€ main.tsx
    β”œβ”€β”€ App.tsx             # Root, tab navigation, v1/v2 selector
    β”œβ”€β”€ api.ts              # All API calls + TypeScript types
    β”œβ”€β”€ index.css
    └── components/
        β”œβ”€β”€ Dashboard.tsx           # Fleet overview heatmap + capacity charts
        β”œβ”€β”€ PredictionForm.tsx      # Single-cycle SOH prediction + gauge
        β”œβ”€β”€ SimulationPanel.tsx     # Multi-battery lifecycle simulation
        β”œβ”€β”€ MetricsPanel.tsx        # Full model metrics dashboard
        β”œβ”€β”€ GraphPanel.tsx          # Analytics β€” fleet, single battery, compare, temperature
        └── RecommendationPanel.tsx # Operating condition optimizer with charts

Tab Order

Tab Component Description
Simulation SimulationPanel ML-backed multi-battery lifecycle forecasting
Predict PredictionForm Single-cycle SOH + RUL prediction
Metrics MetricsPanel Full model evaluation dashboard
Analytics GraphPanel Fleet & per-battery interactive analytics
Recommendations RecommendationPanel Operating condition optimizer
Research Paper β€” Embedded research PDF

Components

MetricsPanel

Full interactive model evaluation dashboard with 6 switchable sections:

  • Overview β€” KPI stat cards with lucide icons, RΒ² ranking bar chart, model family pie chart, normalized radar chart (top 5), RΒ² vs MAE scatter trade-off plot, Top-3 rankings podium
  • Models β€” Interactive sort (RΒ²/MAE/RMSE/MAPE, asc/desc), family filter dropdown, chart-type toggle (bar/radar/scatter), multi-select compare mode, colour-coded metric badges, full metrics table with per-row highlighting
  • Validation β€” Within-5% / within-10% grouped bar chart, full validation table with pass/fail badges
  • Deep Learning β€” LSTM/ensemble/VAE-LSTM/DG-iTransformer results with charts and metric tables
  • Dataset β€” Battery stats cards, engineered features list, temperature groups, degradation distribution bar chart, SOH range gauge
  • Figures β€” Searchable grid of all artifact figures with modal lightbox on click

Key features:

  • All icons via lucide-react (no emojis)
  • filteredModels useMemo respects active sort/filter state
  • MetricBadge component colour-codes values green/yellow/red based on model quality thresholds
  • SectionBadge nav bar with icon + label

GraphPanel (Analytics)

Four-section analytics dashboard:

  • Fleet Overview β€” SOH bar chart sorted by health (colour-coded green/yellow/red), SOH vs cycles bubble scatter (bubble = temperature), fleet status KPI cards (healthy/degraded/near-EOL), filter controls (min SOH slider, temp range), clickable battery roster table
  • Single Battery β€” SOH trajectory + linear RUL projection overlay, capacity fade area chart, smoothed degradation rate area chart, show/hide EOL reference line toggle
  • Compare β€” Multi-select up to 5 batteries; SOH overlay line chart with distinct colours per battery, capacity fade overlay, summary comparison table (final SOH, cycles, min capacity)
  • Temperature Analysis β€” Temperature vs SOH scatter, temperature distribution histogram

Key features:

  • Multi-battery data loaded in parallel using Promise.all
  • RUL projection via least-squares on last 20 cycles β†’ extrapolated to 70% SOH
  • SohBadge component with dynamic colour + icon

RecommendationPanel

Interactive optimizer replacing the previous plain form + table:

  • Input form β€” Text input for battery ID, range sliders for SOH and ambient temperature, numeric inputs for cycle and top-k
  • Summary cards β€” Battery ID, best predicted RUL, best improvement, config count
  • Visual Analysis tabs:
    • RUL Comparison β€” bar chart comparing predicted RUL across all recommendations
    • Parameters β€” grouped bar chart showing temp/current/cutoff per rank
    • Radar β€” normalized multi-metric radar chart for top-3 configs
  • Recommendations table β€” rank icons (Trophy/Award/Medal from lucide), colour-coded improvement badges, expandable rows showing per-recommendation explanation and parameter details

SimulationPanel

  • Configure up to N battery simulations with individual parameters (temp, voltage, current, EOL threshold)
  • Select ML model for lifecycle prediction (or pure physics fallback)
  • Animated SOH trajectory charts, final stats table, degradation state timeline

Dashboard

  • Fleet battery grid with SOH colour coding
  • Capacity fade line chart per selected battery
  • Model metrics bar chart

PredictionForm

  • 12-input form with all engineered cycle features
  • SOH gauge visualization (SVG ring) with degradation state colour
  • Confidence interval display
  • Model selector (v2 models / best_ensemble)

API Integration (api.ts)

All API calls return typed TypeScript response objects:

Function Endpoint Description
fetchDashboard() GET /api/dashboard Fleet overview + capacity fade data
fetchBatteries() GET /api/batteries All battery metadata
fetchBatteryCapacity(id) GET /api/battery/{id}/capacity Per-battery cycles, capacity, SOH arrays
predictSoh(req) POST /api/v2/predict Single-cycle SOH + RUL prediction
fetchRecommendations(req) POST /api/v2/recommend Operating condition optimization
simulateBatteries(req) POST /api/v2/simulate Multi-battery lifecycle simulation
fetchMetrics() GET /api/metrics Full model evaluation metrics
fetchModels() GET /api/v2/models All loaded models with metadata

Development

cd frontend
npm install
npm run dev        # http://localhost:5173

API requests proxy to http://localhost:7860 in dev mode (see vite.config.ts).

Build

npm run build      # outputs to dist/

The built dist/ folder is served as static files by FastAPI at the root path. | Vite | 6.x | Build tool & dev server | | React | 18.x | UI framework | | TypeScript | 5.x | Type safety | | Three.js | latest | 3D rendering | | @react-three/fiber | latest | React renderer for Three.js | | @react-three/drei | latest | Three.js helpers | | Recharts | latest | 2D charts | | TailwindCSS | 4.x | Utility-first CSS | | Axios | latest | HTTP client |

Project Structure

frontend/
β”œβ”€β”€ index.html              # Entry HTML
β”œβ”€β”€ vite.config.ts          # Vite + proxy config
β”œβ”€β”€ tsconfig.json           # TypeScript config
β”œβ”€β”€ package.json
β”œβ”€β”€ public/
β”‚   └── vite.svg            # Favicon
└── src/
    β”œβ”€β”€ main.tsx            # React entry point
    β”œβ”€β”€ App.tsx             # Root component + tab navigation
    β”œβ”€β”€ api.ts              # API client + types
    β”œβ”€β”€ index.css           # TailwindCSS import
    └── components/
        β”œβ”€β”€ Dashboard.tsx       # Fleet overview + charts
        β”œβ”€β”€ PredictionForm.tsx  # SOH prediction form + gauge
        β”œβ”€β”€ BatteryViz3D.tsx    # 3D battery pack heatmap
        β”œβ”€β”€ GraphPanel.tsx      # Analytics / per-battery graphs
        └── RecommendationPanel.tsx  # Operating condition optimizer

Components

Dashboard

  • Stat cards (battery count, models, best RΒ²)
  • Battery fleet grid with SOH color coding
  • SOH capacity fade line chart (Recharts)
  • Model RΒ² comparison bar chart

PredictionForm

  • 12-input form with all cycle features
  • SOH gauge visualization (SVG ring)
  • Result display with degradation state coloring
  • Confidence interval display

BatteryViz3D

  • 3D battery pack with cylindrical cells
  • SOH-based fill level and color mapping
  • Click-to-inspect with side panel details
  • Auto-rotation with orbit controls
  • Health legend and battery list sidebar

GraphPanel

  • Battery selector dropdown
  • Per-battery SOH trajectory (line chart)
  • Per-battery capacity fade curve
  • Fleet scatter plot (SOH vs cycles, bubble size = temperature)

RecommendationPanel

  • Input: battery ID, current cycle, SOH, temperature, top_k
  • Table of ranked recommendations
  • Shows temperature, current, cutoff voltage, predicted RUL, improvement %

Development

cd frontend
npm install
npm run dev        # http://localhost:5173

API requests are proxied to http://localhost:7860 during development.

Production Build

npm run build      # Outputs to dist/

The built files are served by FastAPI as static assets.