Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ride Sharing API

A ride-sharing backend built with Spring Boot 3 and Java 21 — stateless JWT authentication, versioned REST controllers, MongoDB persistence and centralised error handling.

What it does

A rider registers, logs in and requests a ride. A driver accepts it and marks it complete. Every state change goes through a service layer that validates the transition, and every failure comes back as a structured ApiError rather than a stack trace.

API

Method Endpoint Purpose
POST /api/auth/register Create an account
POST /api/auth/login Exchange credentials for a JWT
POST /api/v1/rides Request a ride
POST /api/v1/rides/{rideId}/accept Driver accepts a pending ride
POST /api/v1/rides/{rideId}/complete Mark a ride complete
GET /api/v1/user/rides The caller's ride history
GET /api/v1/driver/rides/requests Open ride requests, drivers only

All /api/v1/** routes need an Authorization: Bearer <token> header, and access is role-scoped: /api/v1/rides/** is open to USER and DRIVER, while /api/v1/driver/** requires DRIVER. Only /api/auth/** is public.

Design

  • JwtFilter + SecurityConfig — a once-per-request filter validates the token and populates the security context; the app holds no session state, and authority checks are declared per route rather than scattered through handlers.
  • Versioned controllers (controller/v1) — the URL carries the version so a v2 can land beside v1 without breaking existing clients.
  • GlobalExceptionHandler@RestControllerAdvice maps NotFoundException and BadRequestException onto consistent JSON bodies.
  • DTOs at the boundaryCreateRideDTO keeps request shapes separate from the persisted Ride and User documents.

Stack

Java 21 · Spring Boot · Spring Security · MongoDB · jjwt · Maven

Run it

# MongoDB must be reachable (default: mongodb://localhost:27017)
./mvnw spring-boot:run

The API starts on http://localhost:8080.

Configure the datastore and signing key through the usual Spring properties — spring.data.mongodb.uri and the JWT secret used by JwtUtil.

Layout

src/main/java/com/kunal/rideSharingApp/
├── config/      JwtFilter, SecurityConfig
├── controller/  AuthController + v1/{Ride,User,Driver}
├── dto/         request shapes
├── exception/   ApiError, GlobalExceptionHandler, typed exceptions
├── model/       Ride, User
├── repository/  Mongo repositories
├── service/     RideService, UserService
└── util/        JwtUtil

About

A ride-sharing REST API in Spring Boot — JWT authentication, versioned controllers, MongoDB repositories and centralised exception handling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages