A modern, real-time chat application built with React, TypeScript, Node.js, Express, Socket.IO, and MongoDB. SwiftTalk provides instant messaging, file sharing, friend management, and real-time notifications with a sleek, responsive user interface.
- Real-time Messaging: Instant message delivery using Socket.IO
- File Sharing: Upload and share images, documents, and PDFs with preview functionality
- Friend System: Send/receive friend requests, manage friendships
- Read Receipts: Real-time message read status updates
- Online Status: See when friends are online/offline
- Responsive Design: Mobile-friendly interface with modern UI/UX
- File Preview: Preview files before sending them
- Push Notifications: Browser notifications for new messages
- Typing Indicators: See when friends are typing
- Message History: Persistent chat history with pagination
- React 19 with TypeScript
- React Router for navigation
- Tailwind CSS for styling
- Socket.IO Client for real-time communication
- Axios for HTTP requests
- React Hot Toast for notifications
- Node.js with TypeScript
- Express.js web framework
- Socket.IO for real-time communication
- MongoDB with Mongoose ODM
- JWT for authentication
- Multer for file uploads
- bcryptjs for password hashing
chatApp/
├── client/ # Frontend React application
│ ├── public/
│ │ ├── index.html
│ │ └── favicon.ico
│ ├── src/
│ │ ├── components/ # React components
│ │ │ ├── AddFriend.tsx # Add friend modal
│ │ │ ├── Chat.tsx # Main chat interface
│ │ │ ├── FriendRequests.tsx # Friend requests management
│ │ │ ├── FriendsList.tsx # Friends sidebar list
│ │ │ ├── Login.tsx # Login form
│ │ │ ├── MessageInput.tsx # Message input with file preview
│ │ │ ├── MessageList.tsx # Message display area
│ │ │ └── Signup.tsx # Registration form
│ │ ├── lib/ # Utility libraries
│ │ │ ├── api.ts # Axios HTTP client
│ │ │ ├── auth.ts # Authentication utilities
│ │ │ ├── NotificationService.ts # Browser notifications
│ │ │ └── socket.ts # Socket.IO client setup
│ │ ├── types.ts # TypeScript type definitions
│ │ ├── App.tsx # Main app component
│ │ ├── index.css # Global styles
│ │ ├── main.tsx # React entry point
│ │ └── vite-env.d.ts # Vite type definitions
│ ├── .env # Frontend environment variables
│ ├── eslint.config.js # ESLint configuration
│ ├── index.html # HTML template
│ ├── package.json # Frontend dependencies
│ ├── postcss.config.js # PostCSS configuration
│ ├── tailwind.config.js # Tailwind CSS configuration
│ ├── tsconfig.json # TypeScript configuration
│ ├── tsconfig.node.json # TypeScript Node configuration
│ └── vite.config.ts # Vite build configuration
├── server/ # Backend Node.js application
│ ├── src/
│ │ ├── config/ # Configuration files
│ │ │ ├── config.ts # Application configuration
│ │ │ └── database.ts # MongoDB connection setup
│ │ ├── controllers/ # Route controllers
│ │ │ ├── authController.ts # Authentication endpoints
│ │ │ ├── chatController.ts # Chat/messaging endpoints
│ │ │ └── userController.ts # User management endpoints
│ │ ├── middleware/ # Express middleware
│ │ │ ├── auth.ts # JWT authentication middleware
│ │ │ ├── upload.ts # File upload middleware
│ │ │ └── validation.ts # Request validation middleware
│ │ ├── models/ # MongoDB schemas
│ │ │ ├── Friendship.ts # Friend relationship model
│ │ │ ├── Message.ts # Chat message model
│ │ │ └── User.ts # User account model
│ │ ├── routes/ # API route definitions
│ │ │ ├── authRoutes.ts # Authentication routes
│ │ │ ├── chatRoutes.ts # Chat/messaging routes
│ │ │ └── userRoutes.ts # User management routes
│ │ ├── services/ # Business logic layer
│ │ │ ├── authService.ts # Authentication logic
│ │ │ ├── chatService.ts # Chat/messaging logic
│ │ │ └── userService.ts # User management logic
│ │ ├── socket/ # Socket.IO handlers
│ │ │ └── socketHandlers.ts # Real-time event handlers
│ │ ├── utils/ # Utility functions
│ │ │ ├── jwt.ts # JWT token utilities
│ │ │ ├── password.ts # Password hashing utilities
│ │ │ └── response.ts # API response utilities
│ │ ├── types/ # TypeScript definitions
│ │ │ └── index.ts # Shared type definitions
│ │ ├── app.ts # Express app configuration
│ │ └── server.ts # Server entry point
│ ├── uploads/ # File upload storage
│ ├── .env # Backend environment variables
│ ├── package.json # Backend dependencies
│ ├── setup-database.js # Database initialization script
│ └── tsconfig.json # TypeScript configuration
└── README.md # This file
- Node.js (v18 or higher)
- MongoDB (v5.0 or higher)
- npm or yarn
- Navigate to the server directory:
cd server- Install dependencies:
npm install- Create
.envfile in the server directory:
# Server Configuration
PORT=5000
NODE_ENV=development
# Database
MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/<database>
DB_NAME=chatapp
# JWT
JWT_SECRET=your-super-secure-jwt-secret-key
JWT_EXPIRES_IN=7d
# File Upload
MAX_FILE_SIZE=5242880
ALLOWED_FILE_TYPES=image/jpeg,image/png,image/gif,application/pdf,text/plain
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100
# CORS
CLIENT_URL=http://localhost:3000- Set up the database (optional - creates indexes and test data):
node setup-database.js --with-test-data- Start the development server:
npm run devThe server will start on http://localhost:5000
- Navigate to the client directory:
cd client- Install dependencies:
npm install- Create
.envfile in the client directory:
VITE_API_BASE_URL=http://localhost:5000
VITE_SOCKET_URL=http://localhost:5000- Start the development server:
npm run devThe client will start on http://localhost:3000
POST /register- Register new userPOST /login- User loginPOST /logout- User logoutGET /me- Get current userPUT /profile- Update user profilePUT /change-password- Change passwordPOST /refresh-token- Refresh JWT tokenGET /verify- Verify JWT token
GET /search- Search usersGET /:userId- Get user by IDGET /username/:username- Get user by usernameGET /friends/list- Get friends listGET /friends/with-messages- Get friends with last messagesGET /friends/online- Get online friendsPOST /friends/request- Send friend requestGET /friends/requests/pending- Get pending requestsGET /friends/requests/sent- Get sent requestsPUT /friends/requests/:requestId/accept- Accept friend requestPUT /friends/requests/:requestId/decline- Decline friend requestDELETE /friends/:friendId- Remove friendPOST /:userId/block- Block userGET /:userId/friendship-status- Get friendship statusGET /stats- Get user statisticsPUT /online-status- Update online status
POST /messages- Send text messagePOST /messages/file- Send file messageGET /history/:userId- Get chat historyPUT /messages/:userId/read- Mark messages as readGET /unread-count- Get unread countDELETE /messages/:messageId- Delete messageGET /messages/search- Search messagesGET /rooms- Get chat roomsGET /messages/:messageId- Get message by IDPOST /upload- Upload fileGET /users/:userId/online- Get user online status
authenticate- Authenticate socket connectionsend_message- Send a messagemark_messages_read- Mark messages as readtyping_start- Start typing indicatortyping_stop- Stop typing indicatorupdate_online_status- Update online status
authenticated- Authentication successfulauth_error- Authentication failednew_message- New message receivedmessages_read- Messages marked as readmessage_sent- Message sent confirmationmessage_error- Message sending failedfriend_status_update- Friend online status changeduser_typing- User typing indicator
npm run dev- Start development server with hot reloadnpm run build- Build for productionnpm start- Start production servernpm run lint- Run ESLintnpm run type-check- Run TypeScript type checking
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production buildnpm run lint- Run ESLintnpm run type-check- Run TypeScript type checking
SwiftTalk uses Socket.IO for instant message delivery. Messages are sent via WebSocket when possible, falling back to HTTP polling if needed. The app handles connection failures gracefully and queues messages when offline.
Users can upload and share various file types:
- Images (JPEG, PNG, GIF, WebP) with inline preview
- Documents (PDF, DOC, DOCX, TXT)
- Maximum file size: 10MB
- Files are stored on the server with secure access controls
- Send friend requests by username
- Accept/decline incoming requests
- View sent requests with cancel option
- Remove friends
- Block/unblock users
- JWT-based authentication
- Password hashing with bcrypt
- Rate limiting on all endpoints
- File upload validation
- XSS protection with Helmet.js
- CORS configuration
- Message pagination for chat history
- Debounced friend search
- Optimistic UI updates
- Memoized React components
- Efficient database queries with indexes
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with React and Express
- Real-time communication powered by Socket.IO
- Database management with MongoDB and Mongoose
- UI styling with Tailwind CSS
- File handling with Multer
SwiftTalk - Connect instantly, chat effortlessly.