Skip to content

πŸš™ Backend API for DriveNest car rental platform. Handles car listings, booking management, user authentication, and real-time search with MongoDB and Firebase integration. Ready for production deployment on Vercel.

Notifications You must be signed in to change notification settings

Mehedi-Hasan-code/Drive_Nest_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš— DriveNest Server

A robust backend API for a car rental platform built with Node.js, Express, MongoDB, and Firebase Authentication.

✨ Features

  • πŸ” Firebase Authentication - Secure user authentication and authorization
  • πŸš™ Car Management - Complete CRUD operations for car listings
  • πŸ“… Booking System - Handle car reservations and booking status
  • πŸ” Search & Filter - Search cars by model, location, and availability
  • πŸ‘€ User-specific Data - Manage user's cars and bookings
  • πŸ›‘οΈ Security Middleware - Token verification and email validation
  • ☁️ Cloud Ready - Configured for Vercel deployment

πŸ› οΈ Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Database: MongoDB
  • Authentication: Firebase Admin SDK
  • Deployment: Vercel

πŸ“‹ Prerequisites

Before running this project, make sure you have:

  • Node.js (v14 or higher)
  • MongoDB Atlas account
  • Firebase project with service account
  • npm or yarn package manager

πŸš€ Quick Start

1. Clone the repository

git clone <repository-url>
cd DriveNest_Server

2. Install dependencies

npm install

3. Environment Setup

Create a .env file in the root directory:

# MongoDB Connection
MONGODB_URI=your_mongodb_connection_string

# Firebase Service Account (Base64 encoded)
FB_SERVICE_KEY=your_base64_encoded_firebase_service_account

# Server Configuration
PORT=3000

4. Firebase Setup

  1. Go to Firebase Console
  2. Create a new project or use existing one
  3. Generate a service account key (JSON)
  4. Convert the JSON to base64 and set it as FB_SERVICE_KEY

5. Start the development server

npm start

The server will start on http://localhost:3000

πŸ“‘ API Endpoints

πŸš— Cars

Method Endpoint Description Auth Required
GET /cars Get all cars with optional filters ❌
GET /cars/:id Get single car details ❌
GET /my-cars Get user's cars βœ…
POST /cars Add new car βœ…
PATCH /cars/:id Update car details βœ…
DELETE /cars Delete user's car βœ…

πŸ“… Bookings

Method Endpoint Description Auth Required
GET /bookings Get user's bookings βœ…
POST /bookings Create new booking βœ…
PATCH /bookings/:id/date Update booking date βœ…
PATCH /bookings/:id/status Update booking status βœ…

πŸ” Query Parameters

Cars Endpoint (/cars)

  • availability - Filter by availability status
  • searchQuery - Search by car model or location

Authentication Endpoints

  • email - User email (required for protected routes)

πŸ”’ Authentication

This API uses Firebase Authentication with custom middleware:

  1. Token Verification: Validates Firebase ID tokens
  2. Email Verification: Ensures request email matches token email

Headers Required for Protected Routes:

Authorization: Bearer <firebase-id-token>

πŸ—οΈ Project Structure

DriveNest_Server/
β”œβ”€β”€ index.js          # Main application file
β”œβ”€β”€ package.json       # Dependencies and scripts
β”œβ”€β”€ vercel.json       # Vercel deployment config
β”œβ”€β”€ .env              # Environment variables
└── README.md         # Project documentation

πŸ”§ Middleware

  • CORS: Configured for cross-origin requests
  • Express JSON: Parse JSON request bodies
  • Cookie Parser: Handle cookies
  • Custom Auth: Firebase token verification
  • Email Verification: Match request email with token

🌐 Deployment

Vercel Deployment

This project is configured for easy deployment on Vercel:

  1. Connect your GitHub repository to Vercel
  2. Set environment variables in Vercel dashboard
  3. Deploy automatically with each push

Environment Variables for Production

Make sure to set these in your deployment platform:

  • MONGODB_URI
  • FB_SERVICE_KEY
  • PORT (optional, defaults to 3000)

πŸ§ͺ Testing

Currently, no tests are configured. To add testing:

# Install testing dependencies
npm install --save-dev jest supertest

# Add test script to package.json
"test": "jest"

🀝 Contributing

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

πŸ“ License

This project is licensed under the ISC License.

πŸ”— Related Projects

  • Frontend Repository: [Add your frontend repo link]
  • Live Demo: [Add your demo link]

πŸ“ž Support

If you have any questions or need help, please:

  1. Check the Issues page
  2. Create a new issue if needed
  3. Contact the development team

Built with ❀️ for the DriveNest community

About

πŸš™ Backend API for DriveNest car rental platform. Handles car listings, booking management, user authentication, and real-time search with MongoDB and Firebase integration. Ready for production deployment on Vercel.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published