Skip to content

Menzorg/nest-kafka-postgres-websocket-chat-prototype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

44 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Enterprise-grade Real-time Chat System

An open-source, production-ready, scalable real-time chat application built with modern event-driven architecture.

Built with: NestJS, Next.js, Apache Kafka, PostgreSQL, Redis, Socket.io

MIT License Docker Ready Event Driven


๐ŸŒŸ Why This Project?

This is not just another chat demo - it's a production-ready foundation for building scalable real-time applications.

Perfect for:

  • ๐ŸŽฎ Gaming platforms (in-game chat, guilds, parties)
  • ๐Ÿ’ผ Business apps (team collaboration, customer support)
  • ๐ŸŒ Social networks (messaging, communities)
  • ๐Ÿซ Educational platforms (virtual classrooms, Q&A)
  • ๐Ÿค– AI applications (chatbots, assistants, agents)

What makes it different:

  • โœ… Event-driven architecture with Kafka (not just WebSocket!)
  • โœ… Horizontal scalability out of the box
  • โœ… Redis adapter for multi-instance WebSocket sync
  • โœ… Complete feature set (pinning, forwarding, presence, rate limiting)
  • โœ… Analytics & audit logging built-in
  • โœ… Well-documented and easy to extend

๐Ÿš€ Quick Start

Want to get started in under 5 minutes? โ†’ โšก QUICKSTART GUIDE

TL;DR

# Clone the repo
git clone <repo-url>
cd nest-kafka-postgres-websocket-chat-prototype

# Start everything
docker-compose up -d --build

# Access the app
# Frontend: http://localhost:3000
# Backend:  http://localhost:4000

That's it! ๐ŸŽ‰

Current Features (Implemented Scenarios)

1. User Authentication & Registration

  • โœ… User signup with email, name, and password
  • โœ… User login with email and password
  • โœ… JWT token-based authentication
  • โœ… Persistent authentication (token stored in localStorage)

