Skip to content

ibrahim11elian/PeakBooker

Repository files navigation

PeakBooker App

This project is a tour booking application based on the Node.js course by Jonas Schmedtmann. I have added several improvements to enhance the application's functionality and user experience.

Table of Contents

Folder Structure

.
├── api
│   ├── controllers
│   │   ├── authController.js
│   │   ├── baseController.js
│   │   ├── bookingController.js
│   │   ├── errorController.js
│   │   ├── reviewController.js
│   │   ├── toursController.js
│   │   └── usersController.js
│   ├── models
│   │   ├── bookingModel.js
│   │   ├── refreshTokenModel.js
│   │   ├── reviewModel.js
│   │   ├── tourModel.js
│   │   └── userModel.js
│   ├── routes
│   │   ├── booking-routes.js
│   │   ├── index.js
│   │   ├── reviews-routes.js
│   │   ├── tours-routes.js
│   │   └── users-routes.js
│   └── utils
│       ├── api-features.js
│       ├── email.js
│       ├── error.js
│       ├── firebase-config.js
│       ├── folder-builder.js
│       ├── imageUploader.js
│       └── logger.js
├── app.js
├── app.log
├── eslint.config.js
├── package.json
├── package-lock.json
├── README.md
├── server.js
├── vercel.json
└── views
    ├── baseEmail.pug
    ├── passwordReset.pug
    ├── _style.pug
    ├── verify.pug
    └── welcome.pug

Features

  • User Management: Register, login, update profile, and deactivate accounts, forget password, reset password.
  • Tour Management: Create, read, update, and delete tours, top 5 cheapest tours, tours statistics, busiest month in a year, tours within distance, closest tours from specific point(coordinate).
  • Booking Management: Create, read, update, and delete bookings, checkout booking, tour bookings, user bookings.
  • Review Management: Create, read, update, and delete reviews, tour reviews.
  • Payment Integration: Integrated with Stripe for secure payments.
  • Photo Uploading: Upload and resize user photos, stored in Firebase.
  • Email Notifications: Automated emails for user registration, booking confirmations, and password reset, resend email confirmation.
  • Pagination support.
  • Limit returned fields.
  • Sort returned data.
  • Error Handling: Improved error handling for both development and production environments.
  • Logging: Implemented request logging using Morgan and application logging using Winston.development and production environments.

Technologies Used

  • Node.js
  • Express.js
  • MongoDB
  • Mongoose
  • Stripe API
  • Firebase Storage
  • Nodemailer
  • JWT
  • Multer
  • Sharp (for image processing)
  • Pug (for email templating)
  • Morgan, Winston (for logging)
  • ESLint, Prettier (for code quality)

Installation

  1. Clone the repository:

    git clone https://github.com/ibrahim11elian/PeakBooker.git
  2. Navigate to the project directory:

    cd booking-app
  3. Install the dependencies:

    npm install
  4. Set up your environment variables by creating a .env file in the root directory and adding the following:

    PORT=3000
    
    NODE_ENV=development
    
    DB_STRING=
    
    DB_USER=
    DB_PASSWORD=
    
    
    HASH_SALT=
    
    JWT_SECRET=
    JWT_EXPIRES_IN=
    JWT_COOKIE_EXPIRES_IN=
    JWT_REFRESH_SECRET=
    
    # Mailtrap (development env)
    EMAIL_USERNAME=
    EMAIL_PASSWORD=
    EMAIL_HOST=
    EMAIL_PORT=
    
    # Sendgrid
    SENDGRID_USERNAME=
    SENDGRID_PASSWORD=
    
    # Company Email
    EMAIL_FROM=
    
    # Stripe Key
    STRIPE_KEY=
    WEBHOOK_SECRET=
    
    # Firebase
    FIREBASE_API_KEY=
    FIREBASE_AUTH_DOMAIN=
    FIREBASE_PROJECT_ID=
    FIREBASE_STORAGE_BUCKET=
    FIREBASE_MESSAGING_SENDER_ID=
    FIREBASE_APP_ID=
    FIREBASE_MEASUREMENT_ID=
    
    FIREBASE_PRIVATE_KEY=
    FIREBASE_CLIENT_EMAIL=

Usage

  1. Start the development server:
    npm run start
  2. The application will be running on http://localhost:3000.

Error Handling

  • Development Mode: Detailed error information including stack trace.
  • Production Mode: Simplified error messages to prevent information leakage.
  • Custom Error Types: Handling of specific errors like CastError, ValidationError, JWT errors, and MongoDB duplicate errors.

Documentation

API Documentation