Backend

From Rsewiki

Backend

Introduction

The backend of the Robot Dashboard is responsible for managing communication between the frontend and the Robobot. It is developed using Node.js and Express, with MQTT handling communication with the robot and Socket.IO providing real-time updates to the frontend.

The backend acts as an intermediary between the robot and the web application, processing incoming robot data and forwarding relevant information to the dashboard.

The backend consists of several files and components, each serving a specific purpose. Some files can be modified to customize the dashboard's functionality, while others contain core functionality and should generally remain unchanged to ensure the system operates correctly.

This section provides an overview of the backend architecture, its file structure, and guidelines for configuring and modifying the system.

Backend Architecutre

The backend of the Robot Dashboard is built using Node.js and Express and acts as a communication layer between the Robobot and the frontend application.

The architecture consists of three main components:

  1. Express: Handles HTTP requests, including user authentication and session management.
  2. MQTT: Enables communication between the backend and the Tuype robot through a publish-subscribe messaging system.
  3. Socket.IO: Establishes real-time, bidirectional communication between the backend and frontend, allowing robot data to be displayed without manually refreshing the page.

Communication Flow

The backend acts as an intermediary between the frontend and Robobot.

  1. The Robobot publishes data to specific MQTT topics through an MQTT broker.
  2. The backend subscribes to relevant topics and receives incoming robot data.
  3. The backend processes the received messages and forwards relevant information to the frontend using Socket.IO.
  4. The frontend receives these updates and displays them in the corresponding dashboard widgets.

For interactions that require sending information or commands to the robot, the communication can also work in the opposite direction, with the backend publishing messages to the appropriate MQTT topics.

Model-View-Controller

The Robot Dashboard was designed using the Model–View–Controller (MVC) architectural pattern to separate the application's user interface, application logic, and communication handling.

The architecture consists of three main components:

  • Model: Represents the backend logic and is responsible for processing data and managing the application's functionality.
  • View: Represents the frontend user interface, where users can interact with the dashboard and visualize real-time robot data.
  • Controller: Acts as an intermediary between the Model, View, and Tuype robot. It handles communication through REST APIs, Socket.IO, and MQTT, as well as session management.

When a user interacts with the dashboard, the input is sent from the View to the Controller. The Controller processes the request and communicates with the Model when application logic or data processing is required.

For robot-related interactions, the Controller communicates with the Tuype robot through MQTT. The robot publishes data to MQTT topics, which the backend subscribes to and forwards to the frontend through Socket.IO.

The Controller is also responsible for sending updates back to the View, allowing the dashboard to display real-time information without requiring the user to refresh the page.

Authentication and Session Management

The backend implements a password-based authentication system to restrict access to the Robot Dashboard.

User authentication is handled through Express, where the provided password is verified against a stored password hash using bcrypt. Upon successful authentication, a session is established using express-session

The session is maintained through a cookie, allowing the backend to recognize authenticated users across subsequent requests without requiring them to log in repeatedly.

The current implementation uses a single shared password rather than individual user accounts.

Backend Codebase Overview

The backend of the Robot Dashboard is organized into several directories and files, each serving a specific purpose in the application's functionality.

The structure separates API handling, MQTT communication, security, and real-time communication into different files. This organization helps developers navigate the codebase, identify relevant files, and understand where modifications may be required.

The following section provides an overview of the backend directory structure and the responsibilities of its main components.

Configuration and Customization

Core files and Restrictions

Running the backend