Skip to content

Latest commit

Β 

History

114 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚌 Naija Transport β€” Route & Fare Finder

A full-stack, real-time Nigerian transport platform built with TypeScript, React, Node.js, MongoDB, and Socket.IO.

Live Demo Backend TypeScript License


πŸ“Έ Screenshots

Live at naijatransport.vercel.app


🧭 What It Does

Naija Transport helps commuters in Lagos find bus routes, estimate fares, and report real-time traffic incidents β€” all in one place.

Users can:

  • πŸ” Search routes and stops by name or location
  • πŸ—ΊοΈ View interactive maps with route polylines and stop markers
  • πŸ’° Get real-time fare estimates blended with crowdsourced reports
  • 🚨 Report and view live traffic incidents (roadblocks, police checkpoints)
  • πŸ“ Record and replay their own trips with GPS tracking
  • πŸ” Register, log in, and save favourite routes
  • πŸ† Earn points, streaks, and badges for community contributions

βš™οΈ Tech Stack

Frontend

Technology Purpose
React + Vite UI framework and build tool
TypeScript Type-safe frontend logic
Tailwind CSS Styling
Mapbox GL JS Interactive route and incident maps
Socket.IO Client Real-time incident updates
React Router Client-side routing
Axios API communication with interceptors

Backend

Technology Purpose
Node.js + Express REST API server
TypeScript Type-safe backend logic
MongoDB Atlas + Mongoose Database with geospatial indexes
Socket.IO Real-time bi-directional events
JWT + bcrypt Authentication (access + refresh tokens)
Zod Request body validation
express-rate-limit API rate limiting
Pino Structured JSON logging
Sentry Error monitoring and observability

Infrastructure & DevOps

Technology Purpose
Vercel Frontend hosting + CD
Render Backend hosting + CD
GitHub Actions CI pipelines (test, build, deploy, security audit)
Playwright End-to-end testing
Jest + Supertest Unit and integration testing
UptimeRobot Uptime monitoring

πŸ—οΈ Architecture

naija-bus/
β”œβ”€β”€ frontend/          # React + Vite + TypeScript
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/    # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ pages/         # Route-level pages
β”‚   β”‚   └── hooks/         # Custom React hooks
β”‚   └── .env.example
β”œβ”€β”€ backend/           # Node.js + Express + TypeScript
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ routes/        # API route handlers
β”‚   β”‚   β”œβ”€β”€ models/        # Mongoose schemas
β”‚   β”‚   β”œβ”€β”€ middleware/    # Auth, rate-limit, validation
β”‚   β”‚   β”œβ”€β”€ services/      # Business logic (fare engine, etc.)
β”‚   β”‚   └── socket/        # Socket.IO event handlers
β”‚   └── .env.example
β”œβ”€β”€ seed/              # Initial Lagos route dataset
β”œβ”€β”€ scripts/           # Seed and utility scripts
β”œβ”€β”€ docs/              # Validation evidence and runbooks
└── .github/workflows/ # CI/CD pipelines

πŸš€ Key Features In Depth

πŸ” Authentication

  • JWT access tokens (in-memory) + refresh tokens (httpOnly cookies)
  • Auto-refresh on 401 via Axios interceptor
  • Protected route wrapper for authenticated-only pages
  • Admin role with route/stop management panel

πŸ—ΊοΈ Geospatial Search

  • MongoDB 2dsphere indexes on routes and stops
  • GET /stops?near=lng,lat&radius=500 β€” find stops within radius
  • GET /routes?bbox= β€” filter routes within map viewport
  • Lagos bounds and zoom caps to control Mapbox tile usage

⚑ Real-Time with Socket.IO

  • Server emits report:created and fare:reported on new submissions
  • Frontend subscribes to viewport/route channels
  • Live incident markers update on the map without page refresh
  • Two-browser real-time demo validated in docs/

πŸ’° Fare Engine

  • Rule-based base fare calculation per route
  • Time-of-day and traffic multipliers
  • Blends rule-based fare with recent crowdsourced reports
  • Full fare breakdown in API response

πŸ“ Trip Recording

  • GPS watchPosition captures checkpoints every 5 seconds
  • Live polyline drawn on map during recording
  • Trip uploaded to backend on stop with distance + duration computed
  • MyTrips page replays stored checkpoint polyline on map

πŸ† Gamification

  • Points awarded for fare reports and trip uploads
  • Streak tracking for consecutive daily contributions
  • Badges unlocked at milestones
  • Leaderboard surface for community engagement

πŸ€– WhatsApp Bot

  • whatsapp-web.js listener ingests route/fare reports from WhatsApp
  • Bot-auth endpoint with token-gated ingestion
  • Allowlist-controlled sender MSISDN filtering

πŸ› οΈ Local Setup

Prerequisites

  • Node.js 18+
  • MongoDB Atlas account (or local MongoDB)
  • Mapbox account (free tier)

1. Clone the repo

git clone https://github.com/Eldren-cmd/naija-bus.git
cd naija-bus

2. Set up the backend

cd backend
cp .env.example .env
# Fill in your values in .env (see Environment Variables below)
npm install
npm run dev

3. Set up the frontend

cd frontend
cp .env.example .env
# Fill in VITE_API_BASE and VITE_MAPBOX_KEY
npm install
npm run dev

4. Seed the database (optional)

# Dry run (no DB writes)
node scripts/seed.js --dry-run

# Seed 5 Lagos corridors
node scripts/seed.js

πŸ”‘ Environment Variables

Backend (backend/.env)

PORT=5000
NODE_ENV=development
MONGO_URI=your_mongodb_atlas_connection_string
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=7d
JWT_REFRESH_SECRET=your_refresh_secret
JWT_REFRESH_EXPIRES_IN=30d
CORS_ALLOWED_ORIGINS=http://localhost:5173
SENTRY_DSN=your_sentry_dsn (optional)

Frontend (frontend/.env)

VITE_API_BASE=http://localhost:5000
VITE_MAPBOX_KEY=your_mapbox_public_token

⚠️ Never commit .env files. Use .env.example as a reference only.


πŸ§ͺ Testing

# Backend unit tests
cd backend && npm test

# Backend integration tests (Supertest)
cd backend && npm run test:integration

# End-to-end tests (Playwright)
npm run test:e2e

Coverage includes:

  • Fare engine base logic (Jest)
  • Auth login, routes list, fare estimate (Supertest)
  • Login flow, saved-route actions, report submission (Playwright)

πŸ“‘ API Highlights

Method Endpoint Auth Description
POST /auth/register ❌ Register new user
POST /auth/login ❌ Login + set refresh cookie
POST /auth/refresh ❌ Refresh access token
GET /api/v1/routes?q=&bbox= ❌ Search routes
GET /api/v1/routes/:id ❌ Route detail + stops
GET /api/v1/stops?near=lng,lat ❌ Stops near location
GET /api/v1/fare/estimate ❌ Fare estimate
POST /api/v1/fare/report βœ… Submit fare report
POST /api/v1/reports βœ… Submit traffic incident
GET /api/v1/reports?bbox= ❌ Active incidents in viewport
POST /api/v1/trips βœ… Upload recorded trip
GET /api/v1/trips βœ… User trip history
GET /api/v1/health ❌ Backend health check

🚒 Deployment

Service Platform URL
Frontend Vercel naijatransport.vercel.app
Backend Render naija-bus-backend.onrender.com
Database MongoDB Atlas β€”

CI/CD:

  • Push to main β†’ GitHub Actions runs tests + build
  • On success β†’ auto-deploys frontend to Vercel, backend to Render
  • Security audit workflow runs on every push (dependency audit + runtime smoke checks)
  • Uptime monitor pings /api/v1/health every 10 minutes

πŸ‘€ Author

Gabriel Adenrele Adegboyega Full Stack Developer

Portfolio LinkedIn GitHub Email


πŸ“„ License

MIT Β© 2025 Gabriel Adenrele Adegboyega

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages