Skip to content

🎬 A comprehensive movie database REST API built with Node.js, Express & MongoDB. Features JWT authentication, role-based access control, advanced movie filtering, review system, and secure CRUD operations for movies, users, genres & roles.

Notifications You must be signed in to change notification settings

Scylox56/scydb-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

86 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ScyDB API 🎬

A comprehensive movie database API built with Node.js, Express, and MongoDB. ScyDB (Screen Database) provides a robust backend for managing movies, users, reviews, genres, and roles with advanced authentication and authorization features.

πŸš€ Features

  • Authentication & Authorization: JWT-based auth with role-based access control
  • Movie Management: CRUD operations for movies with advanced filtering and search
  • Review System: Users can review movies with ratings and comments
  • Genre Management: Dynamic genre system with color coding
  • Role-Based Access: Three-tier role system (client, admin, super-admin) extra roles can be added
  • User Management: Profile management and watchlist functionality
  • Rate Limiting: Protection against abuse with configurable limits
  • Security: Helmet, CORS, HPP protection, and XSS cleaning
  • File Upload: Cloudinary integration for image handling
  • Data Seeding: Pre-populated roles and genres

πŸ› οΈ Tech Stack

  • Backend: Node.js, Express.js
  • Database: MongoDB with Mongoose ODM
  • Authentication: JWT (JSON Web Tokens)
  • Security: CORS, HPP, XSS-Clean
  • File Storage: Cloudinary
  • Rate Limiting: Express Rate Limit
  • Validation: Custom middleware validation
  • Development: Nodemon for hot reloading

πŸ”— Related Repositories

  • scydb-website – The frontend client built with HTML, CSS, and JavaScript

πŸ“¦ Installation

  1. Clone the repository
git clone https://github.com/Scylox56/scydb-api.git
cd scydb-api
  1. Install dependencies
npm install
  1. Environment Setup Create a .env file in the root directory:
DB_URI=mongodb://127.0.0.1:27017/scydb
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRES_IN=90d
JWT_COOKIE_EXPIRES_IN=7
NODE_ENV=development
CLOUDINARY_CLOUD_NAME=your-cloudinary-name
CLOUDINARY_API_KEY=your-cloudinary-key
CLOUDINARY_API_SECRET=your-cloudinary-secret
  1. Start MongoDB Make sure MongoDB is running on your system.
  2. Seed the database
   npm run seed:import
  1. Start the server
# Development mode
npm run dev

# Production mode
npm start

🎯 API Endpoints

  • Authentication
POST /api/v1/auth/signup         - User registration
POST /api/v1/auth/login          - User login
GET  /api/v1/auth/logout         - User logout
GET  /api/v1/auth/check          - Check auth status
  • Movies
GET    /api/v1/movies            - Get all movies (with filtering/search)
GET    /api/v1/movies/:id        - Get single movie
POST   /api/v1/movies            - Create movie (admin only)
PATCH  /api/v1/movies/:id        - Update movie (admin only)
DELETE /api/v1/movies/:id        - Delete movie (admin only)
  • Reviews
GET    /api/v1/movies/:movieId/reviews     - Get movie reviews
POST   /api/v1/movies/:movieId/reviews     - Create review (authenticated)
PATCH  /api/v1/reviews/:id                 - Update review (owner only)
DELETE /api/v1/reviews/:id                 - Delete review (owner/admin)
GET    /api/v1/reviews/my                  - Get user's reviews
GET    /api/v1/reviews/admin               - Get all reviews (admin)
  • Users
GET    /api/v1/users/me                    - Get current user
PATCH  /api/v1/users/updateMe              - Update profile
PATCH  /api/v1/users/updateMyPassword      - Update password
DELETE /api/v1/users/deleteMe              - Deactivate account
POST   /api/v1/users/watchlist/:movieId    - Add to watchlist
DELETE /api/v1/users/watchlist/:movieId    - Remove from watchlist
GET    /api/v1/users                       - Get all users (admin)
GET    /api/v1/users/stats                 - User statistics (admin)
  • Genres
GET    /api/v1/genres                      - Get all genres
GET    /api/v1/genres/active               - Get active genres
GET    /api/v1/genres/stats                - Genre statistics
POST   /api/v1/genres                      - Create genre (admin)
PATCH  /api/v1/genres/:id                  - Update genre (admin)
DELETE /api/v1/genres/:id                  - Delete genre (admin)
PATCH  /api/v1/genres/bulk                 - Bulk update genres (admin)
  • Roles
GET    /api/v1/roles                       - Get all roles
GET    /api/v1/roles/stats                 - Role statistics
POST   /api/v1/roles                       - Create role (super-admin)
PATCH  /api/v1/roles/:id                   - Update role (super-admin)
DELETE /api/v1/roles/:id                   - Delete role (super-admin)

