Skip to content

Adityatorgal17/Justchat

Repository files navigation

JustChat Backend 🚀

Real-time chat backend built with Node.js, Express, and Socket.IO, featuring secure messaging, room management, and file sharing capabilities.

Features

  • 🔒 Secure Authentication with Auth0 integration
  • 💬 Real-time Messaging using Socket.IO
  • 🗄️ Persistent Storage with PostgreSQL + Prisma
  • 📁 File Sharing support for images and documents
  • 🔑 Private Rooms with invite-only access
  • 📝 Read Receipts and typing indicators

💫 Why JustChat?

🎯 Core Features

  • Instant Messaging: Create a room, share the code, start chatting
  • Private Rooms: Unique invite codes for secure access
  • Theme Engine: 10+ themes to personalize your experience
  • File Sharing: Share images and documents seamlessly
  • Real-time Updates: Live typing indicators and read receipts

🛡️ Built for Security

  • Auth0 Integration: Enterprise-grade user authentication
  • Data Protection: Secure message handling and storage
  • XSS Prevention: Advanced input sanitization
  • Rate Limiting: Spam and abuse protection
  • Secure Headers: Industry-standard security practices

Room Management

  • Private Rooms: Each room has a unique invite code
  • Room Themes: Customizable themes that can be changed by room creators
  • Admin Controls:
    • Kick participants
    • Rotate room invite codes
    • Change room themes
    • Full room deletion capability

User Features

  • Custom Display Names: Users can set and update their display names
  • Profile Pictures: Support for user avatars
  • Member List: Real-time updated list of room participants
  • Join/Leave Notifications: Automatic notifications for room activity

Security

  • XSS Prevention: DOMPurify implementation for message sanitization
  • Rate Limiting: Protection against abuse (configured in Azure API Management)
  • Input Validation: Strict validation for all incoming data
  • Secure Headers: Implementation of security best practices

� Backend Setup Guide

Prerequisites

  • Node.js 16+
  • PostgreSQL 13+
  • Auth0 Account
  • Cloudflare R2 Account (optional, for file uploads)

Environment Variables

Create a .env file:

# Required
DATABASE_URL="postgresql://user:password@localhost:5432/justchat"
PORT=5003
NODE_ENV=development

# Auth0 Configuration
AUTH0_ISSUER_URL="https://your-tenant.region.auth0.com"
AUTH0_AUDIENCE="your-api-identifier"

# Optional - Cloudflare R2 (for file uploads)
R2_ACCOUNT_ID="your-account-id"
R2_ACCESS_KEY_ID="your-access-key"
R2_SECRET_ACCESS_KEY="your-secret-key"
R2_BUCKET_NAME="your-bucket-name"

🚀 Getting Started

Quick Start

  1. Clone & Install
    git clone https://github.com/Adityatorgal17/Justchat.git
    cd Justchat/backend
    pnpm install   # or npm install

2. **Database Setup**

   ```bash
   npx prisma migrate dev
  1. Start Server

    pnpm dev   # or npm run dev

Docker Deployment

  1. Build Image

    docker build -t justchat-backend .
  2. Run Container

    docker run -d \
      --name justchat-backend \
      -p 5003:5003 \
      --env-file .env \
      justchat-backend

🏗️ Architecture

Technology Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Real-time: Socket.IO
  • Database: PostgreSQL with Prisma ORM
  • Authentication: Auth0
  • File Storage: Cloudflare R2

Key Components

  • Socket Manager: Handles real-time communication
  • Room Manager: Manages room lifecycle and user interactions
  • Auth Middleware: Validates JWT tokens and manages user sessions
  • Rate Limiter: Prevents abuse through request limiting
  • Sanitization: Protects against XSS and other injection attacks

🛡️ Security Considerations

  • All messages are sanitized using DOMPurify
  • JWT tokens are validated on every request
  • Rate limiting is implemented to prevent abuse
  • File uploads are validated for size and type
  • No message persistence for privacy
  • Room codes are cryptographically secure

🔧 Configuration Options

The server can be configured through environment variables:

  • PORT: Server port (default: 5003)
  • NODE_ENV: Environment (development/production)
  • MAX_ROOM_SIZE: Maximum users per room (default: 50)
  • ROOM_EXPIRY_HOURS: Room lifetime in hours (default: 24)
  • MAX_MESSAGE_LENGTH: Maximum message length (default: 500)

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📧 Contact

For any queries, reach out to me on GitHub @Adityatorgal17

About

Real-time chat app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors