# vista-iot/frontend-dashboard architecture

> Architecture diagram of the GitHub repository vista-iot/frontend-dashboard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vista-iot/frontend-dashboard
- Repository: https://github.com/vista-iot/frontend-dashboard

## Overview

##### Project type and purpose
- Vista IoT is a full-stack, monolithic web application built on Next.js (using the app/ directory), React, and TypeScript.
- Its purpose is to serve as a configuration portal for industrial IoT gateways: a user logs into a web UI to discover, register, configure, and monitor remote IoT devices (Ethernet/Wi-Fi interfaces, firewall rules, industrial protocols, MQTT settings, etc.).

##### File structure
- Top-level “app/” folder: Next.js 13+ App Router—pages, layout.tsx, server / client components, API routes under app/api.
- “components/”: hundreds of React UI components (dialogs, forms, tabs, onboarding widgets, network graph, Monaco editor wrapper), organized by feature.
- “hooks/”: custom hooks for responsiveness and toast notifications.
- “lib/”: Prisma client (lib/prisma.ts), YAML/config loaders, a comprehensive config module, Zustand-based client store.
- “prisma/”: schema.prisma, migrations, dev.db indicating a relational database (SQLite in dev, likely Postgres in prod).
- Config and deployment script at app/api/deploy-config/route.ts—Next.js API route for pushing configuration to physical gateways.
- Styles: Tailwind CSS + Radix UI primitives.

##### Extract additional insights from the README
- The app flow is already diagrammed: Landing → Onboarding → Dashboard → Tabbed sub‐views.
- Data‐flow from User ↔ Web UI ↔ API Layer ↔ Device Manager ↔ IoT Devices, with a shared Configuration Store (DB).
- Key libraries: Prisma (DB), Zustand (state), React Hook Form + Zod (forms & validation), React Flow/Force Graph/Recharts (visualization), Monaco (code editor).

