Skip to main content

Road Hazard Map

道路危険マップCourse project
Road Hazard Map screenshot
Demo accounts run on a separate database — real data is never touched

Road users mark and confirm road hazards together: see a pothole, a faded marking or a dangerous intersection, take a photo and report it; others confirm it, and administrators move its status from "pending" to "verified" to "fixed". The front end is a vanilla JS single-page app with no bundler that can be added to a phone's home screen (PWA), deployed on Render.

Problem

Information about potholes, faded road markings and dangerous intersections is scattered. This project lets road users report hazards on a map, others confirm them, and administrators track progress in an admin panel — from "pending" to "verified" to "fixed".

My roleGroup project for the Systems Analysis and Design course; I built the v2 rewrite (modular code, two databases, deployment on Render).

Key decisions

  1. 01

    Separate databases for real data and demo data

    Middleware switches the database based on the logged-in account; whatever the demo account does never touches real data, and the demo data is rebuilt on every start.

  2. 02

    Split the back end into routes / middleware / db

    Express only wires them together, and each layer can be changed and tested on its own.

  3. 03

    Passwords and sessions done the standard way

    Passwords use PBKDF2-SHA256 (100,000 iterations, a random salt per user); sessions use a 192-bit random token in an HttpOnly cookie.

  4. 04

    Validate every input

    All SQL is parameterised; string lengths, number ranges and uploaded file sizes and types are checked; a composite primary key stops duplicate votes.

  5. 05

    No bundler on the front end, and make it a PWA

    The vanilla JS single-page app can be added to a phone's home screen, so reporting with a photo doesn't need a separate app.

Trade-offs

  • SQLite is a single-file database that suits a project of this size; many simultaneous writers would need a database server

Results

  • Map reports (GPS location or tap to place, optional photo), community confirmations, comments, 6 achievement badges, and an admin panel (moderation, charts, CSV export)
  • The demo account can safely be handed to anyone to try

Architecture

fetch /api

Basic Auth

Vanilla JS single-page app
Leaflet map + PWA

Express app.js

Admin panel admin.html

middleware
switches database by account

routes
hazards / posts / users / admin

data.sqlite
real data

data-demo.sqlite
demo data, rebuilt on start

fetch /api

Basic Auth

Vanilla JS single-page app
Leaflet map + PWA

Express app.js

Admin panel admin.html

middleware
switches database by account

routes
hazards / posts / users / admin

data.sqlite
real data

data-demo.sqlite
demo data, rebuilt on start

Features

  • Map home page: a dark Leaflet map with 6 category filters; severity 1–5 maps to marker size, and the most severe ones pulse
  • Quick reports: GPS locates you automatically, and if the browser denies location you tap the map instead; photos can be attached
  • Community confirmations: one vote per person per post (a composite primary key blocks duplicates), plus comments
  • Achievements: the back end awards 6 badges automatically when reports come in — for example "Night Owl" for 5 reports between 6 pm and 6 am
  • Admin panel: moderate status, pin or remove posts, manage users, charts, CSV export

Backend

  • Two databases: one SQLite file for real data and one for demo data, switched by middleware based on the logged-in account, so the demo account can never pollute real data
  • Demo data is rebuilt on every start: fictional users plus 20 locations in Kaohsiung (coordinates checked against OpenStreetMap Nominatim)
  • Passwords use PBKDF2-SHA256 (100,000 iterations, a random salt per user); sessions use a 192-bit random token in an HttpOnly cookie
  • Every SQL query is parameterised; string lengths, number ranges and uploaded file sizes and types are validated
  • The code is split into routes / middleware / db, with Express only wiring them together

Group project for the Systems Analysis and Design course. I built the v2 rewrite (modular code, two databases, deployment on Render). The screenshot shows the demo account's fictional data.

Type to search projects and posts too