Skip to content

AI-powered real-time chat app with semantic message search using vector embeddings, Pinecone, and WebSockets.

Notifications You must be signed in to change notification settings

MaxAnii/MindChat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

91 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  MindChat - Real-Time Chat Application

A modern, feature-rich real-time messaging platform built with React, Node.js, Express, and WebSocket technology. MindChat enables seamless communication with advanced authentication, intelligent messaging, and scalable infrastructure.


๐Ÿš€ Main Feature: AI-Powered Semantic Search

Intelligent message discovery powered by Vector Embeddings & Pinecone

MindChat's flagship feature is its advanced semantic search capability that goes beyond simple keyword matching. Using cutting-edge AI technology:

  • ๐Ÿค– Vector-Based Intelligence - Messages are automatically converted into semantic embeddings using transformers
  • ๐Ÿ” Intelligent Retrieval - Find messages by meaning, not just keywords. Search "happy moments" and get all positive conversations
  • โšก Pinecone Integration - Lightning-fast vector similarity search across millions of messages
  • ๐Ÿ’ก Context-Aware Results - Understand the intent behind your search query
  • ๐ŸŽฏ Smart Recommendations - Get personalized message suggestions based on conversation patterns

How It Works:

  1. Every message sent is automatically indexed with semantic embeddings
  2. Search queries are converted to the same vector space
  3. Pinecone computes similarity scores to find the most relevant messages
  4. Results are ranked by semantic relevance, not just text matching

โœจ Key Features

๐Ÿ” Authentication & Security

  • โœ… Magic Link Authentication - Secure passwordless login via email
  • โœ… Google OAuth Integration - Quick sign-up with Google accounts
  • โœ… JWT-Based Sessions - Secure token management with refresh tokens
  • โœ… Email Verification - Verification tokens for account validation
  • โœ… Rate Limiting - Protection against brute force and abuse

๐Ÿ’ฌ Real-Time Messaging

  • โœ… WebSocket Communication - Instant message delivery using Socket.IO
  • โœ… Live Direct Messaging - One-on-one private conversations
  • โœ… Contact Management - Add and manage contacts easily
  • โœ… Message History - Persistent message storage in PostgreSQL
  • โœ… Real-time Status Updates - See when users are online/offline

๐Ÿค– Intelligent Features โญ PRIMARY

  • โœ… AI-Powered Semantic Search - โญ CORE FEATURE - Vector-based intelligent search using Pinecone and AI embeddings
  • โœ… Message Indexing - Automatic conversion of messages to semantic embeddings
  • โœ… Meaning-Based Retrieval - Find messages by context and intent, not just keywords
  • โœ… Smart Recommendations - Contextual suggestions based on messaging patterns and conversation semantics
  • โœ… User Search - Find and connect with other users using semantic understanding

๐Ÿ—๏ธ Architecture & Scalability

  • โœ… Kafka Message Queue - Asynchronous message processing with Apache Kafka
  • โœ… Redis Caching - High-performance caching layer for sessions and data
  • โœ… PostgreSQL Database - Reliable and scalable relational database
  • โœ… Docker Support - Containerized deployment for easy scaling
  • โœ… Prisma ORM - Type-safe database operations

๐ŸŽจ User Interface

  • โœ… Modern React UI - Built with Vite for fast development
  • โœ… Shadcn/UI Components - Beautiful, accessible UI components
  • โœ… Responsive Design - Works seamlessly on desktop and mobile
  • โœ… Tailwind CSS - Utility-first styling framework
  • โœ… Dark Mode Support - Eye-friendly interface themes

๐Ÿ“ง Communication

  • โœ… Email Notifications - Send emails via Resend/Nodemailer
  • โœ… Magic Link Emails - Beautiful HTML email templates
  • โœ… Real-time Email Updates - Instant notification delivery

๐Ÿ› ๏ธ Tech Stack

Backend

Technology Purpose
Node.js Runtime environment
Express.js Web framework
TypeScript Type-safe JavaScript
PostgreSQL Primary database
Prisma ORM & database management
Socket.IO Real-time WebSocket communication
Apache Kafka Message queue & event streaming
Redis Caching & session storage
Pinecone Vector database for semantic search
Nodemailer/Resend Email service
JWT Token-based authentication