a. Main components / layers
- Presentation Layer (Client Browser)
– Next.js pages & React components (app/page.tsx, components/*)
– UI modules: Onboarding flow, Dashboard tabs, Forms & Dialogs, Network graph & charts
- Application Layer (Next.js Server & API)
– SSR/SSG entrypoints + API routes (app/api/*), including “deploy-config”
– Business logic: Device discovery/registration, configuration orchestration
- Data Layer
– Prisma ORM → Relational Database (dev.db / Postgres)
– YAML/JS-YAML parser and comprehensive-config.ts for snapshot import/export
- Device Communication Layer
– Device Manager service (could be a Next.js API service or external microservice)
– Handles push/pull of config via SSH/HTTP/MQTT to actual industrial gateways
- External Services
– Industrial protocol simulators (in testing), e.g. ModbusPal, HiveMQ, open62541, OpenDNP3
– Docker registry (for containerized deployment)
b. Relationships and data flows
- User ↔ HTTP(S) ↔ Next.js UI (SSR + CSR)
- UI ↔ REST/JSON API routes ↔ Business Logic → Prisma → Database
- API → DeviceManager → IoT Gateway devices (over MQTT, HTTP, SSH, industrial protocols)
- Config import/export: UI exports YAML → lib/config → user downloads; UI imports YAML → lib/config → DB
- Background state: Zustand store hydrates from backend on page load
c. Architectural patterns & design principles
- Layered (Presentation → Application → Data → Device)
- Component-based UI (React + Radix + Tailwind)
- API-first design (Next.js API routes as BFF)
- Declarative form handling (React Hook Form + Zod)
- State management separation (Zustand store decouples UI from direct API calls)
- Infrastructure as code (YAML snapshots + “deploy-config” endpoint)
- Next.js (App Router, server functions, API routes)
- React, TypeScript, Tailwind, Radix UI, Lucide
- Prisma ORM + relational DB
- Zustand, React Hook Form, Zod
- ReactForceGraph, ReactFlow, Recharts, Monaco Editor
- YAML/JS-YAML

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User interaction
    User["User"]:::user
    User -->|"HTTPS / HTTP"| UI

    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        UI["Next.js UI\n(app/layout.tsx)"]:::frontend
        Landing["Landing Pages\n(app/page.tsx)"]:::frontend
        OnboardingPage["Onboarding Page\n(app/onboarding/page.tsx)"]:::frontend
        Styles["Global Styles\n(app/globals.css, styles/globals.css,\n tailwind.config.js, postcss.config.mjs)"]:::frontend

        subgraph "React Components"
            direction TB
            Sidebar["Sidebar & Navigation\n(components/sidebar-nav.tsx)"]:::frontend
            Tabs["Tabs Components\n(components/tabs/*.tsx)"]:::frontend
            OnboardingLayout["Baremetal Device Layout\n(components/onboarding/baremetal-device-layout.tsx)"]:::frontend
            DeviceCard["Device Card\n(components/onboarding/device-card.tsx)"]:::frontend
            DiscoveryDialog["Device Discovery Dialog\n(components/onboarding/device-discovery-dialog.tsx)"]:::frontend
            RegistrationDialog["Device Registration Dialog\n(components/onboarding/device-registration-dialog.tsx)"]:::frontend
            OnboardingDashboard["Onboarding Dashboard\n(components/onboarding/onboarding-dashboard.tsx)"]:::frontend
            ConfigPanel["Device Configuration Panel\n(components/device-configuration-panel.tsx)"]:::frontend
            Dialogs["Dialogs\n(components/dialogs/*.tsx)"]:::frontend
            Forms["Forms & Validation\n(components/forms/*.tsx)"]:::frontend
            NetworkGraph["Network Graph\n(components/network-graph.tsx)"]:::frontend
            MonacoEditor["Monaco Editor Wrapper\n(components/monaco-editor.tsx)"]:::frontend
            Charts["Charts\n(components/ui/chart.tsx)"]:::frontend
            UIPrimitives["UI Primitives\n(components/ui/*.tsx)"]:::frontend
            ThemeProvider["Theme Provider\n(components/theme-provider.tsx)"]:::frontend
        end

        subgraph "State & Hooks"
            direction TB
            UseMobile["useMobile Hook\n(hooks/use-mobile.tsx)"]:::frontend
            UseToast["useToast Hook\n(hooks/use-toast.tsx)"]:::frontend
            UseHydrate["useHydrateConfigFromBackend\n(hooks/useHydrateConfigFromBackend.ts)"]:::frontend
            ZustandStore["Zustand Store\n(lib/stores/configuration-store.ts)"]:::frontend
        end
    end

    UI --> Sidebar
    UI --> Tabs
    UI --> OnboardingLayout
    UI --> DeviceCard
    UI --> DiscoveryDialog
    UI --> RegistrationDialog
    UI --> OnboardingDashboard
    UI --> ConfigPanel
    UI --> Dialogs
    UI --> Forms
    UI --> NetworkGraph
    UI --> MonacoEditor
    UI --> Charts
    UI --> UIPrimitives
    UI --> ThemeProvider
    UI --> UseMobile
    UI --> UseToast
    UI --> UseHydrate
    UI --> ZustandStore

    %% API / Business Logic Layer
    subgraph "API / Business Logic Layer"
        direction TB
        DeployAPI["Deploy-Config API\n(app/api/deploy-config/route.ts)"]:::api
    end

    UI -->|"REST JSON"| DeployAPI

    %% Data Persistence Layer
    subgraph "Data Persistence Layer"
        direction TB
        PrismaClient["Prisma Client\n(lib/prisma.ts)"]:::data
        DB["Relational Database\n(prisma/dev.db / Postgres)"]:::data
        Schema["Prisma Schema & Migrations\n(prisma/schema.prisma,\n prisma/migrations/*)"]:::data
    end

    DeployAPI --> PrismaClient
    PrismaClient --> DB
    PrismaClient --> Schema

    %% Configuration Import/Export
    subgraph "Config Import/Export"
        direction TB
        YAMLLoader["Comprehensive Config\n(lib/config/comprehensive-config.ts,\n default-config.ts,\n comprehensive-config.yaml)"]:::data
        ExportDialog["Export Config Dialog\n(components/dialogs/export-config-dialog.tsx)"]:::frontend
        ImportDialog["Import Config Dialog\n(components/dialogs/import-config-dialog.tsx)"]:::frontend
    end

    UI --> ExportDialog
    UI --> ImportDialog
    ExportDialog --> YAMLLoader
    ImportDialog --> YAMLLoader
    YAMLLoader --> DB

    %% Device Communication Layer
    subgraph "Device Communication Layer"
        direction TB
        DeviceManager["Device Manager Service"]:::device
        Protocols["Protocols: MQTT, HTTP, SSH,\n Modbus, DNP3, OPC-UA"]:::device
        IoTDevices["IoT Gateway Devices"]:::device
    end

    DeployAPI --> DeviceManager
    DeviceManager --> Protocols
    Protocols --> IoTDevices

    %% Utilities
    Utils["Utilities\n(lib/utils.ts)"]:::util
    UI --> Utils
    DeployAPI --> Utils

    %% Click Events
    click UI "https://github.com/vista-iot/frontend-dashboard/blob/main/app/layout.tsx"
    click Landing "https://github.com/vista-iot/frontend-dashboard/blob/main/app/page.tsx"
    click OnboardingPage "https://github.com/vista-iot/frontend-dashboard/blob/main/app/onboarding/page.tsx"
    click Styles "https://github.com/vista-iot/frontend-dashboard/blob/main/app/globals.css"
    click Styles "https://github.com/vista-iot/frontend-dashboard/blob/main/styles/globals.css"
    click Styles "https://github.com/vista-iot/frontend-dashboard/blob/main/tailwind.config.js"
    click Styles "https://github.com/vista-iot/frontend-dashboard/blob/main/postcss.config.mjs"
    click Sidebar "https://github.com/vista-iot/frontend-dashboard/blob/main/components/sidebar-nav.tsx"
    click Tabs "https://github.com/vista-iot/frontend-dashboard/tree/main/components/tabs"
    click OnboardingLayout "https://github.com/vista-iot/frontend-dashboard/blob/main/components/onboarding/baremetal-device-layout.tsx"
    click DeviceCard "https://github.com/vista-iot/frontend-dashboard/blob/main/components/onboarding/device-card.tsx"
    click DiscoveryDialog "https://github.com/vista-iot/frontend-dashboard/blob/main/components/onboarding/device-discovery-dialog.tsx"
    click RegistrationDialog "https://github.com/vista-iot/frontend-dashboard/blob/main/components/onboarding/device-registration-dialog.tsx"
    click OnboardingDashboard "https://github.com/vista-iot/frontend-dashboard/blob/main/components/onboarding/onboarding-dashboard.tsx"
    click ConfigPanel "https://github.com/vista-iot/frontend-dashboard/blob/main/components/device-configuration-panel.tsx"
    click Dialogs "https://github.com/vista-iot/frontend-dashboard/tree/main/components/dialogs"
    click Forms "https://github.com/vista-iot/frontend-dashboard/tree/main/components/forms"
    click NetworkGraph "https://github.com/vista-iot/frontend-dashboard/blob/main/components/network-graph.tsx"
    click MonacoEditor "https://github.com/vista-iot/frontend-dashboard/blob/main/components/monaco-editor.tsx"
    click Charts "https://github.com/vista-iot/frontend-dashboard/blob/main/components/ui/chart.tsx"
    click UIPrimitives "https://github.com/vista-iot/frontend-dashboard/tree/main/components/ui"
    click ThemeProvider "https://github.com/vista-iot/frontend-dashboard/blob/main/components/theme-provider.tsx"
    click UseMobile "https://github.com/vista-iot/frontend-dashboard/blob/main/hooks/use-mobile.tsx"
    click UseToast "https://github.com/vista-iot/frontend-dashboard/blob/main/hooks/use-toast.tsx"
    click UseHydrate "https://github.com/vista-iot/frontend-dashboard/blob/main/hooks/useHydrateConfigFromBackend.ts"
    click ZustandStore "https://github.com/vista-iot/frontend-dashboard/blob/main/lib/stores/configuration-store.ts"
    click DeployAPI "https://github.com/vista-iot/frontend-dashboard/blob/main/app/api/deploy-config/route.ts"
    click PrismaClient "https://github.com/vista-iot/frontend-dashboard/blob/main/lib/prisma.ts"
    click DB "https://github.com/vista-iot/frontend-dashboard/blob/main/prisma/dev.db"
    click Schema "https://github.com/vista-iot/frontend-dashboard/blob/main/prisma/schema.prisma"
    click YAMLLoader "https://github.com/vista-iot/frontend-dashboard/blob/main/lib/config/comprehensive-config.ts"
    click ExportDialog "https://github.com/vista-iot/frontend-dashboard/blob/main/components/dialogs/export-config-dialog.tsx"
    click ImportDialog "https://github.com/vista-iot/frontend-dashboard/blob/main/components/dialogs/import-config-dialog.tsx"
    click Utils "https://github.com/vista-iot/frontend-dashboard/blob/main/lib/utils.ts"

    %% Styles
    classDef user fill:#f9f,stroke:#333,stroke-width:1px
    classDef frontend fill:#bbdefb,stroke:#1976d2,stroke-width:2px
    classDef api fill:#c8e6c9,stroke:#388e3c,stroke-width:2px
    classDef data fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px
    classDef device fill:#e1bee7,stroke:#7b1fa2,stroke-width:2px
    classDef util fill:#e0e0e0,stroke:#757575,stroke-width:1px
```
