A mini Ride Sharing backend built with Spring Boot, MongoDB, and JWT Authentication.
- Spring Boot 3.2.0
- MongoDB
- JWT Authentication
- BCrypt Password Encoding
- Jakarta Validation
src/
├── main/
│ ├── java/
│ │ └── org/example/rideshare/
│ │ ├── model/
│ │ ├── repository/
│ │ ├── service/
│ │ ├── controller/
│ │ ├── config/
│ │ ├── dto/
│ │ ├── exception/
│ │ └── util/
│ └── resources/
│ └── application.properties
- id : String
- username : String
- password : String (BCrypt encoded)
- role : String (ROLE_USER / ROLE_DRIVER)
- id : String
- userId : String (Passenger FK)
- driverId : String (Driver FK)
- pickupLocation : String
- dropLocation : String
- status : String (REQUESTED / ACCEPTED / COMPLETED)
- createdAt : Date
POST /api/auth/register
Content-Type: application/json
{
"username": "john",
"password": "1234",
"role": "ROLE_USER"
}
POST /api/auth/login
Content-Type: application/json
{
"username": "john",
"password": "1234"
}
Response:
{
"token": "eyJhbGc...",
"username": "john",
"role": "ROLE_USER"
}
POST /api/v1/rides
Authorization: Bearer <token>
Content-Type: application/json
{
"pickupLocation": "Koramangala",
"dropLocation": "Indiranagar"
}
GET /api/v1/user/rides
Authorization: Bearer <token>
GET /api/v1/driver/rides/requests
Authorization: Bearer <token>
POST /api/v1/driver/rides/{rideId}/accept
Authorization: Bearer <token>
POST /api/v1/rides/{rideId}/complete
Authorization: Bearer <token>
- Install MongoDB and start the service:
mongod- Build the project:
mvn clean install- Run the application:
mvn spring-boot:runThe application will start on http://localhost:8081
curl -X POST http://localhost:8081/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"john","password":"1234","role":"ROLE_USER"}'curl -X POST http://localhost:8081/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"driver1","password":"abcd","role":"ROLE_DRIVER"}'curl -X POST http://localhost:8081/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"john","password":"1234"}'curl -X POST http://localhost:8081/api/v1/rides \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"pickupLocation":"A","dropLocation":"B"}'curl -X GET http://localhost:8081/api/v1/driver/rides/requests \
-H "Authorization: Bearer <token>"curl -X POST http://localhost:8081/api/v1/driver/rides/{rideId}/accept \
-H "Authorization: Bearer <token>"curl -X POST http://localhost:8081/api/v1/rides/{rideId}/complete \
-H "Authorization: Bearer <token>"curl -X GET http://localhost:8081/api/v1/user/rides \
-H "Authorization: Bearer <token>"- ✅ User Registration with BCrypt password encoding
- ✅ JWT-based Authentication
- ✅ Role-based Authorization (ROLE_USER, ROLE_DRIVER)
- ✅ Request a Ride (Passenger)
- ✅ View Pending Ride Requests (Driver)
- ✅ Accept Ride (Driver)
- ✅ Complete Ride
- ✅ User Gets Their Own Rides
- ✅ Input Validation with Jakarta Validation
- ✅ Global Exception Handling
- ✅ Clean Architecture (Controller → Service → Repository)
Built with 💚 by Prince Shakya