Frontend

Technology Purpose
React 18+ UI framework
TypeScript Type-safe development
Vite Build tool & dev server
Tailwind CSS Styling
Shadcn/UI Component library
Socket.IO Client Real-time communication
Axios HTTP client
React Query Data fetching & caching
React Hook Form Form management
Google OAuth Social authentication

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18+)
  • npm or bun (v1.0+)
  • PostgreSQL (v14+)
  • Redis (v6+)
  • Apache Kafka (optional, for message queue features)
  • Docker (optional, for containerized setup)
  • Git

Environment Requirements

  • Pinecone API Key - For vector search capabilities
  • Google OAuth Credentials - For social authentication
  • SMTP/Email Service - For sending emails
  • JWT Secret Key - For token generation

๐Ÿš€ Getting Started

Step 1: Clone the Repository

git clone https://github.com/yourusername/mindchat.git
cd MindChat

Step 2: Backend Setup

Navigate to the backend directory:

cd backend

Install Dependencies

npm install
# or
bun install

Configure Environment Variables

Create a .env file in the backend directory:

# Get these from Google Cloud Console
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret

# Backend URL
BACKEND_URL=http://localhost:3000

# Database Configuration
DATABASE_URL=postgresql://user:password@localhost:5432/mindchat

# JWT Configuration
JWT_SECRET=your-secret-key-here

# Frontend URL for CORS
FRONTEND_URL=http://localhost:5173

# Node Environment
NODE_ENV=development

# Server Port
PORT=3000

Setup Database

# Create database and run migrations
npm run prisma:migrate

# Seed database (optional)
npm run prisma:seed

Start Backend Server

# Development mode with auto-reload
npm run dev

# or build and start production
npm run build
npm start

The backend server will run on http://localhost:5000

Start Kafka Consumer (Optional)

In a separate terminal:

npm run consumer

Step 3: Frontend Setup

In a new terminal, navigate to the frontend directory:

cd frontend

Install Dependencies

npm install
# or
bun install

Configure Environment Variables

Create a .env.local file in the frontend directory:

# Google OAuth
VITE_GOOGLE_CLIENT_ID=your_google_client_id


# API Configuration
VITE_BACKEND_URL="http://localhost:3000"

Start Frontend Development Server

npm run dev

The frontend application will be available at http://localhost:5173


๐Ÿ“ฆ Docker Setup (Optional)

For a containerized setup using Docker Compose:

# From the project root
docker-compose up -d

This will start:

  • PostgreSQL database
  • Redis cache
  • Backend API server
  • Frontend development server

๐Ÿ”ง Available Scripts

Backend Scripts

npm run dev          # Start development server with hot reload
npm run build        # Build TypeScript to JavaScript
npm run start        # Start production server
npm run consumer     # Start Kafka consumer
npm run prisma:migrate  # Run database migrations
npm run prisma:studio   # Open Prisma Studio (database GUI)

Frontend Scripts

npm run dev          # Start development server
npm run build        # Build for production
npm run build:dev    # Build in development mode
npm run lint         # Run ESLint
npm run preview      # Preview production build locally

๐Ÿ“ Project Structure

MindChat/
โ”œโ”€โ”€ backend/                 # Backend application
โ”‚   โ”œโ”€โ”€ controllers/             # Route controllers
โ”‚   โ”œโ”€โ”€ lib/                     # Utilities & services
โ”‚   โ”‚   โ”œโ”€โ”€ kafka.ts            # Kafka producer
โ”‚   โ”‚   โ”œโ”€โ”€ kafkaConsumer.ts    # Kafka consumer
โ”‚   โ”‚   โ”œโ”€โ”€ pinecone.ts         # Vector search
โ”‚   โ”‚   โ”œโ”€โ”€ socket.ts           # WebSocket setup
โ”‚   โ”‚   โ”œโ”€โ”€ mailer.ts           # Email service
โ”‚   โ”‚   โ””โ”€โ”€ prisma.ts           # Database client
โ”‚   โ”œโ”€โ”€ middleware/              # Express middleware
โ”‚   โ”œโ”€โ”€ routes/                  # API routes
โ”‚   โ”œโ”€โ”€ prisma/                  # Database schema
โ”‚   โ”œโ”€โ”€ utils/                   # Helper functions
โ”‚   โ”œโ”€โ”€ consumer.ts              # Kafka consumer script
โ”‚   โ”œโ”€โ”€ index.ts                 # Server entry point
|   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ docker-compose.yml           # Docker configuration
โ”‚
โ”œโ”€โ”€ frontend/                 # Frontend application
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/          # React components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth/           # Auth components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ chat/           # Chat components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ DirectMessage/  # DM components
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ui/             # Shadcn UI components
โ”‚   โ”‚   โ”œโ”€โ”€ pages/              # Page components
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/              # Custom React hooks
โ”‚   โ”‚   โ”œโ”€โ”€ lib/                # Utilities
โ”‚   โ”‚   โ”œโ”€โ”€ contextAPI/         # Context providers
โ”‚   โ”‚   โ””โ”€โ”€ main.tsx            # App entry point
โ”‚   โ”œโ”€โ”€ public/                  # Static assets
โ”‚   โ”œโ”€โ”€ tailwind.config.ts       # Tailwind configuration
โ”‚   โ”œโ”€โ”€ vite.config.ts           # Vite configuration
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ””โ”€โ”€ README.md                    # Project documentation

๐Ÿ”Œ API Endpoints

Authentication

  • POST /auth/magic-link - Request magic link
  • POST /auth/verify-token - Verify magic link token
  • POST /auth/google - Google OAuth authentication
  • POST /auth/logout - Logout user

Users

  • GET /user/profile - Get user profile
  • PUT /user/profile - Update user profile
  • GET /user/search - Search users
  • GET /user/:id - Get user by ID

Contacts

  • GET /contacts - Get user contacts
  • POST /contacts - Add contact
  • DELETE /contacts/:id - Remove contact

Messages

  • GET /messages/:contactId - Get message history
  • POST /messages - Send message
  • GET /messages/search - Semantic search across messages - Main feature for finding messages by meaning

๐Ÿ”Œ Real-Time Events (Socket.IO)

Client โ†’ Server

  • send_message - Send a new message
  • typing - User is typing
  • user_online - User comes online
  • user_offline - User goes offline

Server โ†’ Client

  • receive_message - New message received
  • user_typing - User typing notification
  • user_online - User came online
  • user_offline - User went offline

Kafka Issues

  • Ensure Kafka broker is running on configured host:port
  • Check Kafka topic exists: kafka-topics --list --bootstrap-server localhost:9092

๐Ÿ“š Documentation


๐Ÿค Contributing

We welcome contributions! Please follow these steps:


๐Ÿ“„ License

This project is licensed under the ISC License - see the LICENSE file for details.


๐Ÿ’ฌ Support

For support, open an issue on GitHub.


๐Ÿ™ Acknowledgments

  • Shadcn/UI - Beautiful component library
  • Prisma - Amazing ORM
  • Socket.IO - Real-time communication
  • Pinecone - Vector search platform

๐Ÿ“Š Performance Considerations

  • Redis caching reduces database queries
  • Kafka decouples message processing
  • Vector embeddings enable semantic search - Core intelligence layer using Pinecone
  • WebSocket reduces HTTP overhead
  • Prisma query optimization with indexes

๐Ÿ”ฌ Semantic Search Deep Dive

Architecture

Message Input โ†’ @xenova/transformers โ†’ Vector Embedding โ†’ Pinecone Index โ†’ Similarity Search โ†’ Ranked Results

Key Technologies:

Component Technology Purpose
Embedding Model @xenova/transformers Converts text to semantic vectors
Vector DB Pinecone Stores and searches embeddings
Processing Kafka Async message embedding pipeline
Caching Redis Caches frequently searched embeddings

๐Ÿ”ฎ Future Enhancements

  • Group chat support
  • Voice/Video calling integration
  • File sharing and media upload
  • Message encryption
  • Mobile app (React Native)
  • Message reactions and emojis
  • Read receipts and typing indicators
  • User presence status
  • Channel-based communication

Built with โค๏ธ by the MindChat Team

About

AI-powered real-time chat app with semantic message search using vector embeddings, Pinecone, and WebSockets.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages