Link Chat is a real-time chat application built with NestJS that provides secure, feature-rich communication capabilities. This backend service supports multiple chat features, user authentication, and real-time messaging.
- JWT-based authentication system
- Secure user registration and login
- Password encryption and protection
- Token-based session management
- User profile creation and management
- User status tracking (online/offline)
- User search functionality
- Profile customization options
- Create and manage chat channels
- Public and private channel support
- Channel membership management
- Channel search functionality
- Real-time channel updates
- Real-time message delivery
- Message history storage
- Support for text messages
- Message status tracking
- Message deletion and editing capabilities
- Real-time notification system
- Channel invitation notifications
- Message notifications
- User activity notifications
- Framework: NestJS
- Database: PostgreSQL
- Real-time Communication: WebSockets
- Authentication: JWT (JSON Web Tokens)
- API Style: RESTful + WebSocket
// Example of authentication endpoints
POST /auth/register
Body: {
username: string,
email: string,
password: string
}
POST /auth/login
Body: {
email: string,
password: string
}
// Connect to WebSocket
const socket = new WebSocket('ws://your-server:3000');
// Listen for messages
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
// Handle different message types
};
// Create a channel
POST /channel
Body: {
name: string,
isPrivate: boolean,
members?: string[]
}
// Get channel messages
GET /channel/:channelId/messages
// Join a channel
POST /channel/:channelId/join
// Send a message
POST /message
Body: {
channelId: string,
content: string,
type: 'text'
}
// Delete a message
DELETE /message/:messageId
// Edit a message
PATCH /message/:messageId
Body: {
content: string
}
// Get user profile
GET /user/:userId
// Update user profile
PATCH /user/profile
Body: {
username?: string,
avatar?: string,
status?: string
}
-
Clone the repository
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file with:DATABASE_URL=your_database_url JWT_SECRET=your_jwt_secret PORT=3000
-
Run the development server:
npm run start:dev
All protected routes require a JWT token in the Authorization header:
Authorization: Bearer <your_jwt_token>
message.new
: New message in a channelchannel.update
: Channel updatesuser.status
: User status changesnotification.new
: New notification
message.send
: Send a new messagechannel.join
: Join a channelchannel.leave
: Leave a channeltyping.start
: User started typingtyping.stop
: User stopped typing
The API returns standard HTTP status codes:
- 200: Success
- 201: Created
- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 500: Server Error
Each error response includes:
{
"statusCode": number,
"message": string,
"error": string
}
-
State Management
- Use a state management solution (Redux, MobX, etc.)
- Keep WebSocket connection state
- Cache messages and channels for better performance
-
Real-time Updates
- Implement optimistic updates for better UX
- Handle WebSocket reconnection
- Queue messages when offline
-
Error Handling
- Implement proper error boundaries
- Show user-friendly error messages
- Handle network issues gracefully
-
Security
- Store JWT token securely
- Implement token refresh mechanism
- Sanitize user input
-
Performance
- Implement message pagination
- Cache frequently accessed data
- Use debouncing for real-time events
For any questions or issues, please open an issue in the repository or contact the development team.