https://github.com/sarwar-asik/study-live-server
Realtime WebRTC Backend about chat/audio/video
https://github.com/sarwar-asik/study-live-server
docker express multer nodejs postgresql prisma socket-io swagger webrtc
Last synced: 3 months ago
JSON representation
Realtime WebRTC Backend about chat/audio/video
- Host: GitHub
- URL: https://github.com/sarwar-asik/study-live-server
- Owner: sarwar-asik
- Created: 2024-07-30T20:05:47.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-10T06:59:30.000Z (over 1 year ago)
- Last Synced: 2025-04-15T01:45:58.200Z (about 1 year ago)
- Topics: docker, express, multer, nodejs, postgresql, prisma, socket-io, swagger, webrtc
- Language: TypeScript
- Homepage: https://study-live-server-2.onrender.com/api-docs
- Size: 7.08 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Study Live Server
[](https://nodejs.org)
[](https://www.typescriptlang.org)
[](https://socket.io)
[](https://kafka.apache.org)
[](https://www.postgresql.org)
## Overview
A powerful real-time communication server supporting audio/video calls, chat, and file sharing. Built with modern technologies and best practices for scalability and performance.
## Features
### Authentication & Security
- JWT-based authentication
- Role-based access control
- Secure password hashing
- CORS protection
### Real-Time Communication
- Text chat with typing indicators
- Audio/Video calls using WebRTC
- File sharing & image uploads
- Presence detection
### Scalability
- Kafka integration for distributed events
- Socket.IO for real-time communication
- Horizontal scaling support
- Redis for session management
### Developer Experience
- TypeScript for type safety
- Swagger API documentation
- Prisma ORM for database operations
- Husky for git hooks
## Quick Start
### Prerequisites
- Node.js (v18.x or later)
- PostgreSQL (v14.x or later)
- Kafka cluster
- Redis (optional, for session storage)
### Installation
1. **Clone the repository**
```bash
git clone https://github.com/sarwar-asik/study-live-server
cd study-live-server
```
2. **Install dependencies**
```bash
npm install
```
3. **Set up environment variables**
Create a `.env` file in the root directory (see Environment Variables section below)
4. **Run database migrations**
```bash
npx prisma migrate dev
```
5. **Start the server**
```bash
# Development
npm run dev
# Production
npm run build
npm start
```
## Environment Variables
Create a `.env` file in the root directory with the following variables:
```env
# Server Configuration
PORT=5000
NODE_ENV=development
SERVER_NAME=study-live-server
# Database
DATABASE_URL="postgresql://user:password@localhost:5432/dbname"
# Authentication
JWT_SECRET=your-jwt-secret
JWT_EXPIRES_IN=7d
BCRYPT_SALT_ROUNDS=12
# Admin Credentials
SUPER_ADMIN_EMAIL=admin@example.com
SUPER_ADMIN_PASSWORD=admin123
DEFAULT_STUDENT_PASS=student123
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret
# Kafka Configuration
KAFKA_CLIENT_ID=study-live-server
KAFKA_BROKERS=kafka://kafka-0.kafka.svc.cluster.local:9092,kafka-1.kafka.svc.cluster.local:9092
# Frontend URL (CORS)
FRONTEND_URL=http://localhost:3000
```
## API Documentation
### REST Endpoints
#### Authentication
- `POST /api/auth/sign-up` - Register new user
- `POST /api/auth/login` - User login
- `GET /api/auth/profile` - Get user profile
- `GET /api/user/:id` - Get user details
#### Messaging
- `POST /api/messages` - Send message
- `POST /api/messages/image` - Send message with image
- `GET /api/messages` - Get conversation history
### Socket.IO Events
#### Chat Events
- `send-message` - Send chat message
- `new-message` - Receive new message
- `typing` - User typing indicator
#### Video Chat Events
- `join-room` - Join video chat room
- `offer` - WebRTC offer
- `answer` - WebRTC answer
- `ice-candidate` - ICE candidate exchange
### Kafka Topics
- `room-join` - Room join events
- `room-leave` - Room leave events
- `webrtc-offer` - WebRTC offers
- `webrtc-answer` - WebRTC answers
- `ice-candidate` - ICE candidates
## Security Features
- JWT authentication
- Request validation using Zod
- CORS protection
- Rate limiting
- Secure password hashing
- Input sanitization
## Testing
```bash
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
```
## Production Deployment
1. Build the application:
```bash
npm run build
```
2. Start the production server:
```bash
npm start
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Contributing
1. Fork the repository
2. Create your feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request
## Support
For support, email support@studylive.com or join our Slack channel.