How kn9annihilator/cyber-physical-smart-grid-load-balancer works
Project type and purpose
• This is a full-stack IoT dashboard project combining a React/TypeScript single-page application (SPA) with Arduino/ESP8266 firmware.
• Purpose: provide a browser-based UI for monitoring and controlling a “socket sentinel” power outlet; it displays power charts, stats, allows isolation control, and runs simple on-device or in-browser predictions.
File structure
• Top level:
• arduino_code/… contains two firmware projects (socket_sentinel_arduino and socket_sentinel_esp8266)
• package.json, vite.config.ts, tsconfig*.json, tailwind.config.ts, postcss.config.js → front-end build and config
• public/, index.html → static assets for SPA
• src/ → React application source
• Inside src/:
• components/ → presentational UI (AlertsDialog, Header, PowerChart, etc.)
• components/ui/ → shadcn-ui primitives (buttons, cards, dialogs, etc.)
• hooks/ → custom React hooks (use-mobile, use-toast)
• lib/ → business logic and utilities (api.ts, mockData.ts, prediction.ts, utils.ts, types.ts)
• pages/ → router targets (Index, NotFound)
• main.tsx, App.tsx → bootstrapping SPA
• Mock data and api.ts imply the front-end can run without a real backend during development; real device communication lives in firmware.
Key insights from the README
• Built with Vite, TypeScript, React, shadcn-ui, Tailwind CSS.
• No dedicated backend folder—this is a static site that communicates directly with the ESP8266 or uses mocks.
• Deployment via Lovable’s platform or any static host (e.g., Netlify).
a. Main components to show
• Developer workstation & CI/CD pipeline
• Git repository & build system (Vite, Node.js, npm)
• Static hosting / CDN (Lovable / Netlify)
• Client device (web browser)
• React SPA layers: UI components, hooks, business logic (api.ts, prediction.ts)
• IoT device: ESP8266/Arduino firmware – HTTP or WebSocket server, sensor & relay hardware
• (Optional) External services if any (e.g., cloud time server, analytics)
b. Relationships & interactions
• Developer → Git → CI/CD → build assets → deploy to CDN
• Browser → HTTP GET index.html & JS → renders UI → uses api.ts to send HTTP requests (GET/POST) to ESP8266 on local network
• ESP8266 ↔ sensors (current, voltage) & relay → responds with JSON data → browser updates PowerChart, StatsCard
• prediction.ts may process data in-browser or off-device (if firmware provides raw data)
c. Architectural patterns & design principles
• SPA pattern (client-side routing via pages/)
• Component-based UI (atomic + composite components under components/ui and components/)
• Separation of concerns: view layer (components), state & side effects (hooks), business logic (lib/)
• Firmware layering: hardware abstraction → network interface → sensor/control logic
d. Key technologies
• Front-end: React, TypeScript, Vite, Tailwind CSS, shadcn-ui
• Firmware: Arduino framework, ESP8266 Wi-Fi library
• Build: Node.js, npm, bun.lockb (optional runner), ESLint, PostCSS
Detailed capture of essential elements
• UI layer (components/)
• Logic layer (hooks/, lib/)
• Routing (pages/)
• Under firmware: separate “Network Interface”, “Sensor Manager”, “Relay Controller”.
• Which files live in each area (e.g., src/lib/api.ts under Logic layer).