2. User Presence Management

  • โœ… Real-time online/offline status tracking powered by Redis
  • โœ… Automatic status updates on connection/disconnection
  • โœ… Visual indicators for user availability
  • โœ… Multi-device support (tracks all user's sockets)
  • โœ… Last seen timestamp tracking
  • โœ… Scalable presence across multiple server instances

3. Real-Time Messaging

  • โœ… Send text messages in real-time
  • โœ… Receive messages instantly via WebSocket
  • โœ… Message persistence in PostgreSQL database
  • โœ… Auto-scrolling to latest messages

4. Message Delivery Status

  • โœ… Sent (โœ“) - Message sent to server
  • โœ… Delivered (โœ“โœ“) - Message delivered to recipient's device
  • โœ… Read (โœ“โœ“โœ“) - Message read by recipient (click on message to mark as read)

5. Chat Room Management

  • โœ… Create private chat between two users
  • โœ… Join/leave chat rooms
  • โœ… Automatic room creation on first message
  • โœ… Chat history persistence

6. WebSocket Integration

  • โœ… Real-time bidirectional communication
  • โœ… Automatic reconnection on connection loss
  • โœ… Connection status indicators
  • โœ… Room-based message broadcasting

7. Backend Architecture

  • โœ… NestJS modular architecture
  • โœ… TypeORM with PostgreSQL for data persistence
  • โœ… Redis for caching, sessions, and user presence
  • โœ… Kafka event-driven architecture for async processing
  • โœ… 21 Kafka topics for different event types
  • โœ… Real-time analytics through Kafka streams
  • โœ… Audit logging for all user actions
  • โœ… Notification system via Kafka events
  • โœ… Socket.io for real-time communication with Redis adapter
  • โœ… JWT-based WebSocket authentication
  • โœ… Rate limiting with Redis
  • โœ… Message caching for performance

TODO: Missing Chat Scenarios

High Priority Features

1. Message Pinning

  • Pin important messages to chat top
  • Unpin messages
  • Display pinned messages section
  • Sync pinned messages across devices
  • Maximum pinned messages limit (configurable)

2. Message Forwarding

  • Forward messages to other chats/users
  • Forward multiple messages at once
  • Include original sender information
  • Forward with additional comment

3. Message Editing & Deletion

  • Edit sent messages within time limit
  • Show "edited" indicator
  • Delete messages for self
  • Delete messages for everyone
  • Message edit history

4. Message Search

  • Search messages by content
  • Search by sender
  • Search by date range
  • Jump to message in chat
  • Highlight search results

Medium Priority Features

5. Message Reactions/Emojis

  • React to messages with emojis
  • Multiple reactions per message
  • Custom emoji support
  • Reaction notifications
  • Most used emojis section

6. Group Chats

  • Create group chats with multiple users
  • Add/remove participants
  • Group admins and permissions
  • Group info and settings
  • Leave group functionality

7. Typing Indicators

  • Show when user is typing
  • Multiple users typing in group
  • Typing timeout handling
  • Optimize typing event frequency

8. Message Threading/Replies

  • Reply to specific messages
  • Quote messages
  • Thread view for conversations
  • Thread notifications
  • Jump to original message

9. Message Encryption

  • End-to-end encryption
  • Key exchange protocol
  • Encrypted file sharing
  • Backup encryption keys
  • Security indicators

10. Chat Customization

  • Custom chat backgrounds
  • Theme selection (dark/light/custom)
  • Font size adjustment
  • Notification sounds
  • Chat color schemes

11. Advanced Notifications

  • Push notifications
  • Email notifications
  • Notification preferences
  • Do not disturb mode
  • Notification grouping

Low Priority Features

12. File & Media Sharing

  • Send images (JPEG, PNG, GIF)
  • Send documents (PDF, DOCX, etc.)
  • Send videos with preview
  • Send voice messages
  • File size limitations
  • Image compression & thumbnails
  • Download progress indicators

13. Voice & Video Calls

  • One-on-one voice calls
  • One-on-one video calls
  • Group calls
  • Screen sharing
  • Call history
  • WebRTC integration

14. Message Scheduling

  • Schedule messages for later
  • Recurring messages
  • Edit scheduled messages
  • Cancel scheduled messages
  • Timezone handling

15. Message Translation

  • Auto-detect language
  • Translate messages on demand
  • Preferred language settings
  • Original message preservation

16. Chat Backup & Export

  • Export chat history
  • Backup to cloud
  • Import chat history
  • Multiple export formats (JSON, CSV, PDF)

17. User Blocking & Reporting

  • Block users
  • Report inappropriate content
  • Blocked users list
  • Moderation queue
  • Auto-moderation rules

18. Message Templates & Quick Replies

  • Save message templates
  • Quick reply suggestions
  • Canned responses
  • Template categories
  • Keyboard shortcuts

19. Location Sharing

  • Share current location
  • Share live location
  • Location history
  • Map integration
  • Privacy controls

20. Read Receipts Controls

  • Disable read receipts
  • Disable typing indicators
  • Privacy settings per user
  • Last seen status control

Architecture

Frontend

  • Next.js 13+ with App Router
  • React Hooks for state management
  • Socket.io client for WebSocket
  • Tailwind CSS for styling

Backend

  • NestJS framework
  • PostgreSQL with TypeORM
  • Redis for caching, sessions, and presence
  • Apache Kafka for message queue
  • Socket.io for real-time events
  • JWT authentication

Database Schema

  • Users table
  • Messages table
  • Chats table
  • Chat participants junction table

Development

Prerequisites

  • Docker & Docker Compose
  • Node.js 18+
  • PostgreSQL
  • Redis
  • Apache Kafka

Environment Variables

See .env.example files in both packages/backend and packages/frontend directories.

Testing

# Backend tests
cd packages/backend
npm test

# Frontend tests
cd packages/frontend
npm test

๐Ÿ“š Documentation

Comprehensive documentation is available in the /doc directory:

๐Ÿค Contributing

This is an open-source project and contributions are welcome!

How to Contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Implement a feature from the TODO list
  4. Add tests for new functionality
  5. Update documentation
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Development Guidelines:

  • Follow existing code style and conventions
  • Write unit and integration tests
  • Update documentation for new features
  • Keep commits atomic and descriptive
  • Add your feature to the completed list in README

Good First Issues:

Check out issues labeled good-first-issue for beginner-friendly tasks!

๐ŸŒŸ Show Your Support

If you find this project useful:

  • โญ Star the repository
  • ๐Ÿด Fork it for your own projects
  • ๐Ÿ“ข Share it with others
  • ๐Ÿ› Report bugs and suggest features
  • ๐Ÿ’ฌ Contribute code or documentation

๐Ÿ“„ License

MIT License - feel free to use this project for any purpose, commercial or personal.

See LICENSE file for details.


Built with โค๏ธ for the open-source community

Ready to scale from MVP to millions of users. Start building today!

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •