MD

Poolerz

Full-stack carpool coordination platform using DBSCAN clustering for automatic carpool matching

Next.js
TypeScript
React
MongoDB
Google OAuth
DBSCAN
Google OAuth
Real-time updates
Vercel

Problem

College students organizing carpools for events face coordination challenges: manually matching people by location, managing group chats, tracking who's driving, and ensuring balanced car capacity.

Existing solutions (group chats, spreadsheets) require significant manual effort and don't scale as events grow. There's no automated way to cluster people by geographic proximity.

Constraints

  • Must authenticate users securely (university email verification)
  • Carpool matching must happen automatically without manual intervention
  • Real-time roster updates as people join/leave carpools
  • Mobile-responsive (most users access from phones)
  • Zero-cost deployment (student project budget constraints)

Solution

Built a full-stack web application with Google OAuth, MongoDB storage, and DBSCAN clustering for automatic carpool matching by geographic proximity.

Architecture

Next.js Frontend
↓ Google OAuth
Auth & Session Management
↓ API Routes
MongoDB (Users, Events, Carpools)
↓ DBSCAN Algorithm
Carpool Clusters by Location

Technical Highlights

1. DBSCAN Clustering for Carpool Matching

Implemented DBSCAN (Density-Based Spatial Clustering) to automatically group people by geographic proximity. Unlike k-means, DBSCAN doesn't require knowing the number of carpools in advance.

import { DBSCAN } from 'density-clustering'

function createCarpools(users: User[], maxDistance: number) {
  // Extract coordinates: [latitude, longitude]
  const coordinates = users.map(u => [u.location.lat, u.location.lng])

  // DBSCAN: eps = max distance (km), minPts = 2
  const dbscan = new DBSCAN()
  const clusters = dbscan.run(coordinates, maxDistance, 2)

  // Map clusters to carpools
  return clusters.map(clusterIndices => ({
    members: clusterIndices.map(i => users[i]),
    centroid: calculateCentroid(clusterIndices, coordinates)
  }))
}

2. Google OAuth Authentication

Integrated Google OAuth to verify university email addresses and prevent spam. Used NextAuth.js for session management.

// pages/api/auth/[...nextauth].ts
import NextAuth from 'next-auth'
import GoogleProvider from 'next-auth/providers/google'

export default NextAuth({
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    })
  ],
  callbacks: {
    async signIn({ profile }) {
      // Only allow university emails
      return profile.email?.endsWith('@gatech.edu') ?? false
    }
  }
})

3. Real-Time Roster Updates

Implemented SWR (stale-while-revalidate) for optimistic UI updates. When a user joins/leaves a carpool, the UI updates immediately while revalidating in the background.

import useSWR from 'swr'

function CarpoolRoster({ carpoolId }: { carpoolId: string }) {
  const { data, mutate } = useSWR(`/api/carpools/${carpoolId}`)

  const joinCarpool = async () => {
    // Optimistic update
    mutate({ ...data, members: [...data.members, currentUser] }, false)

    // Actual API call
    await fetch(`/api/carpools/${carpoolId}/join`, { method: 'POST' })

    // Revalidate
    mutate()
  }

  return <div>{/* Roster UI */}</div>
}

4. Multi-Step Registration Flow

Built a clean onboarding flow with form validation, location input (geocoding via Google Maps API), and availability selection.

5. Vercel Serverless Deployment

Deployed on Vercel with serverless functions for API routes and MongoDB Atlas for data storage. Zero-cost deployment for student project.

Results

  • Automated carpool matching using DBSCAN geographic clustering
  • Secure Google OAuth authentication with university email verification
  • Real-time roster updates with optimistic UI
  • Mobile-responsive design for on-the-go coordination
  • Deployed on Vercel with zero hosting costs

What I'd Do Next

  • Add in-app messaging for carpool coordination
  • Implement push notifications for ride reminders
  • Support recurring events (weekly carpools)
  • Add route optimization (Google Maps Directions API)
  • Build analytics dashboard for organizers (attendance, carpool efficiency)