Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EchoMeet — Complete Deployment Guide

Overview

EchoMeet is a full-stack anonymous random chat & audio call platform.

Stack:

  • Frontend: Next.js 14, TypeScript, TailwindCSS, Socket.io Client, WebRTC
  • Backend: Node.js, Express, Socket.io, TypeScript
  • Database: MongoDB + Redis
  • Auth: JWT + bcrypt
  • Media: Cloudinary
  • Payments: Stripe
  • Deployment: Docker + Nginx / Vercel + AWS
  • realtime: socket.io

Project Structure

echomeet/
├── frontend/                  # Next.js 14 app
│   ├── src/
│   │   ├── app/               # App Router pages
│   │   │   ├── page.tsx       # Landing page
│   │   │   ├── dashboard/     # Main dashboard
│   │   │   ├── chat/          # Random text chat
│   │   │   ├── call/          # Random audio call (WebRTC)
│   │   │   ├── friends/       # Friends management
│   │   │   ├── gift-store/    # Gift & coin store
│   │   │   ├── premium/       # Premium subscription
│   │   │   ├── profile/       # User profile
│   │   │   ├── admin/         # Admin panel
│   │   │   └── auth/          # Login / Register
│   │   ├── components/        # Reusable UI components
│   │   ├── context/           # React Context (Auth, Socket)
│   │   ├── hooks/             # Custom hooks (useWebRTC, useToast)
│   │   ├── lib/               # API client, utilities
│   │   └── types/             # TypeScript interfaces
│   └── Dockerfile
│
├── backend/
│   ├── src/
│   │   ├── controllers/       # Route handlers
│   │   ├── models/            # Mongoose schemas
│   │   │   ├── User.ts
│   │   │   ├── Message.ts
│   │   │   ├── ChatSession.ts
│   │   │   ├── FriendRequest.ts
│   │   │   ├── Gift.ts
│   │   │   ├── Transaction.ts
│   │   │   └── Report.ts
│   │   ├── routes/            # Express routes
│   │   ├── socket/            # Socket.io server + matchmaking
│   │   ├── services/          # Email, external services
│   │   ├── middleware/        # Auth, error handler, rate limiter
│   │   ├── config/            # DB, Redis, Cloudinary config
│   │   └── utils/             # Logger, JWT, AppError, seeder
│   └── Dockerfile
│
├── nginx/                     # Reverse proxy config
├── docker-compose.yml
└── README.md

Prerequisites

  • Node.js 20+
  • Docker & Docker Compose
  • MongoDB (or use Docker)
  • Redis (or use Docker)
  • Cloudinary account
  • Stripe account
  • SMTP email service

Quick Start (Docker)

1. Clone and configure

git clone https://github.com/yourusername/echomeet
cd echomeet

# Backend
cp backend/.env.example backend/.env
# Edit backend/.env with your credentials

# Frontend
cp frontend/.env.example frontend/.env.local
# Edit frontend/.env.local with your credentials

2. Configure environment variables

backend/.env (required):

NODE_ENV=production
PORT=5000
CLIENT_URL=https://yourdomain.com
MONGODB_URI=mongodb://admin:password@mongodb:27017/echomeet?authSource=admin
REDIS_URL=redis://:password@redis:6379
JWT_SECRET=your-256-bit-secret-key
JWT_REFRESH_SECRET=another-256-bit-secret-key
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your@gmail.com
SMTP_PASS=your-app-password
EMAIL_FROM=EchoMeet <noreply@echomeet.com>
STRIPE_SECRET_KEY=sk_live_...
STRIPE_WEBHOOK_SECRET=whsec_...
ADMIN_EMAIL=admin@echomeet.com
ADMIN_PASSWORD=SecureAdminPass123!

frontend/.env.local:

NEXT_PUBLIC_API_URL=https://yourdomain.com/api
NEXT_PUBLIC_SOCKET_URL=https://yourdomain.com
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_...

3. Start everything

docker-compose up -d --build

4. Seed the database

docker exec echomeet-backend node dist/utils/seeder.js

5. SSL Certificates (production)

# Using Let's Encrypt
apt install certbot
certbot certonly --standalone -d yourdomain.com -d www.yourdomain.com
cp /etc/letsencrypt/live/yourdomain.com/fullchain.pem nginx/ssl/
cp /etc/letsencrypt/live/yourdomain.com/privkey.pem nginx/ssl/

Local Development (without Docker)

Backend

cd backend
npm install
cp .env.example .env
# Fill in local values (MongoDB: localhost:27017, Redis: localhost:6379)
npm run dev
# Server starts on http://localhost:5000

Frontend

cd frontend
npm install
cp .env.example .env.local
npm run dev
# App starts on http://localhost:3000

Vercel + AWS Deployment

Frontend → Vercel

cd frontend
npm install -g vercel
vercel --prod
# Set env vars in Vercel dashboard

Backend → AWS EC2 / DigitalOcean

# On your VPS:
git clone https://github.com/yourname/echomeet
cd echomeet
docker-compose up -d mongodb redis backend nginx
# Seed DB
docker exec echomeet-backend node dist/utils/seeder.js

Stripe Webhook Setup

  1. In Stripe Dashboard → Webhooks → Add endpoint
  2. URL: https://yourdomain.com/api/webhooks/stripe
  3. Events to listen for:
    • checkout.session.completed
    • customer.subscription.deleted
  4. Copy the webhook secret to STRIPE_WEBHOOK_SECRET

