A modern, secure chat application built with blockchain technology for message verification, real-time communication, file sharing, and comprehensive user management.
BChat is a full-stack decentralized chat application that combines traditional real-time messaging with blockchain technology for enhanced security and message verification. The application features user authentication, room-based messaging, file sharing, user profile management, and smart contract integration for message immutability.
- Real-time Messaging: WebSocket-based instant messaging with Socket.IO
- Blockchain Verification: Smart contract integration for message authenticity
- User Authentication: JWT-based secure login and registration
- Room Management: Create public/private rooms with PIN protection
- File Sharing: Encrypted upload and share files with MinIO object storage
- User Profile Management: Complete profile settings with avatar upload
- Friend System: Send friend requests, manage friendships, and view friends list
- Friend Requests: Real-time friend request notifications and management
- Online Status: See which friends are currently online
- Password Management: Secure password change functionality
- Account Management: Safe account deletion with confirmation
- Database Integration: PostgreSQL with in-memory fallback
- Message Encryption: End-to-end encryption for messages and files
- Notification System: Toast notifications using Sonner
- Responsive Design: Mobile-friendly interface with dark theme
The application consists of four main components:
- Location:
/frontend
- Technology: Next.js 14, React, TypeScript, Tailwind CSS
- Port: 3000
- Features:
- Real-time chat interface
- User authentication forms
- Room management UI
- File upload functionality
- Profile settings modal
- Password change dialog
- Account deletion confirmation
- Toast notifications with Sonner
- Mobile-responsive design
- Location:
/chat-api
- Technology: Node.js, Express, Socket.IO
- Port: 5000
- Features:
- RESTful API endpoints
- WebSocket server for real-time communication
- JWT authentication middleware
- File upload handling with encryption
- User profile management
- Password change endpoints
- Account deletion with data cleanup
- Database operations with PostgreSQL
- Location:
/blockchain
- Technology: Solidity, Web3.js
- Network: Ganache (local blockchain)
- Features:
- Message hash storage
- Message verification
- Immutable record keeping
- PostgreSQL Database: User and message data storage
- MinIO: Encrypted file storage and retrieval
- Ganache: Local Ethereum blockchain
- Next.js 14: React framework with App Router
- TypeScript: Type-safe development
- Tailwind CSS: Utility-first styling
- Socket.IO Client: Real-time communication
- Sonner: Toast notification system
- Node.js: Runtime environment
- Express.js: Web application framework
- Socket.IO: WebSocket implementation
- JWT: Authentication tokens
- Multer: File upload middleware
- Bcrypt: Password hashing
- Crypto: Message and file encryption
- PostgreSQL: Primary database
- MinIO: S3-compatible object storage with encryption
- In-memory fallback: Development mode
- Solidity: Smart contract language
- Web3.js: Ethereum JavaScript API
- Ganache: Local blockchain for development
Before running the application, ensure you have:
- Node.js (v18 or higher)
- Docker and Docker Compose
- Git
- Clone and install dependencies:
git clone https://github.com/guruswarupa/Bchat cd Bchat npm install cd blockchain && npm install && cd .. cd chat-api && npm install && cd .. cd frontend && npm install && cd ..
- Start all services:
docker-compose up -d
POST /api/auth/register
- User registrationPOST /api/auth/login
- User login
GET /api/profile
- Get user profilePUT /api/profile
- Update profile (username, email)POST /api/profile/avatar
- Upload profile picturePUT /api/profile/password
- Change passwordDELETE /api/profile
- Delete account
GET /api/rooms
- Get all chat roomsPOST /api/rooms
- Create new roomDELETE /api/rooms/:roomId
- Delete roomPOST /api/rooms/:roomId/verify-pin
- Verify room PIN
GET /api/rooms/:roomId/messages
- Get room messages (encrypted)- Socket events:
send_message
,new_message
,join_room
POST /api/upload
- Upload encrypted fileGET /api/files
- List uploaded filesGET /api/files/:roomId/:fileName
- Download decrypted fileGET /api/avatars/:fileName
- Get user avatar
GET /api/friends
- Get user's friends listPOST /api/friends/request
- Send friend requestPOST /api/friends/accept
- Accept friend requestPOST /api/friends/reject
- Reject friend requestDELETE /api/friends/:friendId
- Remove friendGET /api/friends/requests
- Get pending friend requests
GET /api/verify/:messageId
- Verify message on blockchain
GET /api/health
- System health checkPOST /api/admin/cleanup-rooms
- Admin room cleanup
- JWT tokens for session management
- Bcrypt password hashing with salt rounds
- Protected API routes with middleware
- Account deletion with password verification
- AES-256-GCM encryption for messages
- Room-specific encryption keys
- Encrypted file storage in MinIO
- SHA-256 content hashing for blockchain
- Private rooms with PIN protection
- User role management (admin/member)
- Room creator privileges
- Automatic membership for public rooms
- Secure avatar upload with validation
- Password change with current password verification
- Account deletion with complete data cleanup
- Registration β User creates account with email verification
- Profile Setup β Upload avatar, update personal information
- Password Management β Change password with current password verification
- Account Deletion β Secure deletion with password confirmation and data cleanup
- User sends message β Frontend captures input
- Encryption β Message encrypted with room-specific key
- Socket emission β Encrypted message sent via WebSocket
- Database storage β Encrypted message saved to PostgreSQL
- Hash generation β SHA-256 hash created for blockchain
- Blockchain recording β Hash stored in smart contract
- Real-time broadcast β Decrypted message sent to room users
- File selection β User chooses file
- Encryption β File encrypted with room-specific key
- Upload to MinIO β Encrypted file stored in object storage
- Database record β Encrypted file message created
- URL generation β Secure download link provided
- Message broadcast β File message sent to room
- Public rooms β Automatic membership for all users
- Private rooms β PIN-based access control
- Room creation β User becomes admin with full permissions
- Room deletion β Only admins can delete rooms
const pool = new Pool({
connectionString: process.env.DATABASE_URL || 'postgresql://postgres:postgres@localhost:5432/chatdb',
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
});
The application includes these main tables:
- users: User accounts with authentication and profile data
- chat_rooms: Room information including public/private settings
- room_members: User membership and roles in rooms
- messages: Encrypted chat messages with blockchain hashes
- friendships: Friend relationships between users & Pending friend requests with status tracking
const minioClient = new Minio.Client({
endPoint: 'minio',
port: 9000,
useSSL: false,
accessKey: 'minioadmin',
secretKey: 'minioadmin'
});
const web3 = new Web3('http://ganache:8545');
-
Database Connection Failed:
- Ensure PostgreSQL is running and accessible
- Check connection string in environment variables
- App automatically falls back to in-memory storage
-
Smart Contract Not Deployed:
- Run:
cd blockchain && npm run deploy
- Check Ganache is running on port 8545
- Blockchain features gracefully degrade if unavailable
- Run:
-
File Upload Issues:
- Verify MinIO is accessible
- Check bucket permissions and policies
- Ensure sufficient disk space
-
Frontend Not Starting:
- Run
npm install
in frontend directory - Check if port 3000 is available
- Verify Next.js dependencies are installed
- Run
- Use browser dev tools to monitor WebSocket connections
- Check console logs for detailed error messages
- Smart contract ABI fallback is available if deployment fails
- In-memory storage activates automatically if database is unavailable
- Toast notifications show system status and errors
- Register a new account with email and password
- Set up profile by uploading an avatar and updating information
- Join rooms by clicking on room names in the sidebar
- Send messages using the input field at the bottom
- Upload files using the attachment icon (files are encrypted)
- Create rooms using the "+" button next to "Rooms"
- Add friends by sending friend requests to other users
- Manage friendships through the friends section in the sidebar
- Update Profile: Access settings to change username and email
- Change Password: Secure password update with current password verification
- Upload Avatar: Profile picture with automatic resizing and validation
- Delete Account: Permanent account deletion with confirmation
- Public rooms: Accessible to all users automatically
- Private rooms: Require PIN for access
- Room deletion: Only available to room creators
- User list: Shows online users in current room
- Message encryption: All messages are encrypted per room
- Real-time delivery: Instant message updates
- Blockchain verification: Green checkmark indicates verified messages
- File attachments: Encrypted upload and share files with download links
- Timestamps: All messages show send time
- Message persistence: Messages stored securely in database
- Friend Requests: Send and receive friend requests with real-time notifications
- Friends Management: Accept, reject, or remove friends easily
- Online Status: See which friends are currently online with green indicators
- Friends List: View all friends in the sidebar with avatars and status
- Request Notifications: Get notified when someone sends you a friend request
- Toast notifications: Real-time feedback for all actions
- Error handling: Clear error messages for failed operations
- Success confirmations: Visual feedback for completed actions
- Friend notifications: Real-time alerts for friend requests and status changes
User Input β AES-256-GCM Encryption β Database Storage β Blockchain Hash β Real-time Broadcast β Client Decryption
File Selection β File Encryption β MinIO Upload β Database Record β Download URL β Broadcast Notification
Login Request β JWT Generation β Socket Authentication β Room Access β Real-time Features
- Fork the repository
- Create a feature branch
- Implement changes with proper encryption
- Test thoroughly with all features
- Submit a pull request
This project is licensed under the ISC License - see the package.json files for details.
For issues and questions:
- Check the troubleshooting section above
- Review console logs for detailed error messages
- Ensure all services are running correctly
- Check network connectivity between services
- Verify database and storage configurations
- All messages are encrypted using AES-256-GCM
- User passwords are hashed with bcrypt
- File uploads are encrypted before storage
- Blockchain provides immutable message verification
- Secure session management with JWT tokens
- Safe account deletion with complete data cleanup
Note: This application includes comprehensive security features and is suitable for development and educational purposes.