Built with Node.js, Express.js, and MongoDB
StreamHive is a video-sharing backend that provides authentication, video management, media uploads, and social features through a REST API.
Built with a clean architecture to support scalable and maintainable API development.
- 🔐 JWT Authentication & Authorization
- 👤 User Profile Management
- 🎥 Video CRUD Operations
- ☁️ Cloudinary Media Upload
- 💬 Comments System
- ❤️ Like / Unlike System
- 🔔 Channel Subscription
- 📂 Playlist Management
- 📝 Community Posts
- 📊 Creator Dashboard
- 🕒 Watch History
| Technology | Usage |
|---|---|
| Node.js | Backend Runtime |
| Express.js | API Framework |
| MongoDB | Database |
| Mongoose | ODM |
| JWT | Authentication |
| Cloudinary | Media Storage |
| Multer | File Upload |
| Nodemailer | Email Service |
src/
├── controllers
├── models
├── routes
├── middlewares
├── utils
├── db
├── app.js
└── index.js
git clone https://github.com/wahidulsami/backend.git
cd backend
npm install
npm run devCreate .env:
PORT=8000
MONGODB_URI=
ACCESS_TOKEN_SECRET=
REFRESH_TOKEN_SECRET=
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=StreamHive runs as two Docker Compose services:
Client
│
▼
StreamHive backend :8000
│
│ internal network: mongodb:27017
▼
MongoDB 8 ── named volume: mongodb_data
backendruns the Node.js/Express API as a non-root user.mongodbruns MongoDB 8 with authentication enabled.- MongoDB is reachable by the backend as
mongodb:27017; it is not exposed on the host. - The backend starts only after MongoDB passes its authenticated healthcheck.
- The named
mongodb_datavolume keeps database data when containers are recreated. - Docker generates the internal
MONGODB_URIand URL-encodes credentials safely.
- Docker and Docker Compose installed
- Create your local environment file. Never commit
.env:
cp .env.example .env- Fill in the required variables in
.env. Use strong, unique values:
ACCESS_TOKEN_SECRET=use-a-long-random-secret
REFRESH_TOKEN_SECRET=use-another-long-random-secret
MONGO_INITDB_ROOT_USERNAME=streamhive_admin
MONGO_INITDB_ROOT_PASSWORD=use-a-long-random-password
MONGO_INITDB_DATABASE=youtubeDocker generates
MONGODB_URIinside the backend container and safely URL-encodes the MongoDB credentials. Do not put a DockerlocalhostURI in.env.
MONGODB_URI is generated automatically for Docker. Do not use localhost for the backend-to-MongoDB connection.
- Build and start StreamHive:
docker compose up --build-
The API is available at
http://localhost:8000. -
Verify the backend:
curl http://localhost:8000/health
docker compose psBoth services should show as healthy.
# Stop containers
docker compose down
# Stop and remove volumes (deletes database data)
docker compose down -v
# View logs
docker compose logs backend
docker compose logs mongodb
# Rebuild after code changes
docker compose up --build
# Validate Compose configuration without starting services
docker compose config -q- MongoDB is private to the Compose network and is not published to the host
- Data is persisted in a named Docker volume (
mongodb_data) - The database name is
youtube(set insrc/constants.js). - Do not run
docker compose down -vunless you intentionally want to delete the database.
- Backend:
GET /health— used by Docker and orchestrators - MongoDB: authenticated
db.adminCommand('ping')— used by Docker Compose
docker compose up
│
├── Start MongoDB with authentication
├── Wait for the authenticated MongoDB ping to pass
├── Generate the internal MongoDB URI for StreamHive
├── Validate environment variables with Zod
├── Connect Mongoose to MongoDB
└── Start Express on port 8000
If required variables are missing or invalid, the backend exits safely and prints validation messages without printing secret values.
| Module | Description |
|---|---|
| Users | Authentication & profiles |
| Videos | Upload & management |
| Comments | User interactions |
| Likes | Engagement system |
| Subscriptions | Channel system |
| Playlists | Video collections |
| Dashboard | Creator analytics |
Client
|
Express API
|
Controllers
|
Models
|
MongoDB
Contributions are welcome.
Fork → Create Branch → Commit → Pull Request
MIT License
Wahidul Islam Sami
GitHub: https://github.com/wahidulsami