Skip to content

Sanskriti10247/Rapido-RideShare-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Java Spring Boot MongoDB JWT Maven License

RideShare Backend – Spring Boot & MongoDB

A complete Ride Sharing Backend API built using Spring Boot, MongoDB, JWT Authentication, Input Validation, and Global Exception Handling.
This project supports user registration, login, ride booking, driver acceptance, and ride completion with role-based access.


πŸ› οΈ Tech Stack

  • Java 17
  • Spring Boot 3.2.5
  • MongoDB
  • Spring Security
  • JWT Authentication
  • Hibernate Validator
  • Maven
  • Tomcat Embedded Server

Project Folder Structure

src/main/java/com/Sanskriti/Rapido/
 β”œβ”€β”€ model/
 β”œβ”€β”€ repository/
 β”œβ”€β”€ service/
 β”œβ”€β”€ controller/
 β”œβ”€β”€ config/
 β”œβ”€β”€ dto/
 β”œβ”€β”€ exception/
 └── util/

User Roles

  • ROLE_USER β†’ Passenger
  • ROLE_DRIVER β†’ Driver

Features Implemented

πŸ” Authentication

  • User Registration (BCrypt password encryption)
  • User Login with JWT Token
  • Role-based access control

πŸš• Ride Management

  • User can request a ride
  • Driver can view all pending rides
  • Driver can accept a ride
  • User/Driver can complete a ride
  • User can view their own rides

πŸ›‘ Security

  • JWT authentication on every secured API
  • Stateless authentication
  • Custom JWT filter

🧾 Validation & Exception Handling

  • DTO based validation
  • Global exception handling
  • Meaningful API error responses

JWT Flow

Login β†’ Receive JWT Token β†’ Add Token in Header β†’ Access Protected APIs

Header Format:

Authorization: Bearer <your-token>

πŸ“Œ API Endpoints

Public APIs

Method Endpoint Description
POST /api/auth/register Register user/driver
POST /api/auth/login Login and get JWT

USER APIs

Method Endpoint Description
POST /api/v1/rides Request a ride
GET /api/v1/user/rides View own rides
POST /api/v1/rides/{id}/complete Complete ride

DRIVER APIs

Method Endpoint Description
GET /api/v1/driver/rides/requests View pending rides
POST /api/v1/driver/rides/{id}/accept Accept a ride

Sample Request Bodies

Register

{
  "username": "john",
  "password": "1234",
  "role": "ROLE_USER"
}

Login

{
  "username": "john",
  "password": "1234"
}

Create Ride

{
  "pickupLocation": "Koramangala",
  "dropLocation": "Indiranagar"
}

Sample CURL Commands

Register User

curl -X POST http://localhost:9000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"john","password":"1234","role":"ROLE_USER"}'

Register Driver

curl -X POST http://localhost:9000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"driver1","password":"abcd","role":"ROLE_DRIVER"}'

Login

curl -X POST http://localhost:9000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"john","password":"1234"}'

Create Ride

curl -X POST http://localhost:9000/api/v1/rides \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"pickupLocation":"A","dropLocation":"B"}'

πŸ“Š Database Used

  • MongoDB (Local)
  • Collections:
    • users
    • rides

▢️ How to Run the Project

  1. Install Java 17
  2. Install and start MongoDB
  3. Clone the repository
  4. Open in IntelliJ IDEA
  5. Run:
    mvn spring-boot:run
  6. Server runs at:
    http://localhost:9000
    


API Testing Screenshots

Below are the screenshots of API testing done using Postman / Curl:

πŸ” User Registration

image

User Registered Sucessfully

image

πŸ”‘ User Login

image

πŸš• Create Ride

image

The token received during login will be used in authorization for creating the ride.

image

πŸš— Driver View Pending Rides

image

Driver Accept Ride

image

🏁 Complete Ride

image

πŸ“„ User Ride History

image

Output Status

  • User Registration Working
  • JWT Login Working
  • Ride Request Working
  • Driver Accept Working
  • Ride Completion Working
  • Role Authorization Working

πŸ“„ Author

Sanskriti
Backend Developer – Spring Boot & MongoDB
GitHub: https://github.com/Sanskriti10247

About

Ride sharing backend using Spring Boot & MongoDB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages