Skip to content

Repository files navigation

🌐 LinguaChat

Break language barriers β€” chat across languages in real time.

TypeScript React Node.js Socket.IO MongoDB Lingo.dev Vercel Render


πŸ”— Live Demo

Service URL
Frontend lingua-chat.vercel.app
Backend linguachat-frmz.onrender.com

Create an account, join or create a room, and start chatting β€” messages are translated automatically for every participant.


🌍 Overview

LinguaChat is a full-stack, real-time multilingual chat application. Users speaking different languages can join the same room and communicate effortlessly β€” every message is automatically translated into each participant's preferred language using the Lingo.dev AI translation engine.

Built with a modern TypeScript stack: React 19 + Vite on the frontend and Node.js + Express + Socket.IO on the backend, backed by MongoDB Atlas for persistent storage.


✨ Features

πŸ’¬ Core Chat

  • Real-time messaging via Socket.IO with instant delivery
  • Automatic translation to 7 languages (English, Hindi, Bengali, Spanish, French, German, Japanese)
  • Two-phase message delivery β€” original text appears instantly, translations arrive asynchronously
  • Translation caching β€” repeated phrases are served instantly from an in-memory cache

οΏ½ Room System

  • Create & join rooms β€” public rooms with admin controls
  • Global / Native mode β€” admins can toggle between translated (Global) and untranslated (Native) modes per room
  • Online presence β€” see who's in the room with live user lists and language tags
  • Room history β€” last 50 messages loaded on join with on-the-fly translation for missing languages

πŸ’… Rich Chat Experience

  • Emoji picker β€” inline emoji selection in the message composer
  • Message reactions β€” react to messages with emojis (toggle on/off)
  • Reply threads β€” reply to specific messages with a preview bar and scroll-to-message navigation
  • Typing indicators β€” see when others are composing a message
  • Date separators β€” messages grouped by Today / Yesterday / date labels
  • Auto-resize composer β€” textarea grows with input, supports Shift+Enter for newlines

πŸ” Authentication & Security

  • JWT-based auth with access + refresh tokens
  • Session management β€” view active sessions, logout individual or all sessions
  • Rate limiting β€” per-route and per-socket rate limits to prevent abuse
  • Input validation with Zod schemas
  • Socket authentication middleware β€” only authenticated users can connect

🌐 Deployment

  • Frontend deployed on Vercel (SPA with client-side routing)
  • Backend deployed on Render (Node.js Web Service)
  • Database on MongoDB Atlas (cloud-hosted)

🧰 Tech Stack

Layer Technologies
Frontend React 19, TypeScript, Vite 7, Tailwind CSS 4, Socket.IO Client
Backend Node.js, Express 5, TypeScript, Socket.IO 4, Mongoose
AI Lingo.dev SDK β€” AI-powered translation engine
Database MongoDB Atlas with Mongoose ODM
Auth JWT (access + refresh tokens), bcrypt password hashing
Testing Jest, Supertest, MongoDB Memory Server
Deploy Vercel (frontend), Render (backend)

πŸ“ Project Structure

LinguaChat/
β”‚
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ api/                       # Node.js + Express + Socket.IO backend
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ server.ts          # Entry point β€” HTTP server + Socket.IO setup
β”‚   β”‚   β”‚   β”œβ”€β”€ app.ts             # Express app β€” CORS, rate limiting, routes
β”‚   β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”‚   β”œβ”€β”€ middlewares/
β”‚   β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ sockets/
β”‚   β”‚   β”‚   └── types/
β”‚   β”‚   β”œβ”€β”€ tests/                 # Jest test suites
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   └── tsconfig.json
β”‚   β”œβ”€β”€ web/                       # React 19 + Vite SPA
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ main.tsx           # App entry point
β”‚   β”‚   β”‚   β”œβ”€β”€ App.tsx            # Router setup (login, register, home, room)
β”‚   β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── types/
β”‚   β”‚   β”œβ”€β”€ vercel.json            # SPA rewrite rules for Vercel
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   └── vite.config.ts
β”‚   └── mobile/                    # Expo + React Native client
β”œβ”€β”€ packages/
β”‚   └── shared/                    # Shared chat + socket contracts
└── package.json                   # Root workspace scripts

πŸ› οΈ Local Development

Prerequisites

  • Node.js 18+ (recommended: 22)
  • MongoDB β€” local instance or MongoDB Atlas (free tier)
  • Lingo.dev API Key β€” get one at lingo.dev

🐳 Option A β€” Run with Docker (Recommended)

The fastest way to get everything running. Only requires Docker installed.

1. Clone the repository

git clone https://github.com/Souma061/LinguaChat.git
cd LinguaChat

2. Create the backend .env file

cp apps/api/.env.example apps/api/.env

Edit apps/api/.env and fill in your credentials:

LINGO_API_KEY=your_lingo_api_key
PORT=5000
MONGODB_URI=mongodb+srv://user:password@cluster.mongodb.net/
JWT_SECRET=your_jwt_secret
JWT_REFRESH_SECRET=your_refresh_secret
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
CORS_ORIGINS=http://localhost

Need API keys?

3. Build and run

docker compose up --build -d

4. Open in browser

Service URL
Frontend http://localhost
Backend http://localhost:5000

Stop / restart

docker compose down       # stop
docker compose up -d      # restart (without rebuilding)
docker compose up --build -d  # restart with rebuild

πŸ–₯️ Option B β€” Run without Docker

