Skip to content

A secure, scalable, and role-based backend API for a ride booking system using Express.js and Mongoose.

Notifications You must be signed in to change notification settings

coder7475/ride-booking-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

230 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ride Booking System

A modern, scalable ride-booking platform built with a TypeScript monorepo architecture using Turborepo. This system provides comprehensive functionality for riders, drivers, and administrators similar to popular ride-sharing services like Uber or Lyft.

🌟 Features

  • πŸ” Role-based Authentication: Secure JWT-based auth for riders, drivers, and admins
  • πŸš— Ride Management: Complete ride lifecycle from request to completion
  • πŸ’° Transaction Processing: Integrated payment and earnings system
  • πŸ—οΈ Scalable Architecture: Modular monorepo structure with shared packages

πŸ—οΈ Architecture

This monorepo contains the following apps and packages:

πŸ“± Applications

  • backend: Express.js REST API with MongoDB integration
    • User authentication and authorization
    • Ride management system
    • Driver and rider functionality
    • Admin panel APIs
    • Transaction processing
  • frontend: React + Vite application for the user interface
    • Modern Vite build system for fast development
    • Responsive design with TailwindCSS
    • Role-based UI components
    • Redux Toolkit for state management
    • Real-time updates

πŸ“¦ Shared Packages

  • @repo/db: Database utilities and MongoDB connector with Redis support
  • @repo/utils: Common utilities including:
    • JWT token management
    • Password hashing
    • Email providers (Gmail, Resend)
    • OTP generation
    • Transaction ID generation
    • URL slug utilities
  • @repo/math: Mathematical utilities for fare calculations and parsing
  • @repo/ui: Shared React component library (using Radix UI and TailwindCSS)

βš™οΈ Configuration Packages

  • @repo/eslint-config: ESLint configurations for Next.js and React
  • @repo/prettier-config: Prettier formatting configurations
  • @repo/typescript-config: TypeScript configurations for different project types

Each package/app is 100% TypeScript with strict type checking.

πŸš€ Quick Start

Prerequisites

  • Node.js >= 18.0.0
  • pnpm >= 8.0.0 (recommended package manager)
  • MongoDB database

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd ride-booking-system
  2. Install dependencies:

    pnpm install
  3. Environment Setup:

    # Copy environment files
    cp apps/backend/.env.example apps/backend/.env
    cp apps/frontend/.env.example apps/frontend/.env
  4. Configure Environment Variables:

    Backend (.env):

    # Server Configuration
    PORT=3000
    HOST=localhost
    NODE_ENV=development
    DB_URI="mongodb://127.0.0.1:27017/practice"
    
    # JWT Configuration
    JWT_ACCESS_SECRET="access"
    JWT_ACCESS_EXPIRES="15m"
    JWT_REFRESH_SECRET="refresh"
    JWT_REFRESH_EXPIRES="1d"
    
    # Hash Salt
    PASSWORD_HASH_SALT=12

    Frontend (.env):

    VITE_BASE_URL="http://localhost:3001/api/v1"
    VITE_GEOCODING_API_KEY="your_geocoding_api_key_here"

Development

# Run all applications in development mode
pnpm dev

# Run only the backend
pnpm backend

# Run specific app
pnpm dev --filter=frontend
pnpm dev --filter=backend

Production Build

# Build all packages and apps
pnpm build

# Start production server
cd apps/backend && pnpm start

πŸ“š API Documentation

The backend provides a comprehensive REST API with the following endpoints:

πŸ” Authentication APIs

Method Endpoint Description
POST /auth/register Register a new user
POST /auth/login Login and receive JWTs
POST /auth/refresh-token Refresh access token
POST /auth/logout Invalidate token/logout
POST /auth/forgot-password Request password reset email
POST /auth/reset-password Reset password with token
POST /auth/change-password Change password (authenticated)

πŸ”‘ OTP APIs

Method Endpoint Description
POST /otp/send Send OTP to email or SMS
POST /otp/verify Verify OTP provided by the user

πŸ‘€ User APIs

Method Endpoint Description
GET /user/me Get current user info (self)
PATCH /user/me Update profile info
DELETE /user/me Deactivate or delete own account
GET /user/:id Get public profile of a user

πŸš— Driver APIs

Method Endpoint Description
POST /drivers/apply Apply to become a driver
GET /drivers/me Get driver profile
PATCH /drivers/me/status Update online/availability status
GET /drivers/me/earnings View earning history
GET /drivers/:id Get Driver Details by Id

πŸš• Ride Management

Method Endpoint Description
GET /rides/fare Estimate fare of a ride
POST /rides/request Rider requests a new ride
PATCH /rides/:id/accept Driver accepts ride
PATCH /rides/:id/picked Update ride status to PICKED_UP
PATCH /rides/:id/transit Update ride status to IN_TRANSIT
PATCH /rides/:id/complete Update ride status to COMPLETED
PATCH /rides/:id/cancel Cancel ride before pickup
GET /rides/me List ride history for current user
GET /rides/:id Get ride details
GET /rides/requests/nearby Get all requested rides near the drivers location
GET /rides/activeRides Get all active ride of driver

πŸ’° Transactions

  • PATCH /api/v1/transactions/pay - Process ride payment

πŸ‘¨β€πŸ’Ό Admin Panel

  • GET /api/v1/admin/users - List all users
  • GET /api/v1/admin/drivers - List all drivers
  • GET /api/v1/admin/rides - List all rides
  • PATCH /api/v1/admin/drivers/:id/approve - Approve driver application
  • PATCH /api/v1/admin/users/:id/block - Block user account

For detailed API documentation, see API_Design.md.

πŸ—οΈ Project Structure

ride-booking-system/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ backend/              # Express.js API server
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ modules/      # Feature modules (auth, user, ride, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ middlewares/  # Express middlewares
β”‚   β”‚   β”‚   β”œβ”€β”€ utils/        # Utility functions
β”‚   β”‚   β”‚   β”œβ”€β”€ types/        # TypeScript type definitions
β”‚   β”‚   β”‚   └── configs/      # Configuration files
β”‚   β”‚   └── dist/             # Compiled JavaScript
β”‚   └── frontend/             # React + Vite application
β”‚       β”œβ”€β”€ src/
β”‚       β”œβ”€β”€ public/
β”‚       └── dist/
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ db/                   # Database utilities
β”‚   β”œβ”€β”€ utils/                # Shared utilities
β”‚   β”œβ”€β”€ math/                 # Mathematical functions
β”‚   └── ui/                   # React components
β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ eslint-config/        # ESLint configurations
β”‚   β”œβ”€β”€ prettier-config/      # Prettier configurations
β”‚   └── typescript-config/    # TypeScript configurations
└── turbo.json                # Turborepo configuration

Utilities

This Turborepo has some additional tools already setup for you:

πŸš€ Deployment

Backend Deployment

The backend is configured for deployment on platforms like Vercel, Railway, or any Node.js hosting service.

# Build for production
pnpm build --filter=backend

# Start production server
cd apps/backend && pnpm start

Frontend Deployment

The frontend can be deployed to Vercel, Netlify, Cloudflare Pages, or any static hosting service.

# Build for production
pnpm build --filter=frontend

# Preview production build locally
pnpm preview --filter=frontend

# Deploy to Cloudflare (if configured)
pnpm deploy --filter=frontend

πŸ› οΈ Available Scripts

# Development
pnpm dev              # Run all apps in development
pnpm backend          # Run only backend
pnpm dev --filter=*   # Run specific app

# Building
pnpm build            # Build all packages and apps
pnpm build --filter=* # Build specific package

# Code Quality
pnpm lint             # Lint all packages
pnpm format           # Format code with Prettier
pnpm check-types      # Type check all packages

# Cleaning
pnpm clean            # Clean all build artifacts

Remote Caching

Tip

Vercel Remote Cache is free for all plans. Get started today at vercel.com.

Turborepo can use a technique known as Remote Caching to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.

By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can create one, then enter the following commands:

cd my-turborepo

# With [global `turbo`](https://turborepo.com/docs/getting-started/installation#global-installation) installed (recommended)
turbo login

# Without [global `turbo`](https://turborepo.com/docs/getting-started/installation#global-installation), use your package manager
npx turbo login
yarn exec turbo login
pnpm exec turbo login

This will authenticate the Turborepo CLI with your Vercel account.

Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your Turborepo:

# With [global `turbo`](https://turborepo.com/docs/getting-started/installation#global-installation) installed (recommended)
turbo link

# Without [global `turbo`](https://turborepo.com/docs/getting-started/installation#global-installation), use your package manager
npx turbo link
yarn exec turbo link
pnpm exec turbo link

πŸ“„ License

This project is licensed under the MIT License.

You are free to use, modify, and distribute this software in accordance with the terms of the MIT License.

About

A secure, scalable, and role-based backend API for a ride booking system using Express.js and Mongoose.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages