A real-time parking discovery and booking application built with Next.js 14, Firebase Firestore, and React Leaflet. ESP32 IoT sensors push live slot availability to the UI instantly.
- πΊοΈ Interactive Map β OpenStreetMap with color-coded parking markers
- β‘ Real-time Updates β ESP32 sensors β Firebase β UI with
onSnapshot π ΏοΈ Visual Slot Grid β See exact slot layout with live occupancy- π Park Now & Pre-book β Immediate or scheduled parking
- π Booking History β With expandable detail cards
- π€ Profile Management β Editable user & vehicle info
- π± Mobile-first β Google Maps / Uber-style bottom sheets
- Node.js 18+ β https://nodejs.org
- pnpm β
npm install -g pnpm - Firebase project β https://console.firebase.google.com
git clone https://github.com/your-username/smart-parking-app.git
cd smart-parking-app
pnpm installa) Create Firebase Project
- Go to https://console.firebase.google.com
- Create project β Enable Firestore Database
- Go to Project Settings β General β Your Apps β Add Web App
- Copy the config values
b) Set Firestore Rules (Dev mode)
In Firebase Console β Firestore β Rules, paste:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
cp .env.local.example .env.localEdit .env.local with your Firebase config:
NEXT_PUBLIC_FIREBASE_API_KEY="AIzaSy..."
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN="your-project.firebaseapp.com"
NEXT_PUBLIC_FIREBASE_PROJECT_ID="your-project"
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET="your-project.firebasestorage.app"
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID="000000000000"
NEXT_PUBLIC_FIREBASE_APP_ID="1:000:web:xxx"# Install firebase-admin for the script
pnpm add -D firebase-admin
# Download your service account key from Firebase Console
# Project Settings β Service Accounts β Generate new private key
# Save as scripts/serviceAccountKey.json
node scripts/initFirebaseData.jsThis creates:
- 3 parking sites in Mumbai
- 18-30 slots per site with random initial occupancy
pnpm dev
# β http://localhost:3000smart-parking-app/
βββ app/
β βββ layout.tsx # Root layout + Leaflet CSS
β βββ page.tsx # Map home page
β βββ globals.css # Global styles
β βββ history/
β β βββ page.tsx # Booking history
β βββ profile/
β βββ page.tsx # User profile
βββ components/
β βββ ParkingMap.tsx # Leaflet map + markers
β βββ SearchBar.tsx # Floating search + locate me
β βββ ParkingBottomSheet.tsx # Slide-up parking card
β βββ SlotGrid.tsx # Interactive slot layout
β βββ BookingModal.tsx # 3-step booking flow
β βββ Navbar.tsx # Bottom navigation
βββ hooks/
β βββ useFirestore.ts # All Firebase queries & real-time hooks
βββ lib/
β βββ firebase.ts # Firebase initialization
β βββ utils.ts # Helper functions
βββ types/
β βββ index.ts # TypeScript types
βββ scripts/
β βββ initFirebaseData.js # Seed Firebase with sample data
β βββ esp32_sensor.ino # Arduino firmware for ESP32
βββ .env.local.example # Environment template
βββ firestore.rules # Firebase security rules
βββ package.json
- Open
scripts/esp32_sensor.inoin Arduino IDE - Install libraries:
ArduinoJsonvia Library Manager - Fill in your WiFi credentials and Firebase API key
- Wire HC-SR04 sensor: TRIG β GPIO5, ECHO β GPIO18
- Flash to ESP32 β it auto-pushes slot status every 3 seconds
Data flow:
HC-SR04 Sensor
β
ESP32 (WiFi)
β HTTPS PATCH
Firebase Firestore
β onSnapshot
Next.js Web App
β
UI updates live
| Command | Description |
|---|---|
pnpm dev |
Start development server |
pnpm build |
Build for production |
pnpm start |
Start production server |
pnpm lint |
Run ESLint |
node scripts/initFirebaseData.js |
Seed Firebase |
pnpm add -g vercel
vercel
# Follow prompts, add env vars in Vercel dashboardpnpm build
pnpm start
# Runs on port 3000FROM node:18-alpine
WORKDIR /app
COPY . .
RUN npm install -g pnpm && pnpm install && pnpm build
EXPOSE 3000
CMD ["pnpm", "start"]| Collection | Description |
|---|---|
parkingSites |
Parking locations with coordinates |
parkingSlots |
Per-slot occupancy (updated by ESP32) |
bookings |
User booking records |
Map not loading?
- Ensure
leaflet/dist/leaflet.cssis imported inlayout.tsx - Check browser console for CSP errors
Firebase permission denied?
- Set Firestore rules to allow read/write (dev mode)
- Verify
.env.localhas correct values withNEXT_PUBLIC_prefix
Markers not showing?
- Run
node scripts/initFirebaseData.jsto seed parking sites - Check Firestore console to confirm data exists
ESP32 not sending data?
- Verify WiFi credentials in
.inofile - Check Serial Monitor at 115200 baud for error messages
- Ensure Firebase API key is correct
MIT








