How vista-iot/frontend-dashboard works
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