This file tracks all completed features, architectural decisions, and the step-by-step roadmap for building the Discord Clone.
- Frontend & API (Port 3000): Next.js App Router (React 19, Tailwind CSS v4, Clerk Auth, Prisma ORM, PostgreSQL).
- Socket Server (Port 3001): Standalone Socket.io server (
socket-server/index.ts) managing rooms and real-time broadcasts. - Hybrid Communication Pattern:
- Client sends messages to Next.js API (
/api/messages). - Next.js validates user session via Clerk (
currentProfile) and writes to PostgreSQL via Prisma. - Next.js triggers the socket server via internal HTTP POST (
/emit). - Socket server broadcasts the event to all users connected to the channel/conversation room.
- Client sends messages to Next.js API (
# Terminal 1: Run Next.js Frontend & Backend API
npm run dev
# Terminal 2: Run Socket Server
npm run socket- Authentication: Clerk setup with
currentProfile&initialProfileutilities. - Database Schema: Prisma schema configured with PostgreSQL (Profiles, Servers, Channels, Members, Messages, Conversations, DirectMessages).
- Server Management: Create Server, Edit Server, Delete Server, Leave Server, and Invite modals.
- Channel Management: Create Channel, Edit Channel, and Delete Channel modals.
- Member Management: Role management (Guest / Moderator / Admin) & Kick Member actions.
- Navigation & Layouts: Server sidebar, Channel/Member list, Action tooltips, and Mobile drawer sheet.
- Conversation Helpers:
lib/conversation.tsfor finding/creating 1-on-1 DM conversations.
- TanStack Query Setup: Installed
@tanstack/react-queryand createdQueryProvider. - Socket Server Enhancement:
socket-server/index.tswith room management (join-room,leave-room) and/emitbroadcast endpoint. - Socket Client Provider:
SocketProvidercontext trackingisConnectedstatus. - Socket Status Indicator:
SocketIndicatorbadge inChatHeader(shows Live: Real-time or Fallback: Polling). - Emoji Picker:
EmojiPickerpopover using@emoji-mart/reactand theme matching. - Chat Input:
ChatInputcomponent with message submission, emoji insertion, and upload trigger. - Message API Handler:
app/api/messages/route.tssupportingGET(cursor pagination) andPOST(saves to DB and emits socket broadcast).
-
useChatQueryhook: Fetch historical messages in batches of 10 using TanStackuseInfiniteQuery. -
useChatSockethook: Listen for real-time socket events (addKey,updateKey) and update the Query cache dynamically without page reload. -
useChatScrollhook: Handle auto-scrolling to bottom on new messages and preserving scroll position when reading past messages. -
ChatWelcomecomponent: Display channel welcome header ("Welcome to #general"). -
ChatItemcomponent: Render individual message bubbles with user avatar, timestamp, role badge, file preview, edit button, and delete button. -
ChatMessagescomponent: Combine all hooks and components to render the full message feed in text channels.
- Edit Message: Inline editing directly inside
ChatItemwith Escape/Enter shortcuts and/api/messages/[messageId]PATCH handler. - Delete Message:
DeleteMessageModalconfirmation and/api/messages/[messageId]DELETE handler (soft delete). - Attachment Upload:
MessageFileModalto upload images/PDFs in chat via UploadThing.
- DM API Route:
app/api/direct-messages/route.ts(cursor-paginatedGETand authenticatedPOST). - DM Chat View: Connect
ChatMessagesandChatInputintoservers/[serverId]/conversations/[memberId]/page.tsx. - DM Editing & Deleting: Handle update/delete socket broadcasts for direct conversations (
app/api/direct-messages/[directMessageId]/route.ts).
- LiveKit Integration: Token generation API route (
app/api/livekit/route.ts). -
MediaRoomcomponent: Audio/video grid, mute/unmute, screen share, and video toggle button in header.
- Mobile responsive layout testing & UX polish.
- Error handling & loading skeletons.