SafetyTrackr

Real-time miner safety and location sharing — built for operations teams who need to know who is on site, where they are, and whether they need help.

SafetyTrackr gives mine supervisors a live ops dashboard while miners carry a lightweight mobile web app on their phone. No dedicated tracking hardware required: the miner app combines GPS anchoring with device motion sensors to plot movement on a mine site schematic, even in areas where raw GPS is unreliable.


The Problem

Mining is one of the most dangerous industrial environments on earth. Workers operate across large, complex sites — often out of direct line-of-sight from supervisors. When something goes wrong — a fall, a missed check-in, a worker entering an unstable section, or a device going offline — response time depends entirely on knowing who is in trouble and where they are.

Traditional solutions rely on expensive proprietary mesh networks, dedicated wearable hardware, or paper-based check-in systems that don't scale and don't provide live situational awareness. Small and mid-size operations are often left without affordable, real-time visibility across the site.


Why It Matters

Challenge How SafetyTrackr addresses it
Unreliable GPS on site Hybrid positioning: GPS anchor + accelerometer step detection + compass heading, amplified for fine-grained movement
Missed welfare check-ins Configurable countdown timer (default 2.5 min); auto-escalates to DISTRESS if not acknowledged
Emergency response One-tap SOS, audible alerts on admin dashboard, incident log with dispatch workflow
Unconscious / injured worker Fall detection via accelerometer with 60-second "Are you okay?" prompt; auto-SOS if no response
Hazardous zones Admins draw hazard zones on the map; miners trigger alerts when entering unstable areas
Device failures 45-second stale-connection detection marks miners offline; low-battery warnings at 15%
Post-incident review Trail history replay and heatmap of movement over the last 60 minutes

SafetyTrackr turns any smartphone into a safety node and gives supervisors a single pane of glass for the entire active roster.


Key Features

Admin Operations Dashboard (/admin)

  • Live 2D site map with real-time miner positions streamed over WebSocket
  • 3D mine model (Three.js) with orbit controls and per-zone level filtering
  • Movement heatmap showing where miners spent the most time
  • Trail history — scrub timeline or play back the last hour of movement for any miner
  • Level filtering — zoom into Surface, L1, L2, L3, or L4; miners on other levels fade out
  • Live stats — on-site headcount, active alerts, average battery
  • Incident feed — SOS, distress, offline, low battery, hazard entry, fall events
  • Dispatch workflow — acknowledge and resolve alerts from the roster panel
  • Zone occupancy — per-level headcount breakdown

Miner Mobile UI (/miner)

  • Live mini-map with nearby crew awareness (within 300 m)
  • Nearest exit guidance with distance and bearing
  • Periodic check-in ring with countdown; tap I'M OK to reset
  • SOS toggle with audible confirmation
  • Fall detection — full-screen alert with countdown; dismiss or auto-SOS
  • Auto level detection based on position on the site map

Admin Management

  • Miners (/admin/miners) — add/remove crew, reset passwords, one-time credential display
  • Zones (/admin/zones) — draw rectangular or polygon zones, mark hazards, zoom to zone

Tech Stack

Layer Technology
Framework Next.js 14 (Pages Router)
UI React 18, CSS Modules
3D visualization Three.js, @react-three/fiber, @react-three/drei
Real-time Socket.io (custom Node HTTP server)
Database MySQL via mysql2
Auth iron-session + bcryptjs (role-based: admin / miner)
Positioning Browser Geolocation API, DeviceMotion, DeviceOrientation, Battery Status API

Architecture

┌─────────────┐     WebSocket      ┌──────────────────┐
│  Miner App  │◄──────────────────►│  server.js       │
│  (browser)  │     REST /api/*    │  Next.js +       │
└─────────────┘                    │  Socket.io       │
                                   └────────┬─────────┘
┌─────────────┐     WebSocket               │
│ Admin Dash  │◄────────────────────────────┤
│  (browser)  │     REST /api/*             │
└─────────────┘                             ▼
                                   ┌──────────────────┐
                                   │  MySQL           │
                                   │  miners, zones,  │
                                   │  positions,      │
                                   │  incidents,      │
                                   │  trail history   │
                                   └──────────────────┘
  • Position updates broadcast to admins immediately (before DB write) for sub-second map refresh
  • Server tick runs every 1 second for check-in countdowns, offline detection, and battery simulation
  • SQL migrations are versioned and idempotent via schema_migrations

Project Stats

Metric Value
Site levels 4 zones + main access route
Default route segments 8
Pre-seeded zones 6 (including 1 hazard zone)
Emergency exits 2 (Surface Shaft, Refuge Bay R3)
Check-in interval 150 s (2 min 30 s)
Offline threshold 45 s without position update
Fall response window 60 s before auto-SOS
Nearby crew radius 300 m
Position sync rate 1 s
Trail / heatmap window 60 min
Map view modes 3 (Live 2D, 3D Mine, Heatmap)
Incident types tracked 10 (SOS, distress, offline, low battery, check-in, dispatch, hazard, fall, fall-SOS, info)
API routes 14
SQL migrations 7
React components 8
Custom hooks 6

Getting Started

Prerequisites

  • Node.js 18+
  • MySQL 8+

1. Configure environment

Create .env.local in the project root:

DATABASE_HOST=localhost
DATABASE_USER=root
DATABASE_PASSWORD=your_password
DATABASE_NAME=cursor_hack
SESSION_SECRET=change-me-in-production
PORT=3000

2. Install dependencies

npm install

3. Run database migrations

npm run migrate

This creates all tables, applies seed data (mine map, routes, zones, exits), and ensures the default admin account exists.

4. Start the dev server

npm run dev

Open http://localhost:3000

Production

npm run build
npm start

Default Login

Role Username Password
Admin admin admin123

Miners are created in Admin → Miners. A one-time username and password is shown when each miner is added.


Pages & Routes

Path Description
/login Sign in (admin or miner)
/admin Live ops dashboard — map, alerts, roster, incidents
/admin/miners Crew management — add, remove, reset passwords
/admin/zones Zone editor — draw areas, mark hazards
/miner Miner mobile UI — GPS, check-in, SOS, fall detection

API Endpoints

Endpoint Purpose
POST /api/auth/login Authenticate
POST /api/auth/logout End session
GET /api/state Full dashboard state
POST /api/positions Submit miner position
POST /api/checkin Reset check-in timer
POST /api/sos Toggle SOS
POST /api/fall Fall detection events
GET /api/trails Position history for replay / heatmap
GET/POST /api/miners List / create miners
POST/DELETE /api/miners/[id] Dispatch / remove miner
GET/POST /api/zones List / create zones
DELETE /api/zones/[id] Remove zone
GET /api/incidents Incident log

How Positioning Works

GPS alone can be unreliable across a large mine site. SafetyTrackr uses a hybrid approach:

  1. GPS anchor — the first fix becomes the origin; subsequent GPS deltas are mapped to the site schematic with 40× amplification for fine-grained movement tracking
  2. Step detection — accelerometer spikes (~1.5 ft per step) advance position along compass heading
  3. Motion drift — fine-grained accelerometer integration for sub-meter adjustments between steps
  4. Route snapping — positions are associated with the nearest route segment for level/zone assignment

Updates sync to the server every 1 second and broadcast to all connected admin clients in real time.

Built With

Share this project:

Updates