Real-time school bus location tracking platform built as a modern TypeScript monorepo with React, Express, and Firebase integration. Track buses, reduce wait times, and improve school transportation coordination.

School Bus Tracker is a real-time location tracking solution that solves a critical problem in school transportation: communication gaps between school administration, parents, and students regarding bus arrival times.
- Students and parents experience uncertainty about exact bus arrival times
- Long, unproductive wait times at bus stops
- Safety concerns due to unpredictable schedules
- Limited visibility for school administrators
A transparent, real-time dashboard powered by Firebase Realtime Database and modern web technologies, featuring:
- Live GPS tracking of multiple school buses
- Distance calculations using Haversine formula
- Arrival alerts when bus is within 1km
- Cross-platform support (Web, iOS, Android via Expo)
- Minimalist, low-data UI for areas with limited connectivity
- Live location updates powered by Firebase Realtime Database
- Animated bus markers on interactive maps
- Support for up to 8 buses (Bus_01 through Bus_08)
- Sub-second location refresh with Realtime Database listeners
- React Native with Expo for web, iOS, and Android
- Native maps using
react-native-maps - Web fallback for browser-based tracking
- Responsive, touch-optimized interface
- BUS IS ARRIVING alert when bus is within 1km radius
- Full-screen alert overlay with audio cues
- Distance and ETA calculations in real-time
- Haversine formula for accurate geodesic distance
- Dropdown selector to track specific buses
- Quick-switch between bus routes
- Dashboard showing live metrics:
- Current distance to bus
- Estimated arrival time (ETA)
- Bus location (lat/lng)
- Development testing without real GPS data
- Animated bus movement toward user location
- Perfect for demos and testing notification logic
- Express 5 REST API with type-safe handlers
- PostgreSQL database with Drizzle ORM
- Zod schema validation (auto-generated from OpenAPI spec)
- React Query hooks for seamless client integration
- CORS-enabled for web clients
- Tailwind CSS for responsive styling
- Navy blue + Amber accent color scheme
- Framer Motion for smooth animations
- Lucide React icons for consistent design
This is a pnpm monorepo with TypeScript project references, designed for scalability and maintainability.
School-Bus-Tracker/
โโโ artifacts/ # Deployable applications
โ โโโ api-server/ # Express REST API + PostgreSQL
โ โโโ bus-tracker/ # React Native (Expo) mobile app
โ โโโ mockup-sandbox/ # UI/UX prototyping
โ
โโโ lib/ # Shared libraries
โ โโโ api-spec/ # OpenAPI spec + Orval code generation
โ โโโ api-client-react/ # Generated React Query hooks (from OpenAPI)
โ โโโ api-zod/ # Generated Zod schemas (from OpenAPI)
โ โโโ db/ # Drizzle ORM schemas + DB connection pool
โ
โโโ scripts/ # Utility TypeScript scripts
โ
โโโ tsconfig.base.json # Shared TypeScript configuration
โโโ pnpm-workspace.yaml # Monorepo workspace definition + security config
โโโ package.json # Root workspace with shared devDeps
- Unified TypeScript: Single
tsconfig.base.jsonfor consistent types - Shared dependencies: Catalog system prevents version conflicts
- Code generation: OpenAPI โ Zod schemas + React Query hooks
- Fast builds: Composite TypeScript projects for incremental compilation
- Security-first: Minimum 1-day release age for npm packages (supply-chain attack defense)
| Layer | Technology |
|---|---|
| Mobile/Web UI | React Native (Expo), React, TypeScript |
| Styling | Tailwind CSS, Framer Motion |
| Maps | Google Maps SDK, react-native-maps |
| Backend | Express 5, Node.js 24 |
| Database | PostgreSQL, Drizzle ORM |
| Validation | Zod (from OpenAPI spec via Orval) |
| Data Layer | Firebase Realtime Database |
| Build Tools | esbuild, Vite |
| Package Manager | pnpm workspaces |
| Type System | TypeScript 5.9 with project references |
| Code Gen | Orval (OpenAPI โ TypeScript) |
- Node.js 24+ (managed by pnpm)
- pnpm 9+ (install via
npm install -g pnpm) - Firebase Project (for Realtime Database credentials)
- Google Maps API Key (for map rendering)
- PostgreSQL 15+ (for backend database)
git clone https://github.com/boikzdev/School-Bus-Tracker.git
cd School-Bus-Tracker
# Install all workspace dependencies
pnpm installCreate or update artifacts/bus-tracker/config/firebase.ts:
export const firebaseConfig = {
apiKey: "YOUR_FIREBASE_API_KEY",
authDomain: "your-project.firebaseapp.com",
databaseURL: "https://your-project.firebaseio.com",
projectId: "your-project-id",
storageBucket: "your-project.appspot.com",
messagingSenderId: "YOUR_SENDER_ID",
appId: "1:YOUR_APP_ID:web:YOUR_WEB_ID",
};Or set environment variables (Replit/Docker-friendly):
export EXPO_PUBLIC_FIREBASE_API_KEY="..."
export EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN="..."
export EXPO_PUBLIC_FIREBASE_DATABASE_URL="..."
export EXPO_PUBLIC_FIREBASE_PROJECT_ID="..."
export EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET="..."
export EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID="..."
export EXPO_PUBLIC_FIREBASE_APP_ID="..."Create .env in artifacts/api-server/:
DATABASE_URL="postgresql://user:password@localhost:5432/school_bus_tracker"
NODE_ENV="development"pnpm run build # TypeCheck + build all packages
pnpm run typecheck # TypeCheck onlyMobile App (Expo):
cd artifacts/bus-tracker
pnpm run dev
# Opens Expo dev server at http://localhost:8081
# Scan QR code with Expo Go app on mobileBackend API:
cd artifacts/api-server
pnpm run dev
# API runs on http://localhost:3000Your Realtime Database should have this structure:
{
"buses": {
"Bus_01": {
"lat": 3.1390,
"lng": 101.6869,
"route": "Route A",
"lastUpdated": 1712500000000
},
"Bus_02": {
"lat": 3.1500,
"lng": 101.7000
},
...
"Bus_08": {
"lat": 3.1600,
"lng": 101.7200
}
}
}- Bus selector dropdown to choose which bus to follow
- Google Map showing:
- Current user location (blue marker)
- Selected bus location (animated bus marker)
- Route line between user and bus
- Distance dashboard showing:
- Current distance (calculated via Haversine formula)
- Estimated arrival time (distance / avg speed)
- Bus coordinates
- Firebase Realtime Database listeners for all buses
- Automatic distance calculations
- Simulation mode for testing
- State includes:
- All buses with live locations
- Selected bus ID
- User location (geolocation API)
- Distance & ETA calculations
MapWrapper.tsxโ Native map component (iOS/Android)MapWrapper.web.tsxโ Web map fallback (no native maps on web)ArrivingAlert.tsxโ Full-screen alert when bus within 1kmBusSelector.tsxโ Bottom sheet for bus selectionDashboardCard.tsxโ Metrics cards for distance/ETA
- Primary: Navy Blue (
#001F3F) - Accent: Amber (
#FFC107) - Background: Clean white with subtle gradients
GET /api/buses # List all buses
POST /api/buses # Create new bus
GET /api/buses/:id # Get bus details
PUT /api/buses/:id # Update bus location
DELETE /api/buses/:id # Remove bus
GET /api/buses/:id/location # Get current location
GET /api/buses/:id/distance # Calculate distance from point
GET /api/routes # List all routes
POST /api/routes # Create new route
GET /api/routes/:id # Get route details
PUT /api/routes/:id # Update route
DELETE /api/routes/:id # Remove route
Full API documentation available in lib/api-spec/ (OpenAPI 3.0 spec)
Located in lib/db/:
// Buses table
export const buses = pgTable('buses', {
id: serial('id').primaryKey(),
busNumber: varchar('bus_number').unique(),
routeId: integer('route_id').references(() => routes.id),
latitude: decimal('latitude'),
longitude: decimal('longitude'),
status: varchar('status'), // 'active', 'inactive', 'maintenance'
capacity: integer('capacity'),
createdAt: timestamp('created_at').defaultNow(),
updatedAt: timestamp('updated_at').defaultNow(),
});
// Routes table
export const routes = pgTable('routes', {
id: serial('id').primaryKey(),
name: varchar('name'),
description: text('description'),
schools: integer('schools'), // Number of schools on route
stops: integer('stops'), // Number of stops
createdAt: timestamp('created_at').defaultNow(),
});This project implements several security best practices:
- Minimum 1-day release age for npm packages (prevents malicious versions)
- Configured in
pnpm-workspace.yaml:minimumReleaseAge: 1440 # 24 hours
- Whitelist trusted orgs for emergency patches
- Rules-based access control (configure in Firebase Console)
- API key restrictions by HTTP referrer
- Database rules prevent unauthorized writes
- Granular API key restrictions and rotation
- Automated security scanning for Firebase rules
- AI-driven route optimization with privacy safeguards
- Real-time anomaly detection for suspicious patterns
- esbuild for fast JS bundling
- TypeScript project references for incremental builds
- Platform-specific overrides in pnpm to reduce bundle size on Replit (linux-x64 only)
- React Query for efficient data fetching with caching
- Expo for optimized mobile builds
- Lazy loading of map components
- Connection pooling via Drizzle ORM
- Indexed database queries for location lookups
- CORS optimized for single origin
- Live at: https://replit.com/@boikunthadev/School-Bus-Tracker
- Auto-deployed from GitHub repository
.replitand.replitignoreconfigured for seamless deployment
FROM node:24-alpine
WORKDIR /app
COPY . .
RUN pnpm install --frozen-lockfile
RUN pnpm run build
EXPOSE 3000
CMD ["pnpm", "run", "dev"]pnpm run build
# Deploy `artifacts/bus-tracker/.expo-shared/` or built outputpnpm run typecheck # Full monorepo typecheck
pnpm run typecheck:libs # Library-only typecheckpnpm run build # Full build (typecheck + build all packages)pnpm --filter @workspace/scripts run hello # Run hello.ts
pnpm --filter @workspace/api-server run dev # Start API in dev mode- Enable TypeScript source maps for debugging
- Use
tsxfor TypeScript execution (better errors thants-node)
Deployable applications that can run independently or as services.
-
api-server/โ Express.js REST APIsrc/index.tsโ Entry point with route handlersbuild.tsโ esbuild configuration for production bundle- Depends on:
@workspace/db,@workspace/api-zod
-
bus-tracker/โ React Native (Expo) mobile appapp/โ Expo Router file-based routingcontext/โ React Context for global state (buses, location)components/โ Reusable UI componentsconfig/โ Firebase initialization
-
mockup-sandbox/โ UI/UX prototype (Vite + React)
Shared libraries used across artifacts.
-
db/โ Database schema and Drizzle ORM setupschema.tsโ PostgreSQL tablesclient.tsโ Connection pool initialization
-
api-spec/โ OpenAPI 3.0 specificationopenapi.yamlโ Full API contractorval.config.tsโ Code generation rules
-
api-zod/โ Auto-generated Zod schemas from OpenAPI- Used for runtime validation
- Regenerated by:
pnpm run codegen
-
api-client-react/โ Auto-generated React Query hooks- Type-safe API calls
- Built from OpenAPI spec via Orval
Utility TypeScript scripts for development tasks.
src/hello.tsโ Example script- Run via:
pnpm --filter @workspace/scripts run hello
We welcome contributions! Here's how to get started:
git clone https://github.com/yourusername/School-Bus-Tracker.git
cd School-Bus-Trackergit checkout -b feature/amazing-featurepnpm install
pnpm run typecheck
pnpm run buildgit commit -m "feat: add amazing feature"
git push origin feature/amazing-feature- Describe your changes clearly
- Link any related issues
- Ensure tests pass
- ๐บ๏ธ Enhanced map features (polylines, geofencing)
- ๐ Improved notification system
- ๐ Analytics dashboard for school admins
- ๐ Multi-language support (i18n)
- ๐งช Unit & integration tests
- ๐ฑ iOS/Android native features
- ๐ Bug fixes and performance improvements
Solution: Ensure environment variables are set correctly or firebase.ts is configured.
echo $EXPO_PUBLIC_FIREBASE_API_KEYSolution: Verify PostgreSQL is running and DATABASE_URL is correct.
psql $DATABASE_URL -c "SELECT 1;"Solution: Install pnpm globally.
npm install -g pnpmSolution: Run full typecheck from root.
pnpm run typecheckSolution:
- Ensure device and computer are on same WiFi
- Check Expo dev server logs for errors
- Try clearing Expo cache:
pnpm cache clean && pnpm install
- Expo Documentation: https://docs.expo.dev/
- React Native: https://reactnative.dev/
- Drizzle ORM: https://orm.drizzle.team/
- Express.js: https://expressjs.com/
- Firebase Realtime Database: https://firebase.google.com/docs/database
- Orval (OpenAPI Codegen): https://orval.dev/
- pnpm Workspaces: https://pnpm.io/workspaces
- Tailwind CSS: https://tailwindcss.com/
This project is licensed under the MIT License โ see the LICENSE file for details.
MIT License
Copyright (c) 2024 Boikuntha
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software...
Boikuntha (@boikzdev)
- ๐ GitHub: boikzdev
- ๐ Replit: @boikunthadev
- ๐ฏ Focus: AI Red Teaming, DevSecOps, Full-Stack Development
If you find this project helpful:
- โญ Star this repository on GitHub
- ๐ Report bugs via GitHub Issues
- ๐ก Suggest features in discussions
- ๐ค Contribute code with pull requests
- ๐ข Share with your network
- โ Real-time bus tracking
- โ Firebase Realtime Database integration
- โ React Native mobile app
- โ Express backend API
- โ TypeScript monorepo
- Advanced route optimization (AI-driven)
- Multi-school support
- Admin dashboard for school coordinators
- Parent/student SMS notifications
- Historical analytics & reports
- Driver mobile app
- Integration with school information systems (SIS)
- Autonomous vehicle compatibility
- Predictive maintenance alerts
- Environmental impact tracking
- Integration with public transit systems
- AR navigation features
Built with โ and curiosity for better school transportation