Skip to content

rohitkumarnaidu/netflix-clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎬 Netflix Clone Backend

A complete backend API for a Netflix clone built with Node.js, Express, and MongoDB.

✨ Features

βœ… Completed Features

  • πŸ”₯ Trending Section API - Fetch trending movies/shows
  • 🎬 Movie Management - CRUD operations for movies
  • πŸ” Authentication - User signup, login with JWT
  • ❀️ Watchlist - Add/remove movies to user's watchlist
  • πŸ”Ž Search - Search movies with filters
  • πŸ›‘οΈ Route Protection - Middleware for protected routes

πŸš€ Coming Soon

  • User ratings and reviews
  • Recommendation system
  • Video streaming endpoints
  • Social features

πŸ› οΈ Tech Stack

  • Backend: Node.js, Express.js
  • Database: MongoDB with Mongoose ODM
  • Authentication: JWT (JSON Web Tokens)
  • Validation: Express-validator
  • Security: bcryptjs for password hashing
  • CORS: Enabled for frontend integration

πŸ“‹ Prerequisites

  • Node.js (v14 or higher)
  • MongoDB (local or cloud)
  • npm or yarn

πŸš€ Quick Start

1. Clone and Install Dependencies

git clone <your-repo-url>
cd netflix-clone
npm install

2. Environment Setup

Copy the config file and update with your values:

cp config.env.example config.env

Update config.env:

MONGODB_URI=mongodb://localhost:27017/netflix-clone
JWT_SECRET=your-super-secret-jwt-key-change-this
PORT=5000
NODE_ENV=development

3. Start MongoDB

Local MongoDB:

# Start MongoDB service
mongod

# Or using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latest

Cloud MongoDB (MongoDB Atlas):

  • Create account at MongoDB Atlas
  • Create cluster and get connection string
  • Update MONGODB_URI in config.env

4. Seed Database (Optional)

npm run seed

5. Start Server

# Development mode
npm run dev

# Production mode
npm start

Server will start at: http://localhost:5000

πŸ“š API Endpoints

πŸ”₯ Trending Section (First Feature)

GET /api/movies/trending

Returns trending movies with isTrending: true

🎬 Movies

GET    /api/movies              # Get all movies with pagination
GET    /api/movies/:id          # Get movie by ID
POST   /api/movies              # Add new movie (admin only)
PUT    /api/movies/:id          # Update movie (admin only)
DELETE /api/movies/:id          # Delete movie (admin only)

πŸ”Ž Search

GET /api/movies/search?q=dark&genre=horror&year=2020&rating=8

πŸ” Authentication

POST /api/auth/signup          # User registration
POST /api/auth/login           # User login
GET  /api/auth/profile         # Get user profile (protected)
PUT  /api/auth/profile         # Update profile (protected)

❀️ Watchlist

GET    /api/watchlist                    # Get user's watchlist (protected)
POST   /api/watchlist                    # Add movie to watchlist (protected)
DELETE /api/watchlist/:movieId           # Remove from watchlist (protected)
PUT    /api/watchlist/:movieId           # Update watchlist item (protected)
GET    /api/watchlist/status/:movieId    # Check watchlist status (protected)

πŸ§ͺ Testing the API

1. Test Trending Endpoint

curl http://localhost:5000/api/movies/trending

2. Test Search

curl "http://localhost:5000/api/movies/search?q=stranger"

3. Test User Signup

curl -X POST http://localhost:5000/api/auth/signup \
  -H "Content-Type: application/json" \
  -d '{
    "email": "test@example.com",
    "password": "password123",
    "username": "testuser"
  }'

4. Test Protected Route

# First get token from login
curl -X POST http://localhost:5000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "test@example.com",
    "password": "password123"
  }'

# Use token in Authorization header
curl http://localhost:5000/api/watchlist \
  -H "Authorization: Bearer YOUR_TOKEN_HERE"

πŸ“ Project Structure

netflix-clone/
β”œβ”€β”€ models/                 # Database models
β”‚   β”œβ”€β”€ Movie.js          # Movie schema
β”‚   β”œβ”€β”€ User.js           # User schema
β”‚   └── Watchlist.js      # Watchlist schema
β”œβ”€β”€ controllers/           # Route controllers
β”‚   β”œβ”€β”€ movieController.js
β”‚   β”œβ”€β”€ authController.js
β”‚   └── watchlistController.js
β”œβ”€β”€ routes/               # API routes
β”‚   β”œβ”€β”€ movies.js
β”‚   β”œβ”€β”€ auth.js
β”‚   └── watchlist.js
β”œβ”€β”€ middleware/           # Custom middleware
β”‚   β”œβ”€β”€ auth.js          # JWT authentication
β”‚   └── validation.js    # Input validation
β”œβ”€β”€ scripts/             # Utility scripts
β”‚   └── seedMovies.js    # Database seeder
β”œβ”€β”€ server.js            # Main server file
β”œβ”€β”€ package.json         # Dependencies
β”œβ”€β”€ config.env           # Environment variables
└── README.md            # This file

πŸ”§ Configuration

Environment Variables

  • MONGODB_URI: MongoDB connection string
  • JWT_SECRET: Secret key for JWT tokens
  • PORT: Server port (default: 5000)
  • NODE_ENV: Environment (development/production)

Database Schema

  • Movies: title, description, genre, rating, poster/banner URLs, trending flags
  • Users: email, password (hashed), username, admin status, watchlist
  • Watchlist: user reference, movie reference, watched status, rating, notes

πŸš€ Deployment

This project is configured for easy deployment to cloud platforms.

Quick Deploy

  1. Backend: Deploy to Render using render.yaml configuration
  2. Frontend: Deploy to Netlify/Vercel using provided config files
  3. Full Guide: See deployment.md for complete step-by-step instructions

Files Added for Deployment

  • render.yaml - Render deployment configuration
  • netlify.toml - Netlify deployment settings
  • vercel.json - Vercel deployment configuration
  • .env.example - Environment variables template
  • js/config.js - Frontend environment configuration
  • deployment.md - Complete deployment guide

Local Production

NODE_ENV=production npm start

🀝 Contributing

  1. Fork the repository
  2. Create feature branch
  3. Commit changes
  4. Push to branch
  5. Create Pull Request

πŸ“ License

This project is licensed under the ISC License.

Made with ❀️ by Rohit


Happy Coding! 🎬✨

About

🎬 Netflix Clone built with React, Node.js, Express, and MongoDB | Features: authentication, movie browsing, search, and My List

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors