A full-stack, real-time Nigerian transport platform built with TypeScript, React, Node.js, MongoDB, and Socket.IO.
Live at naijatransport.vercel.app
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
| 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 |
| 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 |
| 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 |
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
- 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
- MongoDB 2dsphere indexes on routes and stops
GET /stops?near=lng,lat&radius=500β find stops within radiusGET /routes?bbox=β filter routes within map viewport- Lagos bounds and zoom caps to control Mapbox tile usage
- Server emits
report:createdandfare:reportedon 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/
- 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
- GPS
watchPositioncaptures 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
- Points awarded for fare reports and trip uploads
- Streak tracking for consecutive daily contributions
- Badges unlocked at milestones
- Leaderboard surface for community engagement
whatsapp-web.jslistener ingests route/fare reports from WhatsApp- Bot-auth endpoint with token-gated ingestion
- Allowlist-controlled sender MSISDN filtering
- Node.js 18+
- MongoDB Atlas account (or local MongoDB)
- Mapbox account (free tier)
git clone https://github.com/Eldren-cmd/naija-bus.git
cd naija-buscd backend
cp .env.example .env
# Fill in your values in .env (see Environment Variables below)
npm install
npm run devcd frontend
cp .env.example .env
# Fill in VITE_API_BASE and VITE_MAPBOX_KEY
npm install
npm run dev# Dry run (no DB writes)
node scripts/seed.js --dry-run
# Seed 5 Lagos corridors
node scripts/seed.jsPORT=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)VITE_API_BASE=http://localhost:5000
VITE_MAPBOX_KEY=your_mapbox_public_token
β οΈ Never commit.envfiles. Use.env.exampleas a reference only.
# 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:e2eCoverage includes:
- Fare engine base logic (Jest)
- Auth login, routes list, fare estimate (Supertest)
- Login flow, saved-route actions, report submission (Playwright)
| 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 |
| 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/healthevery 10 minutes
Gabriel Adenrele Adegboyega Full Stack Developer
MIT Β© 2025 Gabriel Adenrele Adegboyega