Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ride Sharing Application

A clean, well-maintained ride-sharing platform built with Spring Boot and MongoDB that connects users who need rides with available drivers. This refactored version features improved code quality, comprehensive documentation, and type-safe ride status management.

Features

For Users

  • Create ride requests with pickup and drop locations
  • View all your ride history
  • Mark rides as completed

For Drivers

  • View all pending ride requests
  • Accept available rides
  • Complete rides after drop-off

Security

  • JWT-based authentication
  • Role-based access control (USER/DRIVER)
  • Secure password encryption using BCrypt

Tech Stack

  • Backend: Spring Boot
  • Database: MongoDB
  • Security: Spring Security with JWT
  • Build Tool: Maven/Gradle

Recent Improvements

This codebase has been refactored for improved quality:

  • New Package Structure: com.rideshare.app (cleaner, more generic)
  • Type-Safe Enums: RideStatus enum replaces string-based status values
  • Comprehensive Documentation: JavaDoc comments on all classes and methods
  • Cleaner Code: Extracted validation logic into private helper methods
  • Better Naming: Clear, descriptive variable and method names
  • Consistent Formatting: Professional code style throughout
  • 100% Backward Compatible: All APIs remain unchanged

See REFACTORING_SUMMARY.md and REFACTORING_CHECKLIST.md for detailed changes.

API Endpoints

Authentication

  • POST /api/auth/register - Register new user/driver
  • POST /api/auth/login - Login and get JWT token

User Endpoints

  • POST /api/v1/rides - Create a new ride request
  • GET /api/v1/user/rides - Get all your rides
  • PUT /api/v1/rides/{rideId}/complete - Complete a ride

Driver Endpoints

  • GET /api/v1/driver/rides/requests - View pending ride requests
  • PUT /api/v1/driver/rides/{rideId}/accept - Accept a ride

Getting Started

Prerequisites

  • Java 17 or higher
  • MongoDB installed and running
  • Maven or Gradle

Configuration

Create an application.properties file in src/main/resources/:

# MongoDB Configuration
spring.data.mongodb.uri=mongodb://localhost:27017/rideshare
spring.data.mongodb.database=rideshare

# JWT Configuration
jwt.secret=your-secret-key-here
jwt.expiration-ms=86400000

Running the Application

# Using Maven
mvn spring-boot:run

# Using Gradle
gradle bootRun

The application will start on http://localhost:8080

Usage Example

1. Register a User

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

2. Login

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

3. Create a Ride (with token)

curl -X POST http://localhost:8080/api/v1/rides \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{
    "pickupLocation": "123 Main St",
    "dropLocation": "456 Park Ave"
  }'

Project Structure

rideshare-app/
├── config/           # Security and JWT configuration
├── controller/       # REST API endpoints
├── dto/              # Data transfer objects
├── model/            # Entity models (includes RideStatus enum)
├── repository/       # MongoDB repositories
├── service/          # Business logic
└── util/             # Utility classes

Ride States

The application uses a type-safe RideStatus enum with the following states:

  • REQUESTED - User created a ride request, waiting for driver acceptance
  • ACCEPTED - Driver has accepted the ride and is en route
  • COMPLETED - Ride has been successfully completed

Code Quality

This refactored version includes:

  • Comprehensive JavaDoc: Every class and public method is documented
  • Private Helper Methods: Complex logic broken into focused methods
  • Meaningful Names: Self-documenting code with clear variable names
  • Consistent Formatting: Professional code style and indentation
  • Better Exception Handling: Contextual error messages for debugging
  • Type Safety: Enum-based status management instead of magic strings

For details, see REFACTORING_SUMMARY.md.

License

This project is open source and available for educational and commercial purposes.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages