Real-time chat system built with TypeScript, Express, Socket.IO, and MongoDB.
- ✨ JWT Authentication
- 💬 Real-time chat rooms
- 📱 Online/Offline status
- 🔒 Private messaging
- ⌨️ Typing indicators
- 📜 Message history
- 🔍 Room listing
- 👥 User management
- Node.js (v14 or higher)
- MongoDB
- NPM or Yarn
- Clone the repository
git clone https://github.com/Erickzao/chatlive.git
cd chat-live- Install dependencies
npm install
# or
yarn install- Set up environment variables
cp .env.example .envEdit the .env file with your settings
- Start the server
# Development
npm run dev
# Production
npm run build
npm start| Variable | Description | Example |
|---|---|---|
| PORT | Server port | 3000 |
| MONGODB_URI | MongoDB connection URI | mongodb://localhost:27017/chat-live |
| JWT_SECRET | JWT secret key | your_jwt_secret_here |
| JWT_EXPIRATION | Token expiration time | 24h |
POST /api/users/register- Register userPOST /api/users/login- LoginPOST /api/users/logout- LogoutGET /api/users/me- Get current user data
POST /api/rooms- Create roomGET /api/rooms- List roomsGET /api/rooms/:id- Room detailsPOST /api/rooms/:id/join- Join roomPOST /api/rooms/:id/leave- Leave room
POST /api/messages- Send messageGET /api/messages/room/:roomId- Room messagesGET /api/messages/private- Private messagesPATCH /api/messages/:messageId/read- Mark as read
// Join a room
socket.emit('join_room', { roomId: string });
// Send message
socket.emit('send_message', {
roomId: string,
content: string
});
// Indicate typing
socket.emit('typing', {
roomId: string,
isTyping: boolean
});// Receive message
socket.on('receive_message', (data: {
message: string,
senderId: string,
timestamp: Date
}) => {});
// User typing
socket.on('user_typing', (data: {
userId: string,
isTyping: boolean
}) => {});- JWT Authentication
- Input sanitization
- XSS Protection
- Rate limiting
- Data validation
- Password encryption
# Run tests
npm test
# Test coverage
npm run test:coveragesrc/
├── config/ # Configuration
├── controllers/ # Controllers
├── entities/ # Models
├── middlewares/ # Middlewares
├── routes/ # Routes
└── index.ts # Entry point
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add: amazing feature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
- Your Name - @Erickzao