# frisonialessia/nexia-frontend architecture

> Architecture diagram of the GitHub repository frisonialessia/nexia-frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/frisonialessia/nexia-frontend
- Repository: https://github.com/frisonialessia/nexia-frontend

## Overview

#### 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: [`lib/state/fleetStore.ts`](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/fleetStore.ts) (Fleet source selector), [`app/layout.tsx`](https://github.com/frisonialessia/nexia-frontend/blob/main/app/layout.tsx) (Root layout & providers), [`components/Shell.tsx`](https://github.com/frisonialessia/nexia-frontend/blob/main/components/Shell.tsx) (Shell & navigation), [`components/AssetDetail.tsx`](https://github.com/frisonialessia/nexia-frontend/blob/main/components/AssetDetail.tsx) (Operational feature views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shell["App shell"]
  node_layout["Root layout &amp; providers<br/>Next.js root<br/>[layout.tsx]"]
  node_home["Command center route<br/>App Router page<br/>[page.tsx]"]
  node_asset_route["Asset detail route<br/>App Router page<br/>[page.tsx]"]
  node_shell_ui["Shell &amp; navigation<br/>shared UI<br/>[Shell.tsx]"]
end

subgraph group_access["Access context"]
  node_auth_gate["Access gate<br/>view boundary<br/>[AuthGate.tsx]"]
  node_session["Session &amp; roles<br/>client state"]
  node_organization["Organization &amp; plant<br/>client state<br/>[OrgProvider.tsx]"]
end

subgraph group_data["Fleet data"]
  node_fleet_hook{{"Fleet data seam<br/>state hook<br/>[useFleet.ts]"}}
  node_fleet_store["Fleet source selector<br/>state store<br/>[fleetStore.ts]"]
  node_remote_source["Remote REST &amp; WebSocket<br/>backend adapter<br/>[remoteSource.ts]"]
  node_backend_contract["Backend contract<br/>integration contract<br/>[contract.ts]"]
end

subgraph group_domain["Simulation &amp; intelligence"]
  node_simulation[("Simulated fleet source<br/>data source<br/>[simulated.ts]")]
  node_intelligence["Detection &amp; prediction engine<br/>domain engine<br/>[fsm.ts]"]
  node_domain_vocabulary["Domain alerts &amp; types<br/>domain model<br/>[alertas.ts]"]
end

subgraph group_features["Operational features"]
  node_command_center["Command center<br/>fleet view<br/>[CommandCenter.tsx]"]
  node_operations["Operational feature views<br/>feature composition<br/>[AssetDetail.tsx]"]
end

subgraph group_delivery["Cross-cutting delivery"]
  node_app_providers["App providers<br/>cross-cutting state<br/>[AppProviders.tsx]"]
  node_pwa["PWA delivery<br/>offline delivery<br/>[manifest.ts]"]
  node_report_export["Report export<br/>export boundary<br/>[exporter.ts]"]
end

node_layout -->|"installs"| node_app_providers
node_layout -->|"renders"| node_shell_ui
node_shell_ui -->|"hosts route"| node_home
node_home -->|"composes"| node_command_center
node_asset_route -->|"composes"| node_operations
node_auth_gate -->|"reads"| node_session
node_auth_gate -->|"reads"| node_organization
node_shell_ui -->|"guards views"| node_auth_gate
node_command_center -->|"reads fleet"| node_fleet_hook
node_operations -->|"reads fleet"| node_fleet_hook
node_fleet_hook -->|"selects from"| node_fleet_store
node_fleet_store -->|"backend mode"| node_remote_source
node_fleet_store -->|"default &amp; fallback"| node_simulation
node_remote_source -->|"implements"| node_backend_contract
node_simulation -->|"feeds measurements"| node_intelligence
node_intelligence -->|"produces fleet state"| node_fleet_store
node_domain_vocabulary -->|"defines shared model"| node_simulation
node_domain_vocabulary -->|"defines alerts"| node_intelligence
node_app_providers -->|"provides context"| node_organization
node_layout -->|"enables delivery"| node_pwa
node_operations -->|"exports reports"| node_report_export

click node_layout "https://github.com/frisonialessia/nexia-frontend/blob/main/app/layout.tsx"
click node_home "https://github.com/frisonialessia/nexia-frontend/blob/main/app/page.tsx"
click node_asset_route "https://github.com/frisonialessia/nexia-frontend/blob/main/app/activo/%5Bid%5D/page.tsx"
click node_shell_ui "https://github.com/frisonialessia/nexia-frontend/blob/main/components/Shell.tsx"
click node_command_center "https://github.com/frisonialessia/nexia-frontend/blob/main/components/CommandCenter.tsx"
click node_auth_gate "https://github.com/frisonialessia/nexia-frontend/blob/main/components/AuthGate.tsx"
click node_session "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/SessionProvider.tsx"
click node_organization "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/OrgProvider.tsx"
click node_fleet_hook "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/useFleet.ts"
click node_fleet_store "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/fleetStore.ts"
click node_remote_source "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/api/remoteSource.ts"
click node_backend_contract "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/api/contract.ts"
click node_simulation "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/data/simulated.ts"
click node_intelligence "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/engine/fsm.ts"
click node_domain_vocabulary "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/domain/alertas.ts"
click node_operations "https://github.com/frisonialessia/nexia-frontend/blob/main/components/AssetDetail.tsx"
click node_app_providers "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/AppProviders.tsx"
click node_pwa "https://github.com/frisonialessia/nexia-frontend/blob/main/app/manifest.ts"
click node_report_export "https://github.com/frisonialessia/nexia-frontend/blob/main/lib/reports/exporter.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_layout,node_home,node_asset_route,node_shell_ui toneBlue
class node_auth_gate,node_session,node_organization toneAmber
class node_fleet_hook,node_fleet_store,node_remote_source,node_backend_contract toneMint
class node_simulation,node_intelligence,node_domain_vocabulary toneRose
class node_command_center,node_operations toneIndigo
class node_app_providers,node_pwa,node_report_export toneTeal
```

## Components

### App shell

- [Root layout & providers](https://github.com/frisonialessia/nexia-frontend/blob/main/app/layout.tsx): Next.js root · Establishes the shared application shell and client contexts. · `app/layout.tsx`
- [Command center route](https://github.com/frisonialessia/nexia-frontend/blob/main/app/page.tsx): App Router page · `app/page.tsx`
- [Asset detail route](https://github.com/frisonialessia/nexia-frontend/blob/main/app/activo/%5Bid%5D/page.tsx): App Router page · `app/activo/[id]/page.tsx`
- [Shell & navigation](https://github.com/frisonialessia/nexia-frontend/blob/main/components/Shell.tsx): shared UI · `components/Shell.tsx`

### Access context

- [Access gate](https://github.com/frisonialessia/nexia-frontend/blob/main/components/AuthGate.tsx): view boundary · Applies session, role, and organization access before rendering views. · `components/AuthGate.tsx`
- [Session & roles](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/SessionProvider.tsx): client state · `lib/state/SessionProvider.tsx`
- [Organization & plant](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/OrgProvider.tsx): client state · `lib/state/OrgProvider.tsx`

### Fleet data

- [Fleet data seam](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/useFleet.ts): state hook · The sole fleet-data access path for feature views. · `lib/state/useFleet.ts`
- [Fleet source selector](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/fleetStore.ts): state store · Selects remote or simulated fleet data and handles fallback. · `lib/state/fleetStore.ts`
- [Remote REST & WebSocket](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/api/remoteSource.ts): backend adapter · Loads an initial snapshot and applies live updates. · `lib/api/remoteSource.ts`
- [Backend contract](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/api/contract.ts): integration contract · Defines routes, DTOs, socket messages, and commands. · `lib/api/contract.ts`

### Simulation & intelligence

- [Simulated fleet source](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/data/simulated.ts): data source · Default typed source for telemetry and operational states. · `lib/data/simulated.ts`
- [Detection & prediction engine](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/engine/fsm.ts): domain engine · Learns baselines, confirms anomalies, and produces risk predictions. · `lib/engine/fsm.ts`
- [Domain alerts & types](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/domain/alertas.ts): domain model · Shared alert vocabulary, thresholds, and types. · `lib/domain/alertas.ts`

### Operational features

- [Command center](https://github.com/frisonialessia/nexia-frontend/blob/main/components/CommandCenter.tsx): fleet view · `components/CommandCenter.tsx`
- [Operational feature views](https://github.com/frisonialessia/nexia-frontend/blob/main/components/AssetDetail.tsx): feature composition · Asset detail, production, alerts, maintenance, fleet ranking, and charts. · `components/AssetDetail.tsx`

### Cross-cutting delivery

- [App providers](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/state/AppProviders.tsx): cross-cutting state · Manages theme, locale, maintenance, integrations, and admin state. · `lib/state/AppProviders.tsx`
- [PWA delivery](https://github.com/frisonialessia/nexia-frontend/blob/main/app/manifest.ts): offline delivery · Manifest and service-worker registration support installable offline use. · `app/manifest.ts`
- [Report export](https://github.com/frisonialessia/nexia-frontend/blob/main/lib/reports/exporter.ts): export boundary · `lib/reports/exporter.ts`

## Connections

- 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
