A modern, secure real-time messaging application built with Next.js, featuring end-to-end encryption, video calling, and real-time presence indicators.
- Real-time messaging with Socket.IO for instant communication
- End-to-end encryption using AES-256-CBC for messages, files, and URLs
- Private and group conversations with member management
- File sharing with support for images, videos, and documents
- Read receipts and message status indicators
- Typing indicators with multi-device support
- Online/offline presence tracking with last seen timestamps
- Voice & video calls powered by ZegoCloud
- Call notifications with incoming call UI and ringtone
- 30-second call timeout for unanswered calls
- Multi-device call handling with proper state management
- JWT authentication for secure API and WebSocket connections
- Email OTP verification for account registration
- Password hashing with bcryptjs
- Encrypted file storage on Cloudinary
- Secure file URL generation with encryption
- Dark/light theme support with next-themes
- Responsive design optimized for all devices
- Profile management with avatar upload and bio
- User search functionality
- Emoji picker for expressive messaging
- File preview for images and documents
- Next.js 16 - React framework with App Router
- React 19 - UI library
- TypeScript - Type safety
- Tailwind CSS 4 - Utility-first styling
- Lucide React - Icon library
- GSAP - Animations
- React Hot Toast - Notifications
- Next.js API Routes - RESTful API endpoints
- Express - WebSocket server
- Socket.IO - Real-time bidirectional communication
- Prisma - Type-safe database ORM
- PostgreSQL - Primary database
- Prisma Accelerate - Database connection pooling
- Cloudinary - File storage and CDN
- Brevo - Email service for OTP delivery
- ZegoCloud - Video/audio calling infrastructure
- jsonwebtoken - JWT token generation and verification
- bcryptjs - Password hashing
- Zod - Schema validation
- crypto (Node.js) - AES-256-CBC encryption
- Node.js 20+ or Bun
- PostgreSQL database
- Cloudinary account
- Brevo account (for email)
- ZegoCloud account (for video calls)
- Clone the repository:
git clone https://github.com/RAJIV81205/ping.git
cd ping- Install dependencies:
npm install
# or
bun install- Set up environment variables:
cp .env.example .envEdit .env and fill in your configuration:
DATABASE_URL- Prisma Accelerate connection stringENCRYPTION_KEY- 256-bit hex key (generate withnode -e "console.log(require('crypto').randomBytes(32).toString('hex'))")JWT_SECRET- Random secret for JWT signingCLOUDINARY_*- Cloudinary credentialsBREVO_*- Brevo email service credentialsNEXT_PUBLIC_ZEGO_APP_ID&ZEGO_SERVER_SECRET- ZegoCloud credentialsFRONTEND_URL- Your app URL (for CORS)NEXT_PUBLIC_WEBSOCKET_URL- WebSocket server URL
- Set up the database:
npx prisma generate
npx prisma migrate deploy- Run the development servers:
# Run both Next.js and WebSocket server
npm run dev:all
# Or run separately:
npm run dev # Next.js (port 3000)
npm run websocket # WebSocket server (port 3001)- Open http://localhost:3000 in your browser.
ping/
├── app/ # Next.js App Router
│ ├── api/ # API routes
│ │ ├── auth/ # Authentication endpoints
│ │ ├── (dashboard)/ # Protected dashboard APIs
│ │ │ ├── chats/ # Chat management
│ │ │ ├── conversations/ # Conversation APIs
│ │ │ └── messages/ # Message handling
│ │ ├── users/ # User management
│ │ └── files/ # File serving
│ ├── auth/ # Auth pages (login/register)
│ ├── dashboard/ # Main app interface
│ └── generated/ # Prisma generated client
├── components/ # React components
│ ├── Auth/ # Login/signup forms
│ ├── Dashboard/ # Chat interface & settings
│ ├── Calls/ # Video call components
│ └── Landing/ # Landing page
├── lib/ # Utilities and services
│ ├── db/ # Database client & services
│ ├── hooks/ # Custom React hooks
│ ├── middleware/ # Auth middleware
│ ├── utils/ # Helper functions
│ ├── validators/ # Zod schemas
│ ├── encryption.ts # Encryption utilities
│ ├── cloudinary.ts # File upload service
│ └── email.ts # Email service
├── prisma/ # Database schema & migrations
├── server/ # WebSocket server
│ └── index.ts # Socket.IO server
└── public/ # Static assets
The application uses PostgreSQL with the following main models:
- User - User accounts with authentication
- Conversation - Chat containers (private/group)
- ConversationMember - User-conversation relationships
- Message - Encrypted messages with type support
- MessageFile - Encrypted file attachments
- ReadReceipt - Message read tracking
- EmailOTP - Email verification codes
POST /api/auth/register- Create new accountPOST /api/auth/verify-otp- Verify email OTPPOST /api/auth/login- User loginPOST /api/auth/logout- User logoutGET /api/auth/me- Get current userPOST /api/auth/socket-token- Get WebSocket token
GET /api/users/[username]- Get user by usernameGET /api/users/by-id/[userId]- Get user by IDGET /api/users/search- Search usersPUT /api/users/[username]/avatar- Update avatarGET /api/users/online-status- Check online status
GET /api/conversations- List user conversationsPOST /api/conversations- Create conversationGET /api/conversations/[id]/online-users- Get online members
GET /api/chats/[id]/messages- Get conversation messagesPOST /api/messages- Send messagePOST /api/messages/upload- Upload filePUT /api/messages/[id]- Update messageDELETE /api/messages/[id]- Delete message
send_message- Send new messagetyping_start- Start typing indicatortyping_stop- Stop typing indicatormark_message_read- Mark message as readincoming_call- Initiate callcall_accepted- Accept incoming callcall_rejected- Reject incoming callcall_ended- End active call
new_message- New message receivedmessage_read- Message read by recipientuser_typing- User started typinguser_stopped_typing- User stopped typinguser_online- User came onlineuser_offline- User went offlineonline_users- List of online usersincoming_call- Incoming call notificationcall_accepted- Call was acceptedcall_rejected- Call was rejectedcall_ended- Call endedcall_failed- Call failed
npm run dev # Start Next.js dev server
npm run websocket # Start WebSocket server
npm run dev:all # Start both servers concurrently
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
npm run studio # Open Prisma Studio- Push your code to GitHub
- Import project in Vercel
- Add environment variables
- Deploy
Deploy the WebSocket server separately (Railway, Render, or any Node.js hosting):
- Set
WEBSOCKET_PORTenvironment variable - Run
npm run websocket - Update
NEXT_PUBLIC_WEBSOCKET_URLin frontend
Use a managed PostgreSQL service:
- Vercel Postgres
- Supabase
- Railway
- Neon
Enable Prisma Accelerate for connection pooling and caching.
- All messages are encrypted at rest using AES-256-CBC
- File URLs are encrypted before storage
- JWT tokens expire and require refresh
- CORS is configured for production domains
- Environment variables must be kept secure
- Use HTTPS in production
- WebSocket connections are authenticated
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is private and proprietary. All rights reserved.
For issues and questions, please open an issue on GitHub.
Built with ❤️ using Next.js and modern web technologies.