Architecture

Matchmaking Algorithm

User clicks "Start Random Chat"
    → socket.emit('join_queue', { type: 'text', genderPreference: 'any' })
    → Server: findMatch() scans queue for compatible user
        - Free users: any gender preference = 'any'
        - Premium users: can set preference to 'male' | 'female' | 'any'
        - Match check: entry1.genderPref matches entry2.gender AND vice versa
    → If match found:
        - Create ChatSession in MongoDB
        - Join both sockets to shared roomId
        - Emit 'match_found' to both with partner info
    → If no match:
        - Add to queue
        - Emit 'queue_joined' with position

WebRTC Audio Flow (No Video)

1. match_found → isInitiator = true for first user
2. initiator.startCall() → getUserMedia({ audio: true, video: false })
3. Create RTCPeerConnection with ICE servers (STUN)
4. Add audio tracks to peer connection
5. createOffer() → setLocalDescription()
6. socket.emit('webrtc_offer', { roomId, offer })
7. Responder receives 'webrtc_offer'
8. setRemoteDescription(offer)
9. createAnswer() → setLocalDescription()
10. socket.emit('webrtc_answer', { roomId, answer })
11. ICE candidates exchanged via 'webrtc_ice_candidate'
12. Audio streams connected P2P

Gift Economy

User → sendGift(giftId, receiverId, roomId)
    → Validate coins: user.coins >= gift.coinCost
    → Deduct coins from sender
    → Increment giftsReceived on receiver
    → Create GiftTransaction record
    → socket.emit('gift_received') to room
    → Receiver sees gift animation

API Reference

Authentication

Method Endpoint Description
POST /api/auth/register Register with username, email, password, gender
POST /api/auth/login Login
POST /api/auth/logout Logout
GET /api/auth/me Get current user
GET /api/auth/verify-email/:token Verify email
POST /api/auth/forgot-password Request reset
POST /api/auth/reset-password/:token Reset password

Users

Method Endpoint Description
GET /api/users/:id Get profile
PUT /api/users/profile Update profile
POST /api/upload/avatar Upload avatar
GET /api/users/search?q= Search users
POST /api/users/:id/block Block user

Friends

Method Endpoint Description
GET /api/friends Get friends list
GET /api/friends/requests Pending requests
POST /api/friends/request/:userId Send request
POST /api/friends/accept/:requestId Accept
POST /api/friends/reject/:requestId Reject
DELETE /api/friends/:userId Remove friend

Gifts & Transactions

Method Endpoint Description
GET /api/gifts All gifts
POST /api/gifts/send Send gift
GET /api/transactions/coin-packs Coin packages
POST /api/transactions/buy-coins Purchase coins via Stripe
POST /api/transactions/buy-premium Premium subscription

Admin

Method Endpoint Description
GET /api/admin/stats Platform stats
GET /api/admin/users All users (paginated)
POST /api/admin/users/:id/ban Ban/unban user
GET /api/admin/reports Reports queue
PUT /api/admin/reports/:id Update report status

Socket.io Events

Client → Server

Event Payload Description
join_queue { type, genderPreference } Enter matchmaking
leave_queue Exit queue
send_message { roomId, content, messageType, mediaUrl } Send chat message
typing_start { roomId } Start typing indicator
typing_stop { roomId } Stop typing
send_gift { roomId, giftId, receiverId } Send gift in session
end_session { roomId } End chat/call
webrtc_offer { roomId, offer } WebRTC offer (audio)
webrtc_answer { roomId, answer } WebRTC answer
webrtc_ice_candidate { roomId, candidate } ICE candidate
call_muted { roomId, muted } Mute state change
start_friend_chat { friendId, type } Start friend chat/call

Server → Client

Event Payload Description
match_found { roomId, sessionId, partner, type } Match found
queue_joined { type, position } Added to queue
new_message Message Incoming message
partner_typing { userId } Partner is typing
session_ended { roomId, duration } Session terminated
gift_received { gift, sender, receiverId } Gift received
queue_stats { textQueue, audioQueue, activeSessions } Live stats
user_online/offline { userId } Presence update
friend_call_incoming { from, roomId, type } Incoming friend call

Security Checklist

  • JWT authentication with refresh tokens
  • bcrypt password hashing (salt rounds: 12)
  • Rate limiting (express-rate-limit) on all API routes
  • Auth rate limiting (20 req/15min)
  • Helmet.js security headers
  • CORS configured for specific origins
  • Input validation (express-validator)
  • XSS protection headers
  • File upload validation (type + size limits)
  • WebRTC audio-only (no video stream allowed)
  • Socket authentication via JWT
  • User blocking system
  • Report & moderation queue
  • Admin-only routes protected
  • Stripe webhook signature verification

Performance

The system is built to handle thousands of concurrent users:

  • Socket.io with WebSocket + polling fallback
  • Redis session caching (plugged in, extend as needed)
  • MongoDB with proper indexes on all query fields
  • Nginx reverse proxy with connection pooling
  • Rate limiting prevents queue flooding
  • Queue-based matching (O(n) scan with early exit)
  • Connection pooling for MongoDB (maxPoolSize: 10)
  • Docker health checks on all services

License

MIT — Build freely, deploy anywhere.

TalkPlayHub

About

under development Opensource welcome contributers

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages