How husainbhattiwala/team-chat-application works
Project type and purpose
• This is a full‑stack Next.js 13 web application using the App Router.
• It’s a real‑time chat/collaboration tool with features like user authentication, server & channel management, direct messages, file uploads, and video/audio via LiveKit.
File structure
• app/ – Next.js App Router folders organized by route groups:
• (auth): sign‑in / sign‑up pages
• (invite): join via invite code
• (setup): initial onboarding
• (main): main app UI under servers ➔ channels & conversations
• app/api/ – API route handlers (serverless functions) for channels, messages, servers, members, direct‑messages, LiveKit integration, and UploadThing.
• pages/api/socket/ – a separate Socket.IO endpoint for real‑time websockets.
• components/ – reusable React components (UI primitives, chat, navigation, modals, providers for theme, modal, React Query, socket).
• lib/ – shared utilities: database (Prisma), conversation logic, upload helpers, profile init, general utils.
• prisma/ – database schema (Prisma).
• next.config.js, middleware.ts, tailwind.config.* – build/deploy config.
Main components to model
a. Client (Browser)
• Next.js pages/app components, React, Tailwind, React‑Query, Socket.IO client, LiveKit client, UploadThing JS.
b. Next.js Server
• SSR/SSG rendering, App Router, Middleware, API routes (app/api/**, pages/api).
c. WebSocket Server
• Socket.IO endpoint under pages/api/socket/io.ts handles real‑time events for chat.
d. Business Logic Layer
• lib/db.ts (Prisma client), conversation.ts, uploadthing.ts & other utilities.
e. Database
• PostgreSQL (or other) via Prisma ORM.
f. External Services
• LiveKit – real‑time audio/video rooms
• UploadThing – file storage (S3 or similar)
• (Optional) Vercel platform for deployment
Relationships & data flows
• User → Browser UI → Next.js SSR/CSR → API route → Business Logic → Database → API response → Browser
• Browser ↔ WebSocket Server ↔ Business Logic → Database for real‑time messaging
• Browser → UploadThing SDK → UploadThing backend → Business Logic → Database
• Browser → LiveKit SDK ↔ LiveKit cloud server
Architectural patterns & design principles
• Separation of concerns:
• Presentation (React UI)
• Data fetching & caching (React‑Query)
• Real‑time communication (Socket.IO, LiveKit)
• Business logic & persistence (Prisma)
• Modular route groups using Next.js App Router segments
• Provider pattern for context (theme, modal, socket, query)
• Serverless functions for scale
Elements
• Labels: “Browser UI”, “Next.js SSR/CSR”, “API Routes”, “WebSocket Server”, “Prisma (DB)”, “LiveKit”, “UploadThing”
• Request/response flows for REST APIs
• File upload flow for UploadThing
• Green for serverless functions/API
Final checklist for the engineer
• Break the system into these core components, label clearly
• Data flows for page loads, API calls, socket events, uploads, video streams