Skip to content

Repository files navigation

Vidly - Movie Rental API

A robust RESTful API for a movie rental service built with TypeScript, Express.js, and MongoDB. This application provides comprehensive functionality for managing movies, customers, rentals, and user authentication with role-based access control.

🚀 Features

  • Movie Management: CRUD operations for movies with genre categorization
  • Customer Management: Customer registration and profile management
  • Rental System: Complete rental workflow with return processing
  • User Authentication: JWT-based authentication with role-based authorization
  • Admin Panel: Administrative functions for system management
  • Data Validation: Comprehensive input validation using Joi
  • Security: Password hashing, helmet protection, and secure headers
  • Logging: Winston-based logging with MongoDB integration
  • Testing: Comprehensive unit and integration tests with Jest

🛠️ Tech Stack

  • Runtime: Node.js 20.10.0+
  • Language: TypeScript
  • Framework: Express.js
  • Database: MongoDB with Mongoose ODM
  • Authentication: JSON Web Tokens (JWT)
  • Validation: Joi
  • Testing: Jest with Supertest
  • Security: bcrypt, helmet
  • Logging: Winston with MongoDB transport

📁 Project Structure

vidly/
├── config/                 # Environment configurations
├── controllers/            # Route controllers
├── dtos/                   # Data Transfer Objects
├── Middlewares/            # Custom middleware functions
├── models/                 # Mongoose models
├── routes/                 # API route definitions
├── start/                  # Application startup modules
├── tests/                  # Unit and integration tests
├── views/                  # Pug templates
└── public/                 # Static files

🔧 Installation

  1. Clone the repository

    git clone <repository-url>
    cd vidly
  2. Install dependencies

    npm install
  3. Set up environment variables

    # Set JWT private key
    export vidly_jwtPrivateKey="your-jwt-secret-key"
    
    # Set MongoDB connection string (optional, defaults to localhost)
    export vidly_db="mongodb://localhost/vidly"
  4. Start MongoDB

    # Make sure MongoDB is running on your system
    mongod

🚀 Usage

Development Mode

npm run start:dev

Starts the server with nodemon for automatic restarts on file changes.

Production Mode

npm run build
npm start

Compiles TypeScript and runs the production build.

Testing

npm test

Runs the complete test suite with Jest.

📚 API Endpoints

Authentication

  • POST /api/auth - User login

Users

  • POST /api/users - Register new user
  • GET /api/users/me - Get current user profile

Genres

  • GET /api/genres - Get all genres
  • GET /api/genres/:id - Get genre by ID
  • POST /api/genres - Create new genre (Auth required)
  • PUT /api/genres/:id - Update genre (Auth required)
  • DELETE /api/genres/:id - Delete genre (Admin required)

Movies

  • GET /api/movies - Get all movies
  • GET /api/movies/:id - Get movie by ID
  • POST /api/movies - Create new movie (Auth required)
  • PUT /api/movies/:id - Update movie (Auth required)
  • DELETE /api/movies/:id - Delete movie (Admin required)

Customers

  • GET /api/customers - Get all customers
  • GET /api/customers/:id - Get customer by ID
  • POST /api/customers - Create new customer (Auth required)
  • PUT /api/customers/:id - Update customer (Auth required)
  • DELETE /api/customers/:id - Delete customer (Admin required)

Rentals

  • GET /api/rentals - Get all rentals
  • POST /api/rentals - Create new rental (Auth required)

Returns

  • POST /api/returns - Process movie return (Auth required)

🔐 Authentication

The API uses JWT tokens for authentication. Include the token in the request header:

x-auth-token: your-jwt-token

User Roles

  • Regular User: Can create rentals, manage own profile
  • Admin: Full access to all resources including delete operations

🧪 Testing

The project includes comprehensive testing:

  • Unit Tests: Individual component testing
  • Integration Tests: API endpoint testing
  • Test Coverage: Controllers, models, and middleware

Run specific test suites:

# Integration tests only
npm test -- --testPathPattern=integration

# Unit tests only
npm test -- --testPathPattern=unit

📝 Configuration

Configuration files are located in the config/ directory:

  • default.json - Default configuration
  • development.json - Development environment
  • production.json - Production environment
  • test.json - Test environment
  • custom-environment-variables.json - Environment variable mappings

🔒 Security Features

  • Password hashing with bcrypt
  • JWT token-based authentication
  • Input validation and sanitization
  • Security headers with Helmet
  • MongoDB injection protection
  • Rate limiting and compression

📊 Logging

Winston logger with multiple transports:

  • Console logging for development
  • File logging for production
  • MongoDB logging for persistent storage

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

👨‍💻 Author

Hossein Rezaei


For more information or support, please refer to the API documentation or contact the development team.

About

A robust RESTful API for a movie rental service built with TypeScript, Express.js, and MongoDB. This application provides comprehensive functionality for managing movies, customers, rentals, and user authentication with role-based access control.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Used by

Contributors

Languages