Real-time chat backend built with Node.js, Express, and Socket.IO, featuring secure messaging, room management, and file sharing capabilities.
- 🔒 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
- 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
- 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
- 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
- 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
- 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
- Node.js 16+
- PostgreSQL 13+
- Auth0 Account
- Cloudflare R2 Account (optional, for file uploads)
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"- 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
-
Start Server
pnpm dev # or npm run dev
-
Build Image
docker build -t justchat-backend . -
Run Container
docker run -d \ --name justchat-backend \ -p 5003:5003 \ --env-file .env \ justchat-backend
- Runtime: Node.js
- Framework: Express.js
- Real-time: Socket.IO
- Database: PostgreSQL with Prisma ORM
- Authentication: Auth0
- File Storage: Cloudflare R2
- 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
- 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
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)
This project is licensed under the MIT License - see the LICENSE file for details.
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.
For any queries, reach out to me on GitHub @Adityatorgal17