A real-time chat application built with React.js frontend and Node.js backend, featuring secure end-to-end encryption using ECDH key exchange and AES-GCM encryption.
- π End-to-End Encryption: Messages are encrypted using ECDH + AES-GCM
- π Secure Key Management: Private keys encrypted with password-derived master keys
- π§ Salt-based Encryption: Random salts for enhanced security
- π Hashed Passwords: Passwords stored as bcrypt hashes in database
- ποΈ Show/Hide Password: User-friendly password visibility toggle
- π¬ Real-time Messaging: Instant message delivery using Socket.IO
- π₯ Multi-user Support: Search and chat with multiple users
- οΏ½ Online User Tracking: Redis-based session management for real-time user status
- π± Responsive Design: Works on desktop and mobile devices
- π Persistent Sessions: Login state maintained across browser sessions
- π Chat History: Previous conversations stored and retrievable
- ποΈ Scalable Architecture: Separate frontend and backend services
- π³ Docker Database: PostgreSQL database containerized with Docker
- π΄ Redis Session Management: Track online users and socket session IDs
- π CORS Enabled: Cross-origin resource sharing configured
- π Real-time Status: Online/offline status tracking
- π§ Environment Configuration: Configurable via environment variables
- React.js - UI framework
- Socket.IO Client - Real-time communication
- Axios - HTTP client for API requests
- Crypto-js - Cryptographic functions
- Elliptic - ECDH key generation
- React Router - Client-side routing
- ChatScope UI Kit - Chat interface components
- Node.js - Server runtime
- Express.js - Web application framework
- Socket.IO - Real-time bidirectional communication
- Redis - Session management and online user tracking
- PostgreSQL - Database for user data and messages
- bcrypt - Password hashing
- nanoid - Unique ID generation
- dotenv - Environment variable management
- Docker - Database containerization
- Redis - In-memory data store for user sessions and socket IDs
- CORS - Cross-origin resource sharing
- Environment Variables - Configuration management
- Node.js (v14 or higher)
- Docker and Docker Compose
- npm or yarn package manager
git clone <repository-url>
cd chat_appCreate a .env file in the root directory:
# Database Configuration
DB_USER=postgres
DB_HOST=localhost
DB_NAME=chat_app_db
DB_PASSWORD=mysecretpassword
DB_PORT=5432
# API Configuration
REACT_APP_API_BASE=http://localhost:5000
# Socket Configuration
SOCKET_PORT=4000
API_PORT=5000docker-compose up -dcd chat-app-backend
npm installcd ../chat-app-frontend
npm installcd ../chat-app-backend
npm startcd ../chat-app-frontend
npm startThe application will be available at:
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- Socket.IO Server: http://localhost:4000
- User enters password and personal information
- Random salt is generated using nanoid
- Master key is derived from password + salt using PBKDF2
- ECDH key pair (public/private) is generated
- Private key is encrypted with master key using AES
- Public key, encrypted private key, and salt are stored in database
- Password is hashed with bcrypt before storage
- User enters email and password
- Server verifies password against bcrypt hash
- Server returns encrypted private key and salt
- Client recreates master key from password + salt
- Client decrypts private key using master key
- Private key is stored in session for message encryption/decryption
- Sender computes shared secret using their private key + receiver's public key (ECDH)
- Message is encrypted using AES-GCM with the shared secret
- Encrypted message is sent to server and stored in database
- Receiver retrieves encrypted message
- Receiver computes same shared secret using their private key + sender's public key
- Receiver decrypts message using AES-GCM
To test encryption between different users, run multiple frontend instances:
cd chat-app-frontend
npm run start:3002cd chat-app-frontend
npm run start:3003chat_app/
βββ chat-app-backend/ # Node.js backend
β βββ server.js # Main server file
β βββ SocketServer.js # Socket.IO server
β βββ login_register.js # Authentication endpoints
β βββ search.js # User search functionality
β βββ msg_db.js # Message storage/retrieval
β βββ package.json
βββ chat-app-frontend/ # React frontend
β βββ src/
β β βββ App.js # Main app component
β β βββ Login.jsx # Authentication component
β β βββ Home.jsx # Chat interface
β β βββ client_socket.js # Crypto & socket functions
β β βββ App.css # Styles
β βββ package.json
βββ docker-compose.yaml # Docker configuration
βββ init.sql # Database schema
βββ .env # Environment variables
βββ README.md # Documentation
- β Messages are encrypted end-to-end
- β Private keys are encrypted before storage
- β Passwords are hashed with bcrypt
- β Shared secrets are computed client-side only
- β Database stores only encrypted content
- π Private keys never leave the client unencrypted
- π Master keys are derived from passwords and never stored
- π§ Each user has a unique salt for key derivation
- πΎ Conversation keys are cached per session for performance
- π Key regeneration is possible if keys are lost
- Group chat functionality
- File sharing with encryption
- Push notifications
- Message delivery confirmations
- User profile management
- Advanced security features (key rotation, etc.)
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
- Database Connection Error: Ensure Docker is running and PostgreSQL container is started
- Port Already in Use: Check if ports 3000, 4000, 5000, or 5432 are already in use
- Environment Variables: Ensure
.envfile is properly configured - Key Decryption Fails: Clear localStorage and re-register if keys are corrupted






