Okay, let's break down the comprehensive "TeleChat" prompt into smaller, more manageable parts. This allows for a phased approach to development, tackling features incrementally.
Part 1: Core Setup, Authentication & Basic Profiles
Goal: Establish the foundational project structure, user authentication, and basic user profiles.
Prompt:
"Build the foundational structure for a real-time chat application named 'TeleChat' using React (with TypeScript) for the frontend and a Node.js/Express.js backend with PostgreSQL database and Redis for caching/session management.
Frontend Requirements:
- Set up a new React project using Vite or Create React App with TypeScript.
- Implement routing using React Router v6.
- Set up state management (e.g., Redux Toolkit or Zustand).
- Style the application using Tailwind CSS.
- Create basic UI components for Login, Registration, and a placeholder for the main chat interface.
Backend Requirements:
- Set up a Node.js/Express.js server.
- Integrate Prisma (or Sequelize) as the ORM for PostgreSQL.
- Implement user registration (username, email, password) and login endpoints.
- Secure endpoints using JWT authentication. Hash passwords using bcrypt.
- Create a User model with fields:
id, username, email, passwordHash, displayName, bio, avatarUrl.
- Implement basic profile viewing endpoint (get user by ID/username).
- Set up basic Redis connection.
Features:
- User Registration: Ability to create a new account.
- User Login: Ability to log in with credentials.
- Basic User Profile: Display username, display name, and bio (initially static, later editable).
- Secure Authentication: JWT generation and validation for protected routes."
Part 2: Real-time 1-on-1 Chat & Presence
Goal: Implement the core real-time messaging functionality for direct chats and user online status.
Prompt:
"Extend the 'TeleChat' application to support real-time one-on-one (1-on-1) private messaging and user presence tracking.
Frontend Requirements:
- Develop the Chat List interface: Display recent conversations with user avatars, display names, last message snippet, and timestamp.
- Implement the Chat Window component: Display messages sequentially, input field for typing messages, send button.
- Integrate Socket.IO Client to connect to the backend WebSocket server.
- Display messages in real-time as they are received.
- Send messages to the backend via WebSocket.
- Implement a visual indicator for user online/offline status next to their name in the chat list and profile.
Backend Requirements:
- Set up a Socket.IO server integrated with the Express app.
- Manage WebSocket connections and disconnections.
- Implement user presence logic: When a user connects/disconnects, broadcast their status to relevant connected users (contacts). Use Redis to store online status efficiently.
- Create API endpoints for:
- Fetching chat history for a specific 1-on-1 conversation.
- Creating a new 1-on-1 chat if one doesn't exist.
- Implement WebSocket event handlers for:
- Receiving new messages from clients.
- Broadcasting received messages to the intended recipient(s).
- Handling typing indicators ('User is typing...').
- Database Schema: Add
Chats table (for 1-on-1 and groups) and Messages table (linking to Chats and Users).
Features:
- Real-time 1-on-1 Messaging: Send and receive text messages instantly.
- Chat History: Fetch and display past messages in a conversation.
- User Presence: See if contacts are online or offline.
- Typing Indicators: Show when another user is typing in a 1-on-1 chat."
Part 3: Group Chats & Basic Media Sharing (Photos)
Goal: Introduce group chat functionality and the ability to share photos.
Prompt:
"Add support for Group Chats and the ability to share photos in 'TeleChat'.
Frontend Requirements:
- Create UI for Group creation: Name, description, profile picture upload.
- Modify Chat List to accommodate groups.
- Update Chat Window to handle messages within groups, displaying sender's name.
- Implement photo upload functionality:
- File input for selecting images.
- Display image preview before sending.
- Send image data via WebSocket or a dedicated API endpoint.
- Display received photos within the chat window with thumbnails.
- Implement basic group member management UI (viewing members).
Backend Requirements:
- Update
Chats table schema to support group properties (name, description, group PFP).
- Create
GroupMembers table to manage user associations with groups.
- Implement API endpoints for:
- Creating new group chats.
- Adding/removing users from groups (initial basic implementation).
- Fetching group details and members.
- Modify WebSocket logic to broadcast messages to all members of a group.
- Implement file upload handling:
- Integrate with a cloud storage solution (AWS S3, Google Cloud Storage, or MinIO) for storing media.
- Generate secure URLs for uploaded media.
- Update
Messages table to include media attachment URLs and types.
- Handle broadcasting of image messages to group members.
Features:
- Create Group Chats: Users can create groups and invite others.
- Group Messaging: Send and receive text messages in groups.
- Photo Sharing: Upload and send photos; display received photos."
Part 4: Advanced Messaging Features & UI Polish
Goal: Implement essential message interactions like editing, deleting, forwarding, replies, reactions, and improve the overall chat UI.
Prompt:
"Enhance 'TeleChat' with advanced message interactions and refine the user interface for a richer experience.
Frontend Requirements:
- Implement message actions:
- Reply: Allow users to quote and reply to specific messages.
- Forward: Enable forwarding messages to other chats.
- Edit: Add functionality to edit sent text messages (with an 'edited' label).
- Delete: Implement options to delete messages (for self, potentially for everyone).
- Add message reactions: Allow users to react to messages with emojis.
- Implement pinned messages: Ability to pin a message to the top of a chat.
- Refine the Chat Window UI:
- Display read receipts (sent/delivered/read ticks).
- Show sender's name and timestamp clearly for each message.
- Add scroll-to-bottom functionality and potentially virtualized scrolling for long chat histories.
- Implement a basic emoji picker component.
Backend Requirements:
- Update
Messages table schema: Add fields for replyToMessageId, isEdited, deletedAt, reactions.
- Implement backend logic for:
- Handling message edits (update message, broadcast update).
- Handling message deletions (mark as deleted, broadcast update).
- Storing and retrieving message reactions.
- Storing pinned message references per chat.
- Implement logic for sending/delivering/reading receipts via WebSockets.
Features:
- Message Reply, Edit, Delete, Forward.
- Emoji Reactions to Messages.
- Pinned Messages.
- Read Receipts (Sent, Delivered, Read).
- Integrated Emoji Picker."
Part 5: Channels, More Media Types & Enhanced Groups
Goal: Introduce channel functionality, support for audio messages and file sharing, and enhance group administration.
Prompt:
"Add Channels, support for audio messages and file sharing, and enhance Group Chat administration in 'TeleChat'.
Frontend Requirements:
- Channels:
- Implement UI for creating public/private channels.
- Display channels in the chat list.
- Channel interface: Similar to groups, but with admin-only posting capabilities.
- Media Sharing:
- Audio Messages: Implement voice recording functionality, sending, and playback within chats.
- File Sharing: Allow uploading and sending arbitrary file types (documents, archives, etc.), display file name, size, and download progress.
- Group Enhancements:
- Implement UI for group admins to assign/remove other admins.
- Add functionality for group admins to ban/kick members.
- Implement "Slow Mode" feature for groups.
- Implement Unread Message Count indicators.
Backend Requirements:
- Channels:
- Create
Channels and ChannelSubscribers tables.
- Implement API endpoints for channel creation, subscription/unsubscription, and posting messages.
- Update WebSocket logic for broadcasting to channel subscribers.
- Media Sharing:
- Update
Messages table to support audio attachments and generic file attachments (type, name, size).
- Ensure backend handles uploading and serving audio files and generic files.
- Group Enhancements:
- Add
isAdmin flag or role management to GroupMembers.
- Implement API endpoints and WebSocket logic for:
- Admin promotion/demotion.
- Member banning/unbanning.
- Implementing "Slow Mode" logic (rate limiting messages per user in a group).
- Implement notification logic for unread message counts.
Features:
- Channels: Create and manage public/private broadcast channels.
- Audio Messaging: Record and send voice messages.
- File Sharing: Send and receive any file type.
- Group Administration: Admin roles, banning, slow mode."
Part 6: Privacy, Security & Notifications
Goal: Implement privacy controls, security features like 2FA, and robust notification handling.
Prompt:
"Implement advanced privacy controls, security features like Two-Factor Authentication (2FA), and notification enhancements for 'TeleChat'.
Frontend Requirements:
- Profile Settings:
- Add options to set "Last Seen" privacy (Everyone, My Contacts, Nobody).
- Implement a placeholder UI for enabling/disabling 2FA.
- Implement a local App Passcode lock feature (frontend-only).
- Notifications:
- Implement browser push notifications for new messages when the app is in the background.
- Add in-app notification banners/toasts for mentions or new messages while browsing other chats.
- User Management:
- Implement a "Block User" feature.
- Implement a basic contact list view.
Backend Requirements:
- Privacy Settings:
- Add
lastSeenPrivacy field to the User model. Implement logic to enforce visibility based on this setting.
- 2FA:
- Implement TOTP-based 2FA generation and verification (requires libraries like
speakeasy). Store 2FA secret securely (encrypted).
- Add endpoints for enabling/disabling 2FA.
- Blocking:
- Create a
Blocks table (blockerId, blockedId). Implement logic to prevent blocked users from messaging each other.
- Notifications:
- Implement a mechanism for sending push notifications (e.g., using
web-push library for browser notifications).
- Generate notification payloads based on events (new message, mention).
- Contact Management:
- Implement API endpoints for adding/removing contacts (simulated, perhaps via username).
Features:
- Last Seen Privacy Settings.
- Two-Factor Authentication (TOTP).
- App Passcode Lock (Client-side).
- Browser Push Notifications & In-app Notifications.
- User Blocking & Contact Management."
Part 7: Search, Scalability & Deployment Prep
Goal: Implement search functionality, address performance optimizations, and prepare for deployment.
Prompt:
"Integrate search capabilities across chats and users, focus on performance optimizations, and prepare 'TeleChat' for deployment.
Frontend Requirements:
- Global Search: Implement a search bar that allows users to find other users, groups, and channels by username/name.
- Chat Search: Implement search functionality within a specific chat's history.
- UI/UX Polish:
- Implement dark/light mode toggle.
- Add basic responsiveness for different screen sizes.
- Optimize loading states and error handling across the application.
- Performance: Implement techniques like code splitting, lazy loading components, and potentially virtualized lists for very long chat histories/lists.
Backend Requirements:
- Search Implementation:
- Optimize database queries for searching users, groups, and channels efficiently. Consider adding full-text search capabilities if needed.
- Implement backend logic for searching within chat histories.
- Scalability & Performance:
- Review and optimize WebSocket event handling for potentially thousands of concurrent connections.
- Implement efficient pagination for fetching chat history and lists.
- Optimize database indexing.
- Consider connection pooling for database access.
- Deployment Preparation:
- Create Dockerfiles for frontend and backend applications.
- Create a
docker-compose.yml file to orchestrate the frontend, backend, database, and Redis services for local development.
- Ensure environment variables are used for configuration.
Features:
- Global User/Chat/Group Search.
- Search within Chat History.
- Dark/Light Mode.
- Basic Responsiveness.
- Performance Optimizations (Code Splitting, Pagination, Indexing).
- Containerization with Docker & Docker Compose."
Part 8: Bonus Features (Optional/Advanced)
Goal: Outline potential advanced features for future development.
Prompt:
"Consider the following advanced features for future development of 'TeleChat', focusing on expanding functionality beyond the core requirements.
Potential Features:
- Voice & Video Calls: Integrate WebRTC for real-time peer-to-peer voice and video communication (1-on-1 and group).
- Secret Chats (E2E): Implement end-to-end encryption for specific 'secret' chat types, ensuring messages are only readable by sender and receiver. This requires careful handling of cryptographic keys.
- Bots API: Design and implement a simplified API framework that allows developers to create and interact with bots within the chat application.
- Scheduled Messages: Allow users to schedule messages to be sent at a future date and time.
- Topic-based Groups: Implement support for distinct discussion topics within large group chats, similar to recent Telegram features.
- Polls: Add functionality for creating and participating in polls within groups and channels.
- Location Sharing: Implement real-time location sharing features.
- Message Forwarding Chains: Track the origin of forwarded messages.
- Sticker Sets: Implement management and sending of custom sticker sets."
By breaking it down like this, you can focus on delivering functional increments, making the overall project much more approachable.