FDA

Project 1 - Admin Panel

Admin Panel - Chat System

The Admin Panel includes a role-based live chat system with real-time updates via Server-Sent Events (SSE).

Overview

  • Admins: Can start chats with any user or instructor.
  • Instructors: Can chat with students enrolled in their courses.
  • Users: Can view and reply to chats with admins or instructors.

Database

Run the chat migration:

psql -d your_database -f supabase/migrations/add-chat-system.sql

Tables

  • chat_rooms: Room type (admin_user, admin_instructor, instructor_student), participant IDs, optional course_id, last message time, unread counts per participant.
  • chat_messages: Room ID, sender ID, message text, read status, created_at.

Accessing chat

  • Open Chat in the app (typically /chat).
  • Admins: create or open rooms with users/instructors.
  • Instructors: create or open rooms with enrolled students (optionally scoped by course).
  • Users: see rooms they’re in and reply.

Real-time behavior

  • SSE: Messages are pushed via Server-Sent Events so new messages appear without refresh.
  • Endpoints are typically under /api/chat/ (e.g. rooms list, messages for a room, stream for a room, mark as read, unread count).

API (typical)

  • List rooms: GET /api/chat/rooms (filtered by role).
  • List users to start chat (admin): GET /api/chat/users.
  • Messages for a room: GET /api/chat/rooms/[roomId]/messages.
  • Stream (SSE): GET /api/chat/rooms/[roomId]/stream.
  • Mark read: POST /api/chat/rooms/[roomId]/read or similar.
  • Unread count: GET /api/chat/unread-count.

Implementation notes

  • Rooms are created on first message or via “Start chat” (admin/instructor).
  • Unread counts are updated when messages are read via the read API.
  • Reconnection logic on the client keeps the SSE stream active after short network drops.

For exact request/response shapes and UI flows, see CHAT_SYSTEM.md in the admin-panel repo.

Previous
Payments & Razorpay