How neutron-robotics/neutron-web works
Project type and purpose
• From the README and file tree, this is a React + TypeScript front-end client (“Neutron Web”) for the Neutron robotics platform. It is not a full end-to-end stack (no server code here), but it interacts with multiple backend microservices (auth, graph, robot, ROS2, organization, analytics) and provides real-time control and monitoring of robots.
File structure
• Top-level: Dockerfile, docker-compose.yml, Vite config, Cypress & Jest tests, public/ (static assets, documentation, legal markdown).
• src/:
• api/: HTTP clients for various backend endpoints (admin, auth, graph, robot, ros2, …) and shared models.
• components/: modular UI elements, grouped by domain (Admin, Connection, Neutron graph editor, Organization, Robot, Settings, controls).
• contexts/: React Context providers (Auth, Alert, Connection, Theme, Graph).
• utils/: general-purpose helpers (async hooks, Elasticsearch, time, thumbnail generation).
• views/: page-level components (Login, Home, Connection, Neutron graph, Robot view, Settings, etc.).
• index.tsx + App.tsx: application entry point & top-level router.
README for additional insights
• It highlights “real-time control” and “analytics” over robotics solutions.
• Users authenticate, then connect to a robot and build “graphs” of operations.
• It points to external docs (cgu/privacy, component templates) under public/assets.
a. Main components:
• User’s Browser / Mobile Device
• Static Asset Host (CDN or static server serving Vite‐built JS/CSS/HTML)
• React Application
– UI Components
– Context Providers (Auth, Alert, Connection, Graph)
– Neutron Graph Editor (canvas, nodes, side panels)
• API Layer (HTTP clients in src/api)
– Auth Service
– Graph Service (save/load graphs)
– Robot Service (list robots, parts, status)
– ROS2 Service (topics, publishers, subscribers, actions)
– Analytics Service
– Organization & Admin Services
• Real-Time/Streaming Service (WebSocket or Server-Sent Events for robot telemetry & control)
• External Systems
– Robot hardware & ROS2 back-end
– ElasticSearch / Kibana for logs & analytics
– CI/CD (GitHub Actions, Docker registry)
b. Relationships and interactions:
• Browser loads React app from the Static Asset Host.
• React App on startup uses AuthContext to call Auth Service → receives JWT.
• Subsequent Graph/Robot/API calls use JWT in HTTP headers.
• Upon “Connect to Robot,” App opens WebSocket to Real-Time Service, routes data through ConnectionContext.
• Neutron Graph Editor reads/writes flows via Graph Service and renders nodes.
• UI triggers actions (publish/subscribe) through ROS2 Service REST endpoints or via WebSocket.
• Analytics events/warnings/errors are sent to Analytics Service or ElasticSearch.
c. Architectural patterns & principles:
• Componentized UI (atomic to composite) in React.
• Context API for cross-cutting concerns (auth, alerts, theme, real-time connection).
• Clear separation: Presentation (views + components) vs. Data (api clients, contexts) vs. Utilities.
• Single-Page Application with client-side routing (RouteManager).
• Dependency Injection-like pattern in Neutron Graph Editor via ComponentFactory.
d. Key technologies:
• React + TypeScript + Vite
• React Context + Hooks
• Axios or Fetch (in src/api)
• WebSocket (for real-time robot control)
• Cypress (component + e2e testing) and Jest
• Docker + docker-compose for local dev