How sujal8976/rtchat works
Main System Components
A. Client Layer
• Next.js Frontend (apps/web)
• WebSocket Client Connection
• Zustand State Management
• Authentication Flow
B. Server Layer
• Next.js API Routes (HTTP Server)
• WebSocket Server (apps/ws)
• Authentication Service
C. Database Layer
• PostgreSQL Database
• Prisma ORM
Detailed Component Breakdown
Frontend Components (apps/web):
• Authentication components (login/register)
• Chat interface (messages, rooms, members)
• Sidebar and navigation
• Real-time communication handlers
Backend Services:
• WebSocket Server components:
• Connection handler
• Message service
• Room service
• Authentication service
Database Schema:
• Main entities:
• Users
• Rooms
• Messages
• Room memberships
Connection Flows
a. Authentication Flow:
User -> Next.js API -> Auth Service -> Database
b. Real-time Communication Flow:
Client -> WebSocket Connection -> WS Server -> Database
• > Broadcast to Room Members
c. Room Management Flow:
Client -> HTTP API -> Database
• > WebSocket -> Room Service
Specific Implementation Details
Architectural patterns:
• Singleton WebSocket connections
• Debouncing for API calls
• Infinite scroll implementation
• Database indexing
• State management flow
Technical Specifications
• Next.js 13+ (App Router)
• WebSocket (ws library)
• PostgreSQL
• Prisma ORM
• Zustand
• TailwindCSS
• NextAuth