# mahmud-r-farhan/realtime-location-tracker architecture

> Architecture diagram of the GitHub repository mahmud-r-farhan/realtime-location-tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mahmud-r-farhan/realtime-location-tracker
- Repository: https://github.com/mahmud-r-farhan/realtime-location-tracker

## Overview

This is a browser-based, room-scoped real-time location and communication platform. A visitor opens the PWA, receives a signed session cookie, joins a room, and shares location updates that peers see on a Leaflet map; the same room supports chat, WebRTC voice, battery status, and SOS relays. The server’s Socket.IO layer routes room events, while client modules provide those distinct features. PWA caching and multiple map layers are documented capabilities. Some client and server wiring is unsampled, so edges are limited to cited imports, excerpts, or README statements.

Main entry points: [`public/js/main.js`](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/main.js) (Client Startup), [`public/js/map.js`](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/map.js) (Live Map), [`public/js/socket.js`](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/socket.js) (Socket Client), [`src/app.js`](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/src/app.js) (Express App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser Client"]
  node_main["Client Startup<br/>[main.js]"]
  node_pwa["Offline PWA<br/>[pwa.js]"]
  node_serviceworker["Service Worker<br/>[sw.js]"]
  node_controls["Map Controls<br/>[controls.js]"]
  node_profile["Room Profile<br/>[profile.js]"]
  node_ui["Device and Panels UI<br/>[ui.js]"]
  node_notifications["Notifications<br/>[notification.js]"]
  node_sounds["Alert Sounds<br/>[sounds.js]"]
  node_config["Client Configuration<br/>[config.js]"]
  node_utils["Shared Utilities<br/>[utils.js]"]
end

subgraph group_location["Tracking and Devices"]
  node_map["Live Map<br/>[map.js]"]
  node_device["Device Identity<br/>[device.js]"]
  node_battery["Fleet Battery<br/>[batteryMonitor.js]"]
end

subgraph group_communication["Room Communication"]
  node_socketclient["Socket Client<br/>[socket.js]"]
  node_chat["Room Chat<br/>[chat.js]"]
  node_audio["WebRTC Voice<br/>[audio.js]"]
  node_sos["SOS Relay UI<br/>[sos.js]"]
end

subgraph group_server["Server Runtime"]
  node_app["Express App<br/>[app.js]"]
  node_http["HTTP Routes<br/>[routes.js]"]
  node_middleware["Security Middleware<br/>[middleware.js]"]
  node_socketserver["Socket.IO Rooms<br/>[sockets.js]"]
end

node_visitor(("Visitor"))
node_browser(("Peer Browser"))

node_visitor -->|"opens app"| node_browser
node_browser -->|"requests page"| node_app
node_app -->|"configures"| node_middleware
node_app -->|"registers routes"| node_http
node_app -->|"sets up sockets"| node_socketserver
node_http -->|"issues session"| node_browser
node_browser -->|"connects by socket"| node_socketserver
node_socketserver -->|"verifies session"| node_http
node_browser -->|"runs client"| node_main
node_main -->|"initializes"| node_map
node_main -->|"initializes handlers"| node_socketclient
node_main -->|"initializes controls"| node_audio
node_main -->|"initializes"| node_chat
node_main -->|"initializes"| node_sos
node_main -->|"uses panels"| node_ui
node_main -->|"updates room"| node_profile
node_socketclient -->|"updates markers"| node_map
node_socketclient -->|"updates device list"| node_ui
node_socketclient -->|"delivers messages"| node_chat
node_socketclient -->|"dispatches signaling"| node_audio
node_chat -->|"focuses marker"| node_map
node_audio -->|"signals peers"| node_socketclient
node_sos -->|"shows alert location"| node_map
node_battery -->|"alerts"| node_notifications
node_battery -->|"reads room state"| node_socketclient
node_battery -->|"plays alerts"| node_sounds
node_chat -->|"notifies activity"| node_notifications
node_notifications -->|"plays beep"| node_sounds
node_map -->|"renders device icons"| node_device
node_map -->|"validates coordinates"| node_utils
node_map -->|"uses map settings"| node_config
node_ui -->|"focuses devices"| node_map
node_pwa -.->|"registers caching"| node_serviceworker
node_serviceworker -->|"caches assets"| node_browser
node_socketserver -->|"relays room events"| node_browser

click node_app "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/src/app.js"
click node_http "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/src/routes/routes.js"
click node_middleware "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/src/middleware/middleware.js"
click node_socketserver "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/src/sockets/sockets.js"
click node_main "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/main.js"
click node_pwa "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/pwa.js"
click node_serviceworker "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/sw.js"
click node_controls "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/controls.js"
click node_map "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/map.js"
click node_device "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/device.js"
click node_battery "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/batteryMonitor.js"
click node_socketclient "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/socket.js"
click node_chat "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/chat.js"
click node_audio "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/audio.js"
click node_sos "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/sos.js"
click node_profile "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/profile.js"
click node_ui "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/ui.js"
click node_notifications "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/notification.js"
click node_sounds "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/sounds.js"
click node_config "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/config.js"
click node_utils "https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/utils.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_pwa,node_serviceworker,node_controls,node_profile,node_ui,node_notifications,node_sounds,node_config,node_utils,node_browser toneBlue
class node_map,node_device,node_battery toneAmber
class node_socketclient,node_chat,node_audio,node_sos toneMint
class node_app,node_http,node_middleware,node_socketserver toneRose
class node_visitor toneIndigo
```

## Components

### Browser Client

- [Client Startup](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/main.js): `public/js/main.js`
- [Offline PWA](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/pwa.js): `public/js/pwa.js`
- [Service Worker](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/sw.js): `public/sw.js`
- [Map Controls](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/controls.js): `public/js/controls.js`
- [Room Profile](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/profile.js): `public/js/profile.js`
- [Device and Panels UI](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/ui.js): `public/js/ui.js`
- [Notifications](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/notification.js): `public/js/notification.js`
- [Alert Sounds](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/sounds.js): `public/js/sounds.js`
- [Client Configuration](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/config.js): `public/js/config.js`
- [Shared Utilities](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/utils.js): `public/js/utils.js`

### Tracking and Devices

- [Live Map](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/map.js): `public/js/map.js`
- [Device Identity](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/device.js): `public/js/device.js`
- [Fleet Battery](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/batteryMonitor.js): `public/js/batteryMonitor.js`

### Room Communication

- [Socket Client](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/socket.js): `public/js/socket.js`
- [Room Chat](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/chat.js): `public/js/chat.js`
- [WebRTC Voice](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/audio.js): `public/js/audio.js`
- [SOS Relay UI](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/public/js/sos.js): `public/js/sos.js`

### Server Runtime

- [Express App](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/src/app.js): `src/app.js`
- [HTTP Routes](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/src/routes/routes.js): `src/routes/routes.js`
- [Security Middleware](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/src/middleware/middleware.js): `src/middleware/middleware.js`
- [Socket.IO Rooms](https://github.com/mahmud-r-farhan/realtime-location-tracker/blob/master/src/sockets/sockets.js): `src/sockets/sockets.js`

### Other components

- **Visitor**
- **Peer Browser**

## Connections

- Visitor → Peer Browser: opens app (evidence: `README.md`)
- Peer Browser → Express App: requests page (evidence: `README.md`)
- Express App → Security Middleware: configures (evidence: `src/app.js`)
- Express App → HTTP Routes: registers routes (evidence: `src/app.js`)
- Express App → Socket.IO Rooms: sets up sockets (evidence: `src/app.js`)
- HTTP Routes → Peer Browser: issues session (evidence: `src/routes/routes.js`)
- Peer Browser → Socket.IO Rooms: connects by socket (evidence: `README.md`)
- Socket.IO Rooms → HTTP Routes: verifies session (evidence: `src/sockets/sockets.js`)
- Peer Browser → Client Startup: runs client (evidence: `README.md`)
- Client Startup → Live Map: initializes (evidence: `public/js/main.js`)
- Client Startup → Socket Client: initializes handlers (evidence: `public/js/main.js`)
- Client Startup → WebRTC Voice: initializes controls (evidence: `public/js/main.js`)
- Client Startup → Room Chat: initializes (evidence: `public/js/main.js`)
- Client Startup → SOS Relay UI: initializes (evidence: `public/js/main.js`)
- Client Startup → Device and Panels UI: uses panels (evidence: `public/js/main.js`)
- Client Startup → Room Profile: updates room (evidence: `public/js/main.js`)
- Socket Client → Live Map: updates markers (evidence: `public/js/socket.js`)
- Socket Client → Device and Panels UI: updates device list (evidence: `public/js/socket.js`)
- Socket Client → Room Chat: delivers messages (evidence: `public/js/socket.js`)
- Socket Client → WebRTC Voice: dispatches signaling (evidence: `public/js/socket.js`)
- Room Chat → Live Map: focuses marker (evidence: `public/js/chat.js`)
- WebRTC Voice → Socket Client: signals peers (evidence: `public/js/audio.js`)
- SOS Relay UI → Live Map: shows alert location (evidence: `public/js/sos.js`)
- Fleet Battery → Notifications: alerts (evidence: `public/js/batteryMonitor.js`)
- Fleet Battery → Socket Client: reads room state (evidence: `public/js/batteryMonitor.js`)
- Fleet Battery → Alert Sounds: plays alerts (evidence: `public/js/batteryMonitor.js`)
- Room Chat → Notifications: notifies activity (evidence: `public/js/chat.js`)
- Notifications → Alert Sounds: plays beep (evidence: `public/js/notification.js`)
- Live Map → Device Identity: renders device icons (evidence: `public/js/map.js`)
- Live Map → Shared Utilities: validates coordinates (evidence: `public/js/map.js`)
- Live Map → Client Configuration: uses map settings (evidence: `public/js/map.js`)
- Device and Panels UI → Live Map: focuses devices (evidence: `public/js/ui.js`)
- Offline PWA → Service Worker: registers caching
- Service Worker → Peer Browser: caches assets (evidence: `README.md`)
- Socket.IO Rooms → Peer Browser: relays room events (evidence: `README.md`)