Prerequisites

  • Node.js 18+ (recommended: 22)
  • npm (comes with Node.js)

1. Clone the repository

git clone https://github.com/Souma061/LinguaChat.git
cd LinguaChat

2. Backend Setup

npm --prefix apps/api install

Create a .env file:

LINGO_API_KEY=your_lingo_api_key
PORT=5000
MONGODB_URI=mongodb+srv://user:password@cluster.mongodb.net/
JWT_SECRET=your_jwt_secret
JWT_REFRESH_SECRET=your_refresh_secret
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
CORS_ORIGINS=http://localhost:5173,http://localhost:5174

Start the development server:

npm run dev:api

Backend runs on http://localhost:5000

3. Frontend Setup

npm --prefix apps/web install

Create a .env file:

VITE_BACKEND_URL=http://localhost:5000/api
VITE_SOCKET_URL=http://localhost:5000

Start the development server:

npm run dev:web

Frontend runs on http://localhost:5173

4. Mobile Setup

cp apps/mobile/.env.example apps/mobile/.env
npm --prefix apps/mobile install

Start the Expo development server:

npm run dev:mobile

Mobile runs through Expo and talks to the same backend in apps/api


πŸ§ͺ Testing

npm run test:api

Tests use Jest with MongoDB Memory Server for isolated database testing and Supertest for HTTP endpoint validation.


πŸ—„οΈ Database Architecture

Models

Model Purpose
User Username, email, hashed password, role
Room Name, owner, admins, members, mode (Global/Native)
Message Original text, translations map, reactions, replies
UserSession JWT session tracking for multi-device logout

Message Schema

{
  room: string;           // Room identifier (indexed)
  author: string;         // Sender's username
  original: string;       // Original untranslated message
  translations: Map;      // { langCode: translatedText }
  sourceLocale: string;   // Detected source language
  msgId: string;          // Unique message identifier
  reactions: Map;         // { emoji: [username1, username2] }
  replyTo?: {             // Optional reply reference
    msgId: string;
    author: string;
    message: string;
  };
  createdAt: Date;        // Auto-managed timestamp
}

Indexes

  • room β€” fast room filtering
  • { room, createdAt } β€” compound index for efficient history retrieval
  • msgId β€” unique constraint for deduplication

πŸ”„ Translation Architecture

LinguaChat uses a two-phase message delivery pattern for optimal UX:

  1. Phase 1 β€” Instant delivery: Message is saved to MongoDB and broadcast to all room members immediately with the original text.
  2. Phase 2 β€” Async translation: Translations are generated in the background via Lingo.dev SDK, then pushed to all clients via a translations_ready socket event.

This ensures messages appear instantly while translations arrive within seconds.

Supported Languages

Code Language
en English
hi Hindi
bn Bengali
es Spanish
fr French
de German
ja Japanese

☁️ Deployment

Backend β†’ Render

  1. Create a Web Service on Render
  2. Connect your GitHub repository
  3. Configure:
    • Root Directory: apps/api
    • Build Command: npm install && npm run build
    • Start Command: npm start
  4. Add environment variables (MONGODB_URI, JWT_SECRET, JWT_REFRESH_SECRET, LINGO_API_KEY, CORS_ORIGINS)

Frontend β†’ Vercel

  1. Import the repository on Vercel
  2. Set Root Directory to apps/web
  3. Add environment variables:
    • VITE_BACKEND_URL = https://your-backend.onrender.com/api
    • VITE_SOCKET_URL = https://your-backend.onrender.com
  4. Deploy β€” Vercel auto-detects Vite and builds accordingly

Important: Add your Vercel domain to CORS_ORIGINS in the Render environment variables after deployment.


πŸ”’ API Endpoints

Authentication

Method Endpoint Description Auth
POST /api/auth/register Create a new account ❌
POST /api/auth/login Login & receive tokens ❌
POST /api/auth/refresh-token Refresh access token ❌
POST /api/auth/logout-session Logout current session βœ…
POST /api/auth/logout-all Logout all sessions βœ…
GET /api/auth/sessions List active sessions βœ…
GET /api/auth/profile Get user profile βœ…

Rooms

Method Endpoint Description Auth
GET /api/rooms List public rooms βœ…
POST /api/rooms Create a new room βœ…

Socket Events

Event Direction Description
join_Room Client β†’ Server Join a chat room
send_message Client β†’ Server Send a message to the room
set_language Client β†’ Server Change preferred language
create_room Client β†’ Server Create a new room
update_room_mode Client β†’ Server Toggle Global/Native mode (admin only)
add_reaction Client β†’ Server React to a message with an emoji
typing_start Client β†’ Server Notify typing started
typing_stop Client β†’ Server Notify typing stopped
receive_message Server β†’ Client New message received
translations_ready Server β†’ Client Translations available for a message
room_history Server β†’ Client Room message history on join
room_users Server β†’ Client Updated list of online users
room_info Server β†’ Client Room mode and admin status
reaction_update Server β†’ Client Updated reactions for a message
user_typing Server β†’ Client Typing indicator from another user
error_event Server β†’ Client Error notification

πŸ“Έ Screenshots

Landing Screen Demo Room Cross-Language Chat
Landing Demo Room Multilingual Chat

πŸŽ₯ Video Demo

Watch on YouTube


πŸ“„ License

This project is open source under the ISC License.


Built with ❀️ for the Lingo.dev Hackathon β€” making global communication effortless.

About

Real-Time Chat Application

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages