Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

18 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

VMC Pothole Detection Platform

This project is a full-stack pothole reporting and monitoring platform with a citizen-facing app, an admin dashboard, an Express/MongoDB backend, and a Flask-based AI detection service. The repo is organized into user-panel and admin-panel frontends, plus a Node backend and a Flask service.


Features

  • Citizen web app (Vite + React + TypeScript) with Firebase authentication and protected routes.
  • Report creation with image upload, geolocation and metadata, stored in MongoDB.
  • AI-powered image analysis via a Flask /predict-image endpoint.
  • Government admin dashboard (Create React App) with map visualization using Leaflet and analytics using Recharts.
  • Admin login with token-based authentication against http://localhost:5000/api/login.

Project Structure

This section summarizes the main modules and how they relate.

  • user-panel/ โ€“ Citizen UI (Vite + React + TS + Tailwind + shadcn/ui).
  • user-panel/backend/ โ€“ Node/Express API integrating with MongoDB and Flask AI.
  • user-panel/models/Report.js โ€“ MongoDB schema for stored reports.
  • user-panel/integrations/firebase/ โ€“ Firebase auth, Firestore and Storage client.
  • admin-panel/ โ€“ Admin dashboard (CRA + Tailwind).
  • Flask AI service โ€“ Python app with /predict-image route listening on port 5001.

High-Level Architecture

This diagram shows how the pieces connect.

๐Ÿ“Œ System Architecture Diagram

flowchart LR

  %% CLUSTERS
  subgraph CitizenApp ["Citizen Web App - User Panel"]
      U["User Browser"]
  end

  subgraph Firebase ["Firebase Services"]
      FA["Auth"]
      FD["Firestore and Storage"]
  end

  subgraph NodeAPI ["Node Express API - User Backend"]
      E["Express API 5000"]
      M["MongoDB Database"]
  end

  subgraph FlaskAI ["Flask AI Detection Service"]
      F["Predict Image API 5001"]
  end

  subgraph AdminApp ["Admin Dashboard Panel"]
      A["Admin Browser"]
  end

  %% CONNECTIONS
  U -->|Login and Signup| FA
  U -->|Submit Report with Image| E

  E -->|Store and Query Data| M
  E -->|Send Image to AI| F
  F -->|AI Response| E

  FA -->|Authentication State| U
  U -->|Retrieve Dashboard Data| FD

  A -->|Login Request| E
  A -->|Fetch Reports and Stats| E
  E -->|Return Aggregated Data| A
Loading

Prerequisites

Make sure you have these installed before running the project.

  • Node.js (LTS) and npm or bun.
  • Python 3 for the Flask AI service.
  • MongoDB instance (Atlas or self-hosted).
  • A Firebase project (Web app) with Email/Password auth enabled.

1. User Panel (Citizen App)

The user panel is a Vite React + TypeScript application with Tailwind and shadcn/ui.

Setup

  1. Install dependencies:

    cd user-panel
    npm install
    # or
    bun install
    
  2. Create an .env file in user-panel/:

    VITE_FIREBASE_API_KEY=...
    VITE_FIREBASE_AUTH_DOMAIN=...
    VITE_FIREBASE_PROJECT_ID=...
    VITE_FIREBASE_STORAGE_BUCKET=...
    VITE_FIREBASE_MESSAGING_SENDER_ID=...
    VITE_FIREBASE_APP_ID=...
    

    These keys are read in src/integrations/firebase/client.ts.

  3. Start the dev server:

    npm run dev
    

    Vite is configured to run on port 8080.

Key Technologies

  • React + TypeScript + Vite entry point: src/main.tsx, src/App.tsx.
  • Auth via AuthProvider wrapping React Router routes and useAuth hook.
  • Themed UI via ThemeProvider and ThemeToggle.
  • Dashboard and reporting sections in src/components/dashboard-section.tsx and src/components/report-section.

2. Node Backend (user-panel/backend)

The Node backend exposes APIs for reports and bridges to MongoDB and the Flask AI service.

Setup

  1. Install dependencies:

    cd user-panel/backend
    npm install
    

    (If there is no package.json yet, create one and add express, mongoose, cors, multer, axios, and form-data.)

  2. Configure MongoDB:

    • Update mongoose.connect(...) in server.js to use an environment variable instead of the hard-coded string.

    • For example:

      // server.js (example change, not yet in repo)
      mongoose.connect(process.env.MONGODB_URI);
      
    • Then create a .env (or similar) with your MongoDB connection string.

  3. Start the API server:

    node server.js
    

    The API listens on port 5000.

Responsibilities

  • Mounts /api routes and connects to MongoDB.
  • utils/reports.js defines the /report route that:
    • Accepts multipart image uploads.
    • Sends the image to Flask at http://127.0.0.1:5001/predict-image.
    • Stores the full report plus AI result into MongoDB using the Report model.

3. Flask AI Service

The Flask service performs image analysis and returns predictions to the Node backend.

Setup (high level)

  1. Create and activate a Python virtual environment.

  2. Install Flask and required ML / image libraries according to your model code.

  3. Ensure the app exposes POST /predict-image and runs on port 5001:

    if __name__ == "__main__":
        app.run(host="0.0.0.0", port=5001, debug=True)
    

    This is referenced by the axios.post("http://127.0.0.1:5001/predict-image", ...) call in utils/reports.js.


4. Admin Panel (Government Dashboard)

The admin panel is a Create React App-based dashboard that consumes the Node API and displays map and analytics views.

Setup

  1. Install dependencies:

    cd admin-panel
    npm install
    
  2. Start the dev server:

    npm start
    

    CRA defaults to port 3000.

Behavior

  • src/App.js switches between Login and Dashboard based on local storage token and user.
  • src/pages/Login.js posts credentials to http://localhost:5000/api/login, then stores a JWT token and user data.
  • src/pages/Dashboard.js shows:
    • Leaflet map with damage markers.
    • Recharts graphs for severity, trends, and other stats.

Demo credentials are shown in the login page UI (for local development only).


5. Running the Full Stack

Follow this order to get a working end-to-end system.

  1. Start MongoDB and ensure the connection string is valid for the Node backend.
  2. Start the Flask AI service on port 5001.
  3. Start the Node backend (user-panel/backend/server.js) on port 5000.
  4. Start the user-panel Vite dev server (port 8080).
  5. Start the admin-panel CRA dev server (port 3000).

You should now be able to:

  • Visit http://localhost:8080 to use the citizen-facing app.
  • Visit http://localhost:3000 to log into the admin portal.

6. API Reference

This section documents the main HTTP endpoints used across the project.

POST /api/report (Node backend)

โŒ API Block Error
Invalid JSON format: control character error, likely incorrect encoding

The route is defined in utils/reports.js and mounted under /api in backend/server.js.


POST /predict-image (Flask AI)

Purpose:
Internal endpoint used by the Node backend to run AI-based detection on uploaded road images.


๐Ÿ”น Endpoint

POST http://127.0.0.1:5001/predict-image

๐Ÿ”น Headers

Header Type Required Value
Content-Type string Yes multipart/form-data

๐Ÿ”น Request Body (Form Data)

Field Type Required Description
image file Yes Image forwarded from Node backend

๐Ÿ”น Example Request

curl -X POST "http://127.0.0.1:5001/predict-image" \
  -H "Content-Type: multipart/form-data" \
  -d "image=@sample.jpg"

๐Ÿ”น Response โ€” 200 OK

{
  "success": true,
  "detections": [
    { "label": "pothole", "confidence": 0.97, "bbox": [x1, y1, x2, y2] }
  ],
  "output_image": "path_or_url_to_annotated_image"
}

๐Ÿ”น Response โ€” 500 Error

{
  "success": false,
  "error": "Error message"
}

The Node backend calls this endpoint using:

axios.post("http://127.0.0.1:5001/predict-image", ...)

POST /api/login (Admin Login)

Authenticate an admin user and return a JWT token + basic user information.


๐Ÿ”น Endpoint

POST http://localhost:5000/api/login

๐Ÿ”น Headers

Header Type Required Value
Content-Type string Yes application/json

๐Ÿ”น Request Body (JSON)

{
  "username": "admin",
  "password": "government123"
}

๐Ÿ”น Example Request

curl -X POST "http://localhost:5000/api/login" \
  -H "Content-Type: application/json" \
  -d '{
    "username": "admin",
    "password": "government123"
  }'

๐Ÿ”น Responses

โœ… 200 OK โ€” Login successful

{
  "token": "jwt_token_string",
  "user": {
    "name": "Admin User",
    "role": "admin"
  }
}

โš ๏ธ 401 Unauthorized โ€” Invalid credentials

{
  "message": "Login failed"
}

โŒ 500 Internal Server Error

{
  "message": "Internal server error"
}

Matches usage in admin-panel/src/pages/Login.js, where token and user fields are expected.

๐Ÿง  AI Model Overview โ€“ Road Damage Detection Engine

This project integrates a lightweight YOLO-based deep learning model trained for pothole and road anomaly detection.
It powers the backend image analysis pipeline and supports real-time detection through a Flask inference service.


๐Ÿ” Model Summary

Attribute Value
Architecture YOLO-based object detection
Total Layers 129
Parameters 3,011,628 (~3M)
Gradients 0 (frozen inference weights)
Compute Requirement 8.2 GFLOPs per image
Input Resolution 640 ร— 640

This compact design enables high performance while remaining efficient for:

  • laptops
  • edge devices
  • microservers
  • cloud deployment

๐Ÿš€ How the Model Works in This System

  1. Backend receives an image from the mobile app / admin dashboard
  2. Flask API loads best.pt and performs inference
  3. Model returns:
    • detected potholes
    • confidence score
    • bounding box values
    • annotated output image

