AVL Tree Car Front uses Socket.IO for real-time, bidirectional communication with the Python backend. Every event travels through a two-layer architecture:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/avl_tree_car_front/llms.txt
Use this file to discover all available pages before exploring further.
SocketService owns the raw connection, and TreeService extends it with every domain-specific event handler and emitter. Controllers never touch the socket directly — they listen to DOM CustomEvent objects instead.
Namespace
All events belong to theAVLTree namespace. The full socket URL is constructed at startup from configs.urlSOCKET:
TreeService calls super('AVLTree'), the resulting URL becomes http://localhost:4500/AVLTree.
Base class: SocketService
SocketService handles the lowest-level connection concerns. It exposes this.socketio (the raw io() instance) and registers a connect_error handler that logs the error message when the connection is actively denied by the server:
The raw Socket.IO client (
socket.io.min.js) is loaded as a vendored file from src/app/utils/socket-io/ and accessed via the global io function. There is no npm install step.TreeService
TreeService extends SocketService and is the single class that wires every AVL-tree Socket.IO event. Its constructor calls super('AVLTree') and then registers all receive handlers immediately:
TreeService instance is created once inside HomeController.init() and passed down to RoadController and AVLController so every part of the app shares the same underlying socket connection.
Emitted events (front end → backend)
These are events that the front end sends to the Python backend over Socket.IO.| Event name | Method | Payload | Description |
|---|---|---|---|
insert_obstacle | emit_insert_obstacle(data) | Obstacle object { x, y, type } | Insert a new obstacle into the AVL tree |
get_tree_avl | emit_get_tree(data = {}) | {} | Request the current balanced AVL tree |
reset_avl | emit_reset_avl(data = {}) | {} | Reset / clear the AVL tree on the backend |
remove_obstacle | emit_remove_obstacle(data = {}) | {} | Remove an obstacle from the tree |
road_preorder | emit_get_road('preorder') | {} | Request a pre-order traversal |
road_inorder | emit_get_road('inorder') | {} | Request an in-order traversal |
road_posorder | emit_get_road('posorder') | {} | Request a post-order traversal |
road_ to the traversal name:
Received events (backend → front end)
These are events that arrive from the Python backend. Every meaningful event is immediately re-dispatched as a DOMCustomEvent so controllers can react without importing or referencing TreeService directly.
| Socket event | DOM CustomEvent dispatched | detail shape | Description |
|---|---|---|---|
connected | — | — | Backend confirms the Socket.IO connection is established |
disconnected | — | — | Backend confirms the Socket.IO connection was closed |
avl_tree_balanced | avl_tree_balanced | Tree root node object | Full balanced AVL tree for rendering |
preorder | pre-order | Obstacle id (string) | Next node ID in the pre-order traversal sequence |
inorder | in-order | Obstacle id (string) | Next node ID in the in-order traversal sequence |
posorder | pos-order | Obstacle id (string) | Next node ID in the post-order traversal sequence |
avl_reseted | avl_reseted | {} | Confirms the AVL tree was reset on the backend |
obstacles_inserted | — | — | Confirms an obstacle was successfully inserted |
The
connected, disconnected, and obstacles_inserted events are handled silently — connected and disconnected each log a message to the console, while obstacles_inserted has an empty handler. None of the three dispatch DOM events or are consumed by any controller.DOM event bridge pattern
Instead of importingTreeService into every controller, the app uses a pub/sub pattern built on the browser’s own event system. TreeService acts as the sole subscriber to Socket.IO events. For each meaningful event it creates a CustomEvent and dispatches it on document, which any module can listen to without any coupling to the socket layer:
TreeService instance persists for the whole page lifetime.
Code example: on_avl_tree_balanced
The following is the real source of the most important receive handler. It safely falls back to an empty object when the backend sends no payload, then wraps the data in a CustomEvent and dispatches it globally:
AVLController registers its listener on document inside listenGetTreeFromBackend():
Traversal events
The three traversal handlers follow the same bridge pattern. Each receives a single obstacleid from the backend inside ev.data and forwards it as detail on the corresponding DOM event:
WatchRoadsController listens to all three DOM events and calls __focusNodeInRoad(id) to add the current CSS class to the matching SVG circle, creating a step-by-step visual walkthrough of the tree: