# harsh-codes-77/real_time_location_tracker architecture

> Architecture diagram of the GitHub repository harsh-codes-77/real_time_location_tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harsh-codes-77/real_time_location_tracker
- Repository: https://github.com/harsh-codes-77/real_time_location_tracker

## Overview

##### Project type and purpose
- This is a lightweight full-stack web application for real-time geolocation tracking.
- The server (Node.js + Express) serves a single page with an embedded map. Clients emit their GPS coords via Socket.io and receive broadcasts of everyone’s locations.

##### File structure
- app.js – the Express entry point, initializes HTTP server and Socket.io
- package.json / package-lock.json – Node dependencies (express, ejs, socket.io)
- node_modules – installed libraries
- views/index.ejs – server-side template for the HTML page with the map container
- public/css/style.css – styling for the map page
- public/js/script.js – client script:
– checks geolocation support and calls watchPosition()
– emits “send-location” with { latitude, longitude }
– listens for incoming location events, updates Leaflet markers
- public/js – any other client scripts or libraries you might add

##### Pulling insights from the README
- Uses Leaflet + OpenStreetMap tiles for map rendering
- Relies on browser Geolocation API (high accuracy, 5s timeout)
- Emits location changes over a Socket.io channel
- Server re-broadcasts to all connected clients
- Markers are kept in an in-memory JS object and removed on disconnect

– Blue for client-side components
– Green for server-side components
– Gray for external services

##### Detail
- Lifecycle events: connect, send-location, receive-location, disconnect

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Browser"
        direction TB
        GeoAPI["Geolocation API"]:::client
        Leaflet["Leaflet Map UI\n(Leaflet + OSM Tiles)"]:::client
        SocketClient["Socket.io Client"]:::client
        CSS["Client CSS Styling\n(style.css)"]:::client
        Script["Client Script\n(script.js)"]:::client
    end

    %% Server Layer
    subgraph "Node.js Server"
        direction TB
        HttpServer["Express HTTP Server\n(port 3000)"]:::server
        EJS["EJS View Engine\n(index.ejs)"]:::server
        SocketServer["Socket.io Server"]:::server
        Markers["In-memory Markers Store"]:::server
    end

    %% External Services
    subgraph "External Services"
        direction TB
        OSM["OpenStreetMap Tile Server"]:::external
        README["Project Documentation\n(README.md)"]:::legend
    end

    %% Legend
    subgraph "Legend"
        direction TB
        L1["Blue = Client-side"]:::legend
        L2["Green = Server-side"]:::legend
        L3["Gray = External Service"]:::legend
        L4["-->|HTTP GET|"]:::legend
        L5["-->|WebSocket|"]:::legend
    end

    %% Data Flows
    HttpServer -->|"Renders index.ejs"| EJS
    EJS -->|"Delivers HTML"| GeoAPI
    EJS -->|"Delivers CSS"| CSS
    EJS -->|"Delivers JS"| Script

    Script -->|"Socket.io handshake"| SocketServer
    Script -->|"send-location (WebSocket)"| SocketServer
    SocketServer -->|"receive-location (WebSocket)"| Script

    GeoAPI -->|"watchPosition() data"| Script
    Script -->|"update markers"| Leaflet

    Leaflet -->|"Tile HTTP GET"| OSM

    %% Click Events
    click HttpServer "https://github.com/harsh-codes-77/real_time_location_tracker/blob/main/app.js"
    click EJS "https://github.com/harsh-codes-77/real_time_location_tracker/blob/main/views/index.ejs"
    click Script "https://github.com/harsh-codes-77/real_time_location_tracker/blob/main/public/js/script.js"
    click CSS "https://github.com/harsh-codes-77/real_time_location_tracker/blob/main/public/css/style.css"
    click README "https://github.com/harsh-codes-77/real_time_location_tracker/blob/main/README.md"
    click HttpServer "https://github.com/harsh-codes-77/real_time_location_tracker/blob/main/package.json"
    click HttpServer "https://github.com/harsh-codes-77/real_time_location_tracker/blob/main/package-lock.json"
    click HttpServer "https://github.com/harsh-codes-77/real_time_location_tracker/tree/main/node_modules"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef server fill:#A9DFBF,stroke:#196F3D,color:#145A32
    classDef external fill:#D5D8DC,stroke:#5D6D7E,color:#2C3E50
    classDef legend fill:#F8F9F9,stroke:#ABB2B9,color:#616A6B
```