πŸ” Advanced Features

  • Movie Filtering & Search
GET /api/v1/movies?search=batman           - Search in title, director, cast, description
GET /api/v1/movies?genre=Action            - Filter by genre
GET /api/v1/movies?director=Christopher    - Filter by director
GET /api/v1/movies?cast=Leonardo           - Filter by cast member
GET /api/v1/movies?yearFrom=2020           - Movies from 2020 onwards
GET /api/v1/movies?yearTo=2023             - Movies up to 2023
GET /api/v1/movies?duration=90-120         - Filter by duration range
GET /api/v1/movies?sort=newest             - Sort options: newest, oldest, title, rating
GET /api/v1/movies?page=2&limit=10         - Pagination

Role-Based Access Control

  • Client: Can view movies, create reviews, manage own profile
  • Admin: All client permissions + manage movies, view all reviews
  • Super-Admin: All permissions + manage users, roles, and system settings

πŸ—‚οΈ Project Structure

scydb-api/
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ cloudinary.js          # Cloudinary configuration
β”‚   └── db.js                  # Database connection
β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ authController.js      # Authentication logic
β”‚   β”œβ”€β”€ movieController.js     # Movie CRUD operations
β”‚   β”œβ”€β”€ userController.js      # User management
β”‚   β”œβ”€β”€ reviewController.js    # Review system
β”‚   β”œβ”€β”€ genreController.js     # Genre management
β”‚   └── roleController.js      # Role management
β”œβ”€β”€ middlewares/
β”‚   β”œβ”€β”€ auth.js                # Authentication middleware
β”‚   β”œβ”€β”€ error.js               # Error handling
β”‚   β”œβ”€β”€ rateLimiter.js         # Rate limiting config
β”‚   └── validation.js          # Input validation
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ User.js                # User schema
β”‚   β”œβ”€β”€ Movie.js               # Movie schema
β”‚   β”œβ”€β”€ Review.js              # Review schema
β”‚   β”œβ”€β”€ Genre.js               # Genre schema
β”‚   └── Role.js                # Role schema
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ authRoutes.js          # Auth endpoints
β”‚   β”œβ”€β”€ movieRoutes.js         # Movie endpoints
β”‚   β”œβ”€β”€ userRoutes.js          # User endpoints
β”‚   β”œβ”€β”€ reviewRoutes.js        # Review endpoints
β”‚   β”œβ”€β”€ genreRoutes.js         # Genre endpoints
β”‚   └── roleRoutes.js          # Role endpoints
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ APIFeatures.js         # Query helpers
β”‚   β”œβ”€β”€ appError.js            # Custom error class
β”‚   β”œβ”€β”€ email.js               # Email utilities
β”‚   └── utils.js               # General utilities
β”œβ”€β”€ app.js                     # Express app setup
β”œβ”€β”€ server.js                  # Server entry point
└── seeder.js                  # Database seeding

πŸ“Š Database Models

User Schema

  • Name, email, password (hashed)
  • Role (client/admin/super-admin)
  • Profile photo, watchlist
  • Password change tracking Movie Schema
  • Title, year, duration, description
  • Genre array, director, cast array
  • Poster, backdrop, trailer URLs
  • Virtual reviews population Review Schema
  • Rating (1-10), review text
  • User and movie references
  • A Constraint (one review per user per movie) Genre Schema
  • Name, description, color
  • Active status, movie count virtual Role Schema
  • Name, description
  • Permissions array
  • User count tracking

πŸ”’ Security Features

  • JWT Authentication: Secure token-based auth
  • Password Hashing: bcryptjs encryption
  • Rate Limiting: API abuse prevention
  • CORS: Cross-origin request handling
  • Helmet: Security headers
  • HPP: HTTP Parameter Pollution protection
  • XSS Protection: Input sanitization
  • Input Validation: Custom middleware validation

πŸ§ͺ Available Scripts

npm start              # Start production server
npm run dev            # Start development server with nodemon
npm run seed:import    # Import default roles and genres
npm run seed:delete    # Clear all roles and genres
npm test               # Run tests (placeholder)

🀝 Contributing

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/a-feature)
  3. Commit your changes (git commit -m 'Added a feature')
  4. Push to the branch (git push origin feature/a-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License.

πŸ‘¨β€πŸ’» Author

Created with ❀️ by [Scylox56]

πŸ”— Links Live Demo


⭐ Don't forget to star this repo if you found it helpful!

About

🎬 A comprehensive movie database REST API built with Node.js, Express & MongoDB. Features JWT authentication, role-based access control, advanced movie filtering, review system, and secure CRUD operations for movies, users, genres & roles.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published