How waccit/unified-red works
Project type and purpose
• unified-red is a full-stack Node.js application that extends Node-RED with a customizable building-automation HMI (human-machine interface) dashboard.
• It bundles:
• A set of custom Node-RED nodes (in the nodes/ folder) for alarms, data-logging, charts, forms, widgets, etc.
• A backend API (in api/ ) exposing REST controllers, WebSocket endpoints, and database services.
• A modern Angular 9+ frontend (in src/app/ ) that runs at /ui for the live dashboard.
• Static assets (in static/ and src/assets/) for CSS, JS, images, fonts.
File-structure highlights and implied architecture
• Top level:
• index.js (entry point) & monitor.js (heartbeat to external monitor server)
• admin-auth.js (Node-RED editor authentication)
• socket.js (WebSocket server attached to Node-RED/Express)
• api/: Express-style controllers (alarm.controller.js, audit.controller.js, etc.), services, models (both mongoose & sequelize variants), db configuration, error handler, email service.
• nodes/: Node-RED node definitions (.html + .js) — these are loaded by Node-RED at runtime.
• src/: Angular application source (components, services, routing).
• static/: served as the httpStatic folder by Node-RED for custom web files.
• Configuration files: api/config.json(default), Angular config (angular.json), Node-RED settings inferred in README.
Key README insights
• Backend supports MongoDB or SQL (via mongoose or sequelize).
• Dashboard is served at /ui; Node-RED editor at /admin.
• Authentication with JWT, multi-user, roles, password reset through smtp.
• Real-time updates via WebSocket.
• External integrations: SMTP email, PagerDuty alerts, heartbeat to remote monitor server.
a. Main components
• Client browser — loads Angular SPA (served at /ui)
• Node-RED & Express server — single Node.js process hosting:
– Node-RED runtime & editor (editor at /admin)
– Unified-RED dashboard plugin (Angular SPA + custom Node-RED nodes)
– Express REST API endpoints (/api/…)
– WebSocket server (socket.js)
– Static file server (static/ folder)
• Database(s) — MongoDB or SQL (Postgres/MySQL/etc.)
• External services: SMTP server, PagerDuty API, remote monitor server
• Custom Node-RED nodes (nodes/) interacting via Node-RED message bus
b. Relationships & interactions
1. Browser ↔ HTTP(S): Angular SPA ↔ Express REST API for CRUD (users, alarms, data logs, scheduling).
2. Browser ↔ WebSocket: real-time push for alarm console, charts, notifications.
3. Express services ↔ Database: via mongoose or sequelize ORM layers.
4. Node-RED flows ↔ custom nodes: widget nodes that forward messages to UI via WebSocket.
5. Express email.service ↔ SMTP for password reset.
6. Express PagerDuty integration ↔ PagerDuty API.
7. monitor.js ↔ remote monitor server (heartbeat).
c. Architectural patterns & design principles
• Layered architecture: UI, API, business logic (services), data access (ORM), persistence.
• Plugin/extensibility: custom Node-RED nodes are dropped into the runtime.
• Real-time event streaming via WebSocket.
• Config-driven: config.json and Node-RED settings.js drive behavior (DB, JWT secret, httpStatic).
• MVC-style grouping in API (controllers → services → models).
• SPA frontend organized by feature modules (authentication, dashboard, node-templates, users).
d. Key technologies/frameworks
• Node.js & Express (server)
• Node-RED (runtime & editor)
• Angular 9+ & Bootstrap 4 (SPA)
• Mongoose (MongoDB) & Sequelize (SQL)
• WebSocket (socket.io or native ws via socket.js)
• SMTP (nodemailer) for email
• External APIs (PagerDuty)
• Gulp & npm scripts for build; Angular CLI for SPA build