A modern ride-sharing/carpooling backend system built with Hono.js and deployed on Cloudflare Workers. Designed specifically for Thapar University students to share transportation.
- Google OAuth Authentication - Secure login restricted to @thapar.edu domain
- JWT-based Authorization - Access tokens (1h) and refresh tokens (7d)
- Pool Management - Create, join, and manage transport pools
- Female-only Pools - Gender-restricted pools for safety
- Advanced Filtering - Search by location, time, transport mode
- Real-time Capacity - Automatic capacity tracking
- Type-safe - Full TypeScript implementation with Drizzle ORM
- Runtime: Cloudflare Workers
- Framework: Hono.js (Ultra-fast web framework)
- Database: Cloudflare D1 (SQLite)
- ORM: Drizzle ORM
- Authentication: Google OAuth 2.0 + JWT
- Language: TypeScript
- Node.js 18+ installed
- Cloudflare account (free tier works)
- Google Cloud Console account (for OAuth credentials)
- Wrangler CLI installed globally
npm install -g wranglergit clone <repository-url>
cd transport-pool-backend
npm install# Login to Cloudflare
wrangler login
# Copy environment template
cp .dev.vars.example .dev.varsEdit .dev.vars:
JWT_SECRET=your-super-secret-jwt-key-min-32-chars
JWT_REFRESH_SECRET=your-refresh-token-secret
GOOGLE_CLIENT_ID=your-google-oauth-client-id
GOOGLE_CLIENT_SECRET=your-google-oauth-client-secret
FRONTEND_URL=http://localhost:3000
ALLOWED_DOMAIN=thapar.edu# Create D1 database
wrangler d1 create transport-pool-db
# Update wrangler.toml with database_id from above command
# Run migrations
npm run db:migratenpm run devServer runs at: http://localhost:8787
npm run dev # Start development server
npm run deploy # Deploy to Cloudflare Workers
npm run db:generate # Generate database migrations
npm run db:migrate # Apply migrations to D1
npm run db:studio # Open Drizzle Studio (local)
npm run test # Run tests
npm run lint # Lint code
npm run typecheck # Type checking- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials:
- Application type: Web application
- Authorized redirect URIs:
http://localhost:8787/auth/google/callback(dev)https://your-worker.workers.dev/auth/google/callback(prod)
- Copy Client ID and Client Secret to
.dev.vars
POST /auth/google- Initiate Google OAuthGET /auth/google/callback- OAuth callbackPOST /auth/refresh- Refresh access tokenPOST /auth/logout- Logout user
GET /user/profile- Get current user profilePUT /user/profile- Update user profilePOST /user/phone- Update phone numberPOST /user/gender- Update gender
GET /pools- List all pools (with filters)POST /pools- Create new poolGET /pools/:id- Get pool detailsPUT /pools/:id- Update pool (creator only)DELETE /pools/:id- Delete pool (creator only)POST /pools/:id/join- Join a poolPOST /pools/:id/leave- Leave a pool
start_point- Filter by starting locationend_point- Filter by destinationtransport_mode- Filter by transport typeis_female_only- Filter female-only poolsdeparture_date- Filter by date (YYYY-MM-DD)search- Search in locationsordering- Sort by field (departure_time, -created_at)
id- UUID primary keyemail- Unique, @thapar.edu onlyfull_name- User's full namephone_number- Optional contactgender- male/female/othergoogle_authenticated- Boolean flagcreated_at/updated_at- Timestamps
id- UUID primary keystart_point- Starting locationend_point- Destinationdeparture_time- DateTimetransport_mode- train/bus/car/bike/othertotal_persons- Maximum capacitycurrent_persons- Current occupancyis_female_only- Boolean flagcreated_by_id- Foreign key to userscreated_at/updated_at- Timestamps
id- UUID primary keypool_id- Foreign key to poolsuser_id- Foreign key to usersis_creator- Boolean flagjoined_at- Timestamp
- Domain-restricted Google OAuth (@thapar.edu)
- JWT tokens with expiration
- Refresh token rotation
- CORS protection
- Rate limiting (via Cloudflare)
- SQL injection prevention (Drizzle ORM)
- XSS protection (input sanitization)
# Deploy to Cloudflare Workers
npm run deploy
# Set production secrets
wrangler secret put JWT_SECRET
wrangler secret put JWT_REFRESH_SECRET
wrangler secret put GOOGLE_CLIENT_ID
wrangler secret put GOOGLE_CLIENT_SECRETSet via Cloudflare Dashboard or Wrangler:
JWT_SECRET- Production JWT secretJWT_REFRESH_SECRET- Refresh token secretGOOGLE_CLIENT_ID- Google OAuth client IDGOOGLE_CLIENT_SECRET- Google OAuth secretFRONTEND_URL- Your frontend URLALLOWED_DOMAIN- thapar.edu
Monitor your worker at:
- Cloudflare Dashboard > Workers > Analytics
- Real-time logs:
wrangler tail - Metrics: Requests, errors, CPU time
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coverage{
"success": true,
"data": { ... },
"message": "Operation successful"
}{
"success": false,
"error": "Error message",
"code": "ERROR_CODE"
}- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
MIT License - see LICENSE file for details
- Your Name - Initial work
- Hono.js team for the amazing framework
- Cloudflare for Workers platform
- Drizzle team for the ORM
For issues and questions:
- Open an issue on GitHub
- Email: support@example.com
- Email notifications
- Push notifications
- Rating system
- Chat functionality
- Route optimization
- Payment integration
- Admin dashboard
Made with β€οΈ for Thapar University students