# ayushdhatwalia/uber-clone architecture

> Architecture diagram of the GitHub repository ayushdhatwalia/uber-clone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ayushdhatwalia/uber-clone
- Repository: https://github.com/ayushdhatwalia/uber-clone

## Overview

#### Purpose and Entry Points
This is a full-stack ride-hailing (“Uber clone”) system with separate Java backend and React frontend. Backend startup is `Backend/src/main/java/com/uberclone/backend/UberCloneBackendApplication.java`; browser startup is `frontend/src/main.jsx`, which mounts `frontend/src/App.jsx`.

#### Client Application
The frontend is a Vite/React single-page application organized around rider and captain workflows. Route-level pages cover authentication, home/map flows, ride progress, trips, and logout for both roles:
- `frontend/src/pages/Home.jsx`
- `frontend/src/pages/Riding.jsx`
- `frontend/src/pages/CaptainHome.jsx`
- `frontend/src/pages/CaptainRiding.jsx`

Ride-state UI is decomposed into panels such as vehicle selection, driver search, ride confirmation, pickup waiting, completion, and rating:
- `frontend/src/components/VehiclePanel.jsx`
- `frontend/src/components/LookingForDriver.jsx`
- `frontend/src/components/FinishRide.jsx`

#### Client State, Access, and Realtime Boundary
Separate React contexts hold user, captain, and socket/realtime state, allowing screens and components to consume role-specific session data and socket connectivity without direct backend coupling:
- `frontend/src/context/UserContext.jsx`
- `frontend/src/context/CapatainContext.jsx`
- `frontend/src/context/SocketContext.jsx`

Protected-wrapper pages establish client-side access boundaries for authenticated rider and captain experiences:
- `frontend/src/pages/UserProtectWrapper.jsx`
- `frontend/src/pages/CaptainProtectWrapper.jsx`

#### HTTP API and Application Services
Spring controllers form the backend’s HTTP boundary for users, captains, rides, maps, and basic home endpoints:
- `Backend/src/main/java/com/uberclone/backend/controller/UserController.java`
- `Backend/src/main/java/com/uberclone/backend/controller/CaptainController.java`
- `Backend/src/main/java/com/uberclone/backend/controller/RideController.java`

Controllers receive request DTOs, delegate to services, and return responses. Core service responsibilities are separated into authentication/JWT handling, user and captain lifecycle, ride lifecycle, map operations, and socket-event coordination:
- `Backend/src/main/java/com/uberclone/backend/service/AuthService.java`
- `Backend/src/main/java/com/uberclone/backend/service/RideService.java`
- `Backend/src/main/java/com/uberclone/backend/service/SocketIoService.java`

#### Ride, Identity, and Persistence Domain
Persistent domain entities model riders, captains, vehicles, rides, identity names, locations, and invalidated tokens:
- `Backend/src/main/java/com/uberclone/backend/model/User.java`
- `Backend/src/main/java/com/uberclone/backend/model/Captain.java`
- `Backend/src/main/java/com/uberclone/backend/model/Ride.java`

Repository interfaces provide the persistence boundary for the central aggregates and token blacklist:
- `Backend/src/main/java/com/uberclone/backend/repository/UserRepository.java`
- `Backend/src/main/java/com/uberclone/backend/repository/CaptainRepository.java`
- `Backend/src/main/java/com/uberclone/backend/repository/RideRepository.java`

Authentication includes JWT issuance/validation and a blacklist cleanup concern, supporting logout or token revocation:
- `Backend/src/main/java/com/uberclone/backend/service/JwtService.java`
- `Backend/src/main/java/com/uberclone/backend/service/BlacklistTokenCleanupService.java`

#### Location Matching and Infrastructure
Captain location updates flow through an application-layer port/service boundary, decoupling ride matching from geospatial and database implementations:
- `Backend/src/main/java/com/uberclone/backend/application/service/CaptainLocationService.java`
- `Backend/src/main/java/com/uberclone/backend/application/port/GeoIndexPort.java`
- `Backend/src/main/java/com/uberclone/backend/application/port/CaptainLocationIndexPort.java`

The concrete geo implementation uses H3 indexing, while captain-location indexing is backed by PostgreSQL:
- `Backend/src/main/java/com/uberclone/backend/infrastructure/geo/H3GeoIndexAdapter.java`
- `Backend/src/main/java/com/uberclone/backend/infrastructure/persistence/PostgresCaptainLocationIndexAdapter.java`

#### Runtime and Operational Boundaries
The backend is a Maven/Spring Boot application configured through `Backend/pom.xml` and `Backend/src/main/resources/application.properties`. PostgreSQL-oriented local infrastructure is represented by `Backend/docker-compose.yml`. The system also has a Socket.IO service boundary for bidirectional ride/location events and a CORS configuration boundary for frontend-to-backend browser access:
- `Backend/src/main/java/com/uberclone/backend/config/CorsConfig.java`
- `Backend/src/main/java/com/uberclone/backend/service/SocketIoService.java`

