How frisonialessia/nexia-frontend works
Purpose and runtime
NEXIA is a Next.js 14 industrial predictive-maintenance frontend: it presents fleet health, anomaly risk, maintenance, OEE, alerts, and financial impact. It runs as a TypeScript/Tailwind App Router application, deployable to Vercel, with TanStack Query-backed client data access. Local operation defaults to typed simulation; REST/WebSocket backend integration is optional.
Key roots: app/layout.tsx, app/providers.tsx, app/page.tsx.
Routing and application shell
App Router pages are thin route entry points that compose feature views. The primary operational surfaces are the command center, asset detail, production, alerts, maintenance, reports, assistant, and administration/configuration. Global layout/providers establish the shared shell, navigation, PWA behavior, and client contexts.
Paths: app/page.tsx, app/activo/[id]/page.tsx, components/Shell.tsx, components/CommandCenter.tsx, components/Nav.tsx.
Access and organizational context
Authentication/session state, roles, organization/plant context, and access denial are client-side boundaries around views. Supported roles include administrator, plant manager, technician, operator, and read-only. This layer should remain independent of individual page data implementations.
Paths: components/AuthGate.tsx, components/AccessDenied.tsx, lib/state/SessionProvider.tsx, lib/state/OrgProvider.tsx, lib/permissions.ts.
Fleet data seam and live integration
Views must read fleet data through state hooks, not directly from simulated or remote sources. useFleet and the fleet store select the active source. In backend mode, the adapter obtains an initial REST snapshot and subscribes to live WebSocket updates; failures fall back automatically to simulated data. The backend contract is the authoritative integration boundary for routes, DTOs, socket messages, and commands.
Paths: lib/state/useFleet.ts, lib/state/fleetStore.ts, lib/api/remoteSource.ts, lib/api/contract.ts, lib/api/mappers.ts.
Simulation and domain intelligence
The default source simulates fleet telemetry and operational states. Pure engine/domain modules turn measurements into baseline learning, hysteretic detection, anomaly confirmation, risk/failure-range predictions, fleet ordering, and alert explainability. Domain types and constants provide the shared vocabulary and thresholds across source, store, and UI.
Paths: lib/data/simulated.ts, lib/engine/fsm.ts, lib/engine/frecuencias.ts, lib/domain/alertas.ts, lib/types.ts.
Operational feature composition
Feature components consume the data seam to render fleet-level KPIs/events, machine detail, OEE/production, alert audit/history, and maintenance workflows. Dashboard-specific “pro” modules supply sortable fleet cards, health map, event stream, and executive reporting. Reusable charts and primitives keep visualization separate from domain logic.
Paths: components/AssetDetail.tsx, components/Production.tsx, components/Alertas.tsx, components/Maintenance.tsx, components/pro/SortableFleet.tsx, components/ui/VibrationChart.tsx.
Cross-cutting state and delivery
Providers manage theme, locale, maintenance, integrations, and admin state. Internationalization supports Spanish/English; formatting handles metric/imperial conversions. The app includes manifest, icon, offline route, and service-worker registration for PWA delivery. Reports export through a dedicated boundary, and the assistant has a separate response module.
Paths: lib/state/AppProviders.tsx, lib/state/I18nProvider.tsx, lib/format.ts, app/manifest.ts, components/PwaRegister.tsx, lib/reports/exporter.ts.
Main entry points: fleetStore.ts Fleet source selector · layout.tsx Root layout & providers · Shell.tsx Shell & navigation · AssetDetail.tsx Operational feature views
Components 19
App shell
- Root layout & providers · Establishes the shared application shell and client contexts.
app/layout.tsx - Command center route
app/page.tsx - Asset detail route
app/activo/[id]/page.tsx - Shell & navigation
components/Shell.tsx
Access context
- Access gate · Applies session, role, and organization access before rendering views.
components/AuthGate.tsx - Session & roles
lib/state/SessionProvider.tsx - Organization & plant
lib/state/OrgProvider.tsx
Fleet data
- Fleet data seam · The sole fleet-data access path for feature views.
lib/state/useFleet.ts - Fleet source selector · Selects remote or simulated fleet data and handles fallback.
lib/state/fleetStore.ts - Remote REST & WebSocket · Loads an initial snapshot and applies live updates.
lib/api/remoteSource.ts - Backend contract · Defines routes, DTOs, socket messages, and commands.
lib/api/contract.ts
Simulation & intelligence
- Simulated fleet source · Default typed source for telemetry and operational states.
lib/data/simulated.ts - Detection & prediction engine · Learns baselines, confirms anomalies, and produces risk predictions.
lib/engine/fsm.ts - Domain alerts & types · Shared alert vocabulary, thresholds, and types.
lib/domain/alertas.ts
Operational features
- Command center
components/CommandCenter.tsx - Operational feature views · Asset detail, production, alerts, maintenance, fleet ranking, and charts.
components/AssetDetail.tsx
Cross-cutting delivery
- App providers · Manages theme, locale, maintenance, integrations, and admin state.
lib/state/AppProviders.tsx - PWA delivery · Manifest and service-worker registration support installable offline use.
app/manifest.ts - Report export
lib/reports/exporter.ts
Connections 21
- Root layout & providers → App providers: installs
- Root layout & providers → Shell & navigation: renders
- Shell & navigation → Command center route: hosts route
- Command center route → Command center: composes
- Asset detail route → Operational feature views: composes
- Access gate → Session & roles: reads
- Access gate → Organization & plant: reads
- Shell & navigation → Access gate: guards views
- Command center → Fleet data seam: reads fleet
- Operational feature views → Fleet data seam: reads fleet
- Fleet data seam → Fleet source selector: selects from
- Fleet source selector → Remote REST & WebSocket: backend mode
- Fleet source selector → Simulated fleet source: default & fallback
- Remote REST & WebSocket → Backend contract: implements
- Simulated fleet source → Detection & prediction engine: feeds measurements
- Detection & prediction engine → Fleet source selector: produces fleet state
- Domain alerts & types → Simulated fleet source: defines shared model
- Domain alerts & types → Detection & prediction engine: defines alerts
- App providers → Organization & plant: provides context
- Root layout & providers → PWA delivery: enables delivery
- Operational feature views → Report export: exports reports