🏗️ Architecture

WebSocket & Real-Time Architecture

Real-time communication using Socket.IO for live updates and notifications.

Overview

Gauzy uses Socket.IO for real-time features:

  • Live time tracker status updates
  • Instant notifications
  • Real-time dashboard data
  • Team activity feeds

Architecture

Diagram; its source is available below
Diagram source
graph TB
    C1[Client 1] <-->|Socket.IO| GW[WebSocket Gateway]
    C2[Client 2] <-->|Socket.IO| GW
    GW --> Redis[(Redis Adapter)]
    GW --> Auth[JWT Authentication]

Gateway Setup

@WebSocketGateway({
  cors: { origin: "*" },
  namespace: "/ws",
})
export class NotificationGateway implements OnGatewayConnection {
  @WebSocketServer()
  server: Server;

  handleConnection(client: Socket) {
    const user = this.validateToken(client.handshake.auth.token);
    client.join(`tenant:${user.tenantId}`);
  }

  @SubscribeMessage("start-timer")
  handleStartTimer(client: Socket, data: any) {
    this.server.to(`tenant:${data.tenantId}`).emit("timer-started", data);
  }
}

Events

EventDirectionDescription
timer-startedServer → ClientEmployee started timer
timer-stoppedServer → ClientEmployee stopped timer
screenshot-takenServer → ClientNew screenshot available
notificationServer → ClientNew notification
task-updatedServer → ClientTask status changed

Redis Adapter (Multi-Instance)

For multi-server deployments, WebSocket events are broadcast through Redis:

import { createAdapter } from "@socket.io/redis-adapter";

const pubClient = new Redis(config.redis);
const subClient = pubClient.duplicate();
server.adapter(createAdapter(pubClient, subClient));

Client Connection

import { io } from "socket.io-client";

const socket = io("wss://api.example.com/ws", {
  auth: { token: "jwt-token" },
});

socket.on("notification", (data) => {
  console.log("New notification:", data);
});

Edit this page

Copyright © 2023-Present Ever Co. LTD.Docs by Sourcey