Main entry points: [`frontend/src/context/SocketContext.jsx`](https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/context/SocketContext.jsx) (Session & socket contexts), [`Backend/src/main/java/com/uberclone/backend/controller/RideController.java`](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/controller/RideController.java) (HTTP controllers), [`Backend/src/main/java/com/uberclone/backend/service/RideService.java`](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/service/RideService.java) (Ride lifecycle), [`Backend/src/main/java/com/uberclone/backend/service/SocketIoService.java`](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/service/SocketIoService.java) (Socket.IO events)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React client"]
  node_browser["Browser app<br/>Vite entry<br/>[main.jsx]"]
  node_react_app["App routes<br/>React app<br/>[App.jsx]"]
  node_rider_ui["Rider ride UI<br/>React pages<br/>[Home.jsx]"]
  node_captain_ui["Captain ride UI<br/>React pages<br/>[CaptainHome.jsx]"]
  node_client_contexts["Session &amp; socket contexts<br/>React contexts<br/>[SocketContext.jsx]"]
  node_access_wrappers["Protected routes<br/>Auth wrappers"]
end

subgraph group_backend["Spring backend"]
  node_backend_app["Spring Boot app<br/>Java entry"]
  node_http_controllers["HTTP controllers<br/>Spring REST"]
  node_auth_services["Auth &amp; JWT<br/>Application services<br/>[AuthService.java]"]
  node_ride_service["Ride lifecycle<br/>Application service<br/>[RideService.java]"]
  node_socket_service["Socket.IO events<br/>Realtime service"]
end

subgraph group_location["Location matching"]
  node_captain_location["Captain location service<br/>Application service"]
  node_geo_port["Geo index port<br/>Application port<br/>[GeoIndexPort.java]"]
  node_h3_adapter["H3 geo adapter"]
  node_location_index["Captain location index<br/>Persistence adapter"]
end

subgraph group_data["Persistence"]
  node_domain["Ride domain<br/>JPA entities<br/>[Ride.java]"]
  node_repositories["Domain repositories<br/>Spring Data"]
  node_postgres[("PostgreSQL<br/>Database<br/>[docker-compose.yml]")]
end

node_browser -->|"mounts"| node_react_app
node_react_app -->|"guards routes"| node_access_wrappers
node_access_wrappers -->|"authorizes"| node_rider_ui
node_access_wrappers -->|"authorizes"| node_captain_ui
node_rider_ui -->|"uses"| node_client_contexts
node_captain_ui -->|"uses"| node_client_contexts
node_client_contexts -->|"HTTP API"| node_http_controllers
node_client_contexts -->|"realtime events"| node_socket_service
node_backend_app -->|"hosts"| node_http_controllers
node_backend_app -->|"hosts"| node_socket_service
node_http_controllers -->|"auth requests"| node_auth_services
node_http_controllers -->|"ride requests"| node_ride_service
node_ride_service -->|"finds captains"| node_captain_location
node_ride_service -->|"persists rides"| node_repositories
node_auth_services -->|"accounts and tokens"| node_repositories
node_socket_service -->|"location updates"| node_captain_location
node_socket_service -->|"ride events"| node_ride_service
node_captain_location -->|"spatial lookup"| node_geo_port
node_geo_port -->|"implemented by"| node_h3_adapter
node_captain_location -->|"indexes locations"| node_location_index
node_repositories -->|"maps aggregates"| node_domain
node_repositories -->|"stores"| node_postgres
node_location_index -->|"stores index"| node_postgres

click node_browser "https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/main.jsx"
click node_react_app "https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/App.jsx"
click node_rider_ui "https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/pages/Home.jsx"
click node_captain_ui "https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/pages/CaptainHome.jsx"
click node_client_contexts "https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/context/SocketContext.jsx"
click node_access_wrappers "https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/pages/UserProtectWrapper.jsx"
click node_backend_app "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/UberCloneBackendApplication.java"
click node_http_controllers "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/controller/RideController.java"
click node_auth_services "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/service/AuthService.java"
click node_ride_service "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/service/RideService.java"
click node_socket_service "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/service/SocketIoService.java"
click node_captain_location "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/application/service/CaptainLocationService.java"
click node_geo_port "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/application/port/GeoIndexPort.java"
click node_h3_adapter "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/infrastructure/geo/H3GeoIndexAdapter.java"
click node_location_index "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/infrastructure/persistence/PostgresCaptainLocationIndexAdapter.java"
click node_domain "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/model/Ride.java"
click node_repositories "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/repository/RideRepository.java"
click node_postgres "https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_react_app,node_rider_ui,node_captain_ui,node_client_contexts,node_access_wrappers toneBlue
class node_backend_app,node_http_controllers,node_auth_services,node_ride_service,node_socket_service toneAmber
class node_captain_location,node_geo_port,node_h3_adapter,node_location_index toneMint
class node_domain,node_repositories,node_postgres toneRose
```

## Components

### React client

- [Browser app](https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/main.jsx): Vite entry · Mounts the React single-page application. · `frontend/src/main.jsx`
- [App routes](https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/App.jsx): React app · Rider and captain route composition. · `frontend/src/App.jsx`
- [Rider ride UI](https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/pages/Home.jsx): React pages · Home, ride progress, vehicle selection, driver search, and completion. · `frontend/src/pages/Home.jsx`
- [Captain ride UI](https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/pages/CaptainHome.jsx): React pages · Captain home and active-ride workflows. · `frontend/src/pages/CaptainHome.jsx`
- [Session & socket contexts](https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/context/SocketContext.jsx): React contexts · Role-specific sessions and Socket.IO connectivity. · `frontend/src/context/SocketContext.jsx`
- [Protected routes](https://github.com/ayushdhatwalia/uber-clone/blob/main/frontend/src/pages/UserProtectWrapper.jsx): Auth wrappers · Client-side rider and captain access boundaries. · `frontend/src/pages/UserProtectWrapper.jsx`

### Spring backend

- [Spring Boot app](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/UberCloneBackendApplication.java): Java entry · Starts the backend runtime. · `Backend/src/main/java/com/uberclone/backend/UberCloneBackendApplication.java`
- [HTTP controllers](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/controller/RideController.java): Spring REST · User, captain, and ride API boundary. · `Backend/src/main/java/com/uberclone/backend/controller/RideController.java`
- [Auth & JWT](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/service/AuthService.java): Application services · Authentication, token validation, revocation, and cleanup. · `Backend/src/main/java/com/uberclone/backend/service/AuthService.java`
- [Ride lifecycle](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/service/RideService.java): Application service · Coordinates ride creation, matching, and lifecycle changes. · `Backend/src/main/java/com/uberclone/backend/service/RideService.java`
- [Socket.IO events](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/service/SocketIoService.java): Realtime service · Bidirectional ride and location event boundary. · `Backend/src/main/java/com/uberclone/backend/service/SocketIoService.java`

### Location matching

- [Captain location service](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/application/service/CaptainLocationService.java): Application service · Updates and queries captain locations for matching. · `Backend/src/main/java/com/uberclone/backend/application/service/CaptainLocationService.java`
- [Geo index port](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/application/port/GeoIndexPort.java): Application port · Decouples matching from geospatial indexing. · `Backend/src/main/java/com/uberclone/backend/application/port/GeoIndexPort.java`
- [H3 geo adapter](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/infrastructure/geo/H3GeoIndexAdapter.java): Geo adapter · Concrete H3 spatial index implementation. · `Backend/src/main/java/com/uberclone/backend/infrastructure/geo/H3GeoIndexAdapter.java`
- [Captain location index](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/infrastructure/persistence/PostgresCaptainLocationIndexAdapter.java): Persistence adapter · PostgreSQL-backed captain location indexing. · `Backend/src/main/java/com/uberclone/backend/infrastructure/persistence/PostgresCaptainLocationIndexAdapter.java`

### Persistence

- [Ride domain](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/model/Ride.java): JPA entities · Users, captains, vehicles, rides, locations, and invalidated tokens. · `Backend/src/main/java/com/uberclone/backend/model/Ride.java`
- [Domain repositories](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/src/main/java/com/uberclone/backend/repository/RideRepository.java): Spring Data · Persistence boundary for riders, captains, rides, and blacklisted tokens. · `Backend/src/main/java/com/uberclone/backend/repository/RideRepository.java`
- [PostgreSQL](https://github.com/ayushdhatwalia/uber-clone/blob/main/Backend/docker-compose.yml): Database · Local operational datastore. · `Backend/docker-compose.yml`

## Connections

- Browser app → App routes: mounts
- App routes → Protected routes: guards routes
- Protected routes → Rider ride UI: authorizes
- Protected routes → Captain ride UI: authorizes
- Rider ride UI → Session & socket contexts: uses
- Captain ride UI → Session & socket contexts: uses
- Session & socket contexts → HTTP controllers: HTTP API
- Session & socket contexts → Socket.IO events: realtime events
- Spring Boot app → HTTP controllers: hosts
- Spring Boot app → Socket.IO events: hosts
- HTTP controllers → Auth & JWT: auth requests
- HTTP controllers → Ride lifecycle: ride requests
- Ride lifecycle → Captain location service: finds captains
- Ride lifecycle → Domain repositories: persists rides
- Auth & JWT → Domain repositories: accounts and tokens
- Socket.IO events → Captain location service: location updates
- Socket.IO events → Ride lifecycle: ride events
- Captain location service → Geo index port: spatial lookup
- Geo index port → H3 geo adapter: implemented by
- Captain location service → Captain location index: indexes locations
- Domain repositories → Ride domain: maps aggregates
- Domain repositories → PostgreSQL: stores
- Captain location index → PostgreSQL: stores index