๐Ÿ“Œ Use Cases

  • Smart City road monitoring
  • Municipal complaint automation
  • Fleet vehicle camera systems
  • Citizen reporting apps
  • Autonomous maintenance assessment

๐Ÿ“Ž Integration Flow

flowchart TB
    App[Mobile App] --> API[Node Backend API]
    Dashboard[Admin Dashboard] --> API

    API --> DB[(MongoDB)]
    API --> AI[Flask YOLO Inference Service]
    AI --> Model[(best.pt Model File)]

    API --> Storage[(Image Storage)]

    API --> Dashboard
    API --> App
Loading

๐Ÿงฉ Why This Architecture?

โœ” Lightweight โ€“ deployable on low-power hardware
โœ” Fast inference โ€“ suitable for real-time use
โœ” Modular โ€“ backend and AI are decoupled
โœ” Expandable โ€“ can be retrained for cracks, speed breakers, etc.


๐Ÿ”ง Files Included

File Purpose
best.pt AI model weight file
app.py Flask-based inference API exposing /predict-image

๐Ÿ“Œ Possible Extensions

  • Support multi-class road damage detection
  • Add segmentation masks instead of bounding boxes
  • Deploy to edge devices like Jetson Nano / Coral TPU
  • Add continuous learning with feedback loop

๐Ÿ”„ Model Pipeline

sequenceDiagram
    participant User
    participant Backend
    participant Flask
    participant Model
    participant Output

    User->>Backend: Upload Image
    Backend->>Flask: POST /predict-image
    Flask->>Model: Run inference
    Model-->>Flask: Return detections
    Flask-->>Backend: JSON + annotated output
    Backend-->>User: Display result
Loading

๐Ÿ“Š Model Evaluation & Performance Metrics

The trained YOLO-based defect detection model (best.pt) was evaluated across four defect types: crack, pothole, patch, and other.
This section summarizes confidence behavior, accuracy, training curves, dataset distribution, and confusion metrics.

๐Ÿ“Œ Quantitative Performance Summary

๐Ÿ”น Per-Class Metrics

Class mAP@0.5 Peak F1 Observations
Crack 0.648 ~0.60 Strong detection performance, slight confusion with background
Pothole 0.664 ~0.62 Best performing class โ€” clear object structure
Patch 0.412 ~0.43 Weakest โ€” likely due to dataset imbalance / ambiguity
Other 0.577 ~0.58 Moderate performance with confusion vs background
Average 0.575 ~0.57 Strong enough for real-world inference

๐Ÿ”น Confidence Behavior Summary

Metric Peak Value Best Confidence Threshold
F1 score (overall) ~0.57 ~0.28
Precision ~1.00 ~0.95
Recall ~0.85 ~0.00

๐Ÿ”น Interpretation Insights

โœ” Increasing confidence improves precision but lowers recall
โœ” Best working threshold range โ†’ 0.25 โ€“ 0.35
โœ” Patch class would benefit from augmentation or re-labelling


๐Ÿ”น Confidenceโ€“Performance Curves

These plots illustrate how confidence scores affect model stability and output quality.

F1 vs Confidence Curve

F1 Curve

Precision vs Confidence Curve

Precision Curve

Precisionโ€“Recall Curve

Overall performance shows mAP@0.5 = 0.575, with per-class values shown in legend. Precision-Recall Curve

Recall vs Confidence Curve

Recall Curve


๐Ÿ”น Confusion Matrices

Raw Confusion Matrix

Shows the exact number of correct/incorrect predictions across classes.

Confusion Matrix

Normalized Confusion Matrix

Shows proportional confusion per class for precision analysis.

Confusion Matrix Normalized


๐Ÿ”น Dataset Distribution & Spatial Density

This figure highlights: โœ” Number of labeled objects per class
โœ” Spatial heatmap of object centers
โœ” Bounding box size distribution

Dataset Labels & Density


๐Ÿ”น Training Progress Metrics

Loss curves and validation metrics demonstrate consistent convergence throughout training.

Training Results


๐Ÿ“Œ Model Summary Insight

โœ” Best average operating threshold ~0.28 confidence
โœ” Best precision achieved near ~0.95 confidence
โœ” Highest confusion occurs between crack vs background
โœ” โ€œPatchโ€ class is weakest โ€” likely due to dataset imbalance or class ambiguity


๐Ÿ“Œ Recommendations

  • Improve dataset balance for underrepresented classes
  • Add harder background cases to reduce false positives
  • Consider threshold tuning per class
  • Explore augmentation & label refinement for โ€œpatchโ€

Python YOLO Flask NodeJS MongoDB Firebase Ultralytics

About

This project is an AI-powered pothole monitoring platform that detects road defects using YOLO, allows citizens to report issues, and provides administrators with a dashboard to track and resolve them. It combines computer vision, backend automation, and user interfaces to make road maintenance faster and smarter.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages