Enterprise-Grade, Multi-Tenant Video Streaming API
built with Node.js, Express, MongoDB, and AWS,FFmpeg.
This backend powers a sophisticated Multi-Tenant Video Streaming Platform. It is designed to act as a SaaS foundation where distinct organizations (tenants) can manage their own video assets, users, and permissions in complete isolation.
The system features a Clean Architecture (Controller-Service-Repository) with Dependency Injection, ensuring scalability, testability, and maintainability. It goes beyond simple CRUD by implementing a complex video processing pipeline that includes AI-based sensitivity analysis to automatically flag unsafe content.
- Clean Layered Design: strictly separates concerns into Controllers (HTTP), Services (Business Logic), and Repositories (Data Access).
- Dependency Injection: All dependencies are explicitly injected (configured in
src/config/dependencies.js), avoiding tight coupling. - Centralized Error Handling: Unified error responses and logging.
- Data Isolation: All database queries are scoped by
tenantId. - Tenant-Scoped RBAC: Roles (Admin, Editor, Viewer) are defined within a tenant. A user can be an Admin in one tenant and a Viewer in another.
- SuperAdmin Control: A dedicated layer for platform administrators to manage tenants and global settings.
- High-Performance Uploads: Validated multipart uploads (via
multer) directly to AWS S3. - Automated Processing:
- Frame Extraction:
ffmpegextracts keyframes for analysis. - AI Analysis: Google Gemini AI analyzes frames for Nudity, Violence, and other sensitive content.
- Classification: Videos are automatically marked as
SAFE,FLAGGED, orPENDING_REVIEW.
- Frame Extraction:
- Adaptive Streaming: Supports HTTP Range Requests for smooth playback and seeking.
- WebSocket Updates:
Socket.iointegration pushes real-time video processing progress to the client. - Security First:
helmetfor secure HTTP headers.express-validatorfor strict input sanitization.bcrypt&JWTfor robust authentication.
| Domain | Technologies |
|---|---|
| Runtime | Node.js (v18+) |
| Framework | Express.js v5 |
| Database | MongoDB (Mongoose ODMs) |
| Storage | AWS S3 |
| Processing | FFmpeg, Fluent-FFmpeg |
| AI / ML | Google Generative AI (Gemini) |
| Real-Time | Socket.io |
| Architecture | Repository Pattern, Dependency Injection |
| DevOps | Docker, Husky, ESLint, Prettier |
A detailed look at the codebase organization:
backend/
├── .husky/ # Git hooks (pre-commit linting)
├── Docker/ # Dockerfile and compose configs
├── src/
│ ├── config/ # Configuration & DI Container
| | ├── index.js # Central Config file
│ | ├── dependencies.js # Central Dependency Injection wiring
│ | ├── s3.js # AWS S3 Client setup
│ | └── logger.js # Winston logger config
│ ├── controllers/ # HTTP Request Handlers
│ │ └── processing... # Orchestrate Service calls, handle responses
│ ├── middleware/ # Express Middleware
│ │ ├── auth.middleware.js # JWT verification
│ │ ├── tenant.middleware.js # Enforces tenant isolation
│ │ └── upload.middleware.js # Multer config
│ ├── models/ # Mongoose Schemas (Data Layer)
│ │ ├── video.model.js # Video metadata & analysis results
│ │ └── ...
│ ├── repositories/ # DBMS abstraction layer
│ │ └── ... # Direct DB operations (Find, Save, Update)
│ ├── routes/ # API Route Definitions
│ ├── services/ # CORE Business Logic
│ │ ├── processing.service.js # Orchestrates Video -> AI pipeline
│ │ ├── sensitivity...js # Google Gemini integration
│ │ └── ...
│ ├── socket/ # WebSocket handlers
│ ├── utils/ # Helper functions (Time, Strings)
│ ├── validators/ # Input Validation Rules (express-validator)
│ ├── app.js # Express App setup
│ └── server.js # Server entry point
├── .env.example # Template for environment variables
├── API_QUICK_REFERENCE.md # Handy API lookup
└── REFLECTION.md # Developer notes & architectural decisions
- Node.js (v18+)
- MongoDB (Local or Atlas)
- AWS Account (S3 Bucket & Access Keys)
- Google AI Studio Key (for sensitivity analysis)
Clone the repository and install dependencies:
git clone https://github.com/NaVIn69/Video_streaming_platfrom_backend.git
cd backend
npm installCreate a .env.dev file. You can base it on .env.example:
cp .env.example .env.devRequired Variables:
# Server
PORT=3000
NODE_ENV=dev
# Database
MONGO_URI=mongodb://localhost:27017/video_streaming
# Auth
JWT_SECRET=your_super_secure_secret
JWT_EXPIRES_IN=7d
# AWS S3
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_REGION=us-east-1
AWS_BUCKET_NAME=your_bucket_name
# Google AI
GEMINI_API_KEY=your_gemini_api_key
# Frontend (CORS)
FRONTEND_URL=http://localhost:5173Development Mode (Hot Reloading):
npm run devProduction Mode:
npm start- Upload: Client POSTs video to
/api/videos. User must havevideos.uploadpermission. - Storage:
StorageServicestreams file to AWS S3. - Queuing:
VideoServicecreates a database record (status:uploading->processing). - Processing:
ProcessingServicetriggers.ffmpegextracts frames.SensitivityAnalysisServicesends frames to Gemini.- Result is computed (Safe/Unsafe).
- Notification:
Socket.ioemitsvideo:processedevent to the tenant room.
- Request: Incoming Request contains Bearer Token.
- Auth Middleware: Decodes token, identifying
userIdandtenantId. - Tenant Middleware: Verifies tenant exists and user is active within it.
- RBAC Check: usage of
checkPermission('videos.delete')checks specific role permissions for that tenant.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License.