Skip to content

pranj4/location-tracking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Location Tracking System

Project Overview

This project is a real-time location tracking system designed to handle live GPS data from multiple users. The system includes a backend for processing location data and a frontend for displaying the information on an interactive map. The backend can scale to handle at least 500 simultaneous users.

Features

  • User Authentication: Secure login and access control using tokens
  • Real-Time Tracking: Periodic updates of user locations sent to the server
  • Filterable Map: View and filter location logs on an interactive map
  • Scalability: Designed to support high concurrency

Tech Stack

Backend

  • Node.js
  • Express.js
  • PostgreSql
  • MongoDB (with Mongoose)

Frontend

  • HTML, CSS, JavaScript
  • Leaflet.js (for map rendering)

Deployment

  • GitHub (version control)

System Architecture

Frontend

  • Displays real-time user locations on a map
  • Allows filtering by user and date range

Backend

  • Processes and stores user location data
  • Serves location logs to authorized clients

Database

  • Stores user details and location logs
  • Redis Cache optimizes frequent read operations

Usage

Log in using your credentials.

Start location tracking using the "Start Tracking" button.

View real-time locations and logs on the map.

Filter logs by user and date range.

Setup Instructions

1. Clone the Repository

git clone https://github.com/pranj4/location-tracking.git
cd location-tracking

2. Install Dependencies

npm install

3. Configure Environment Variables

Create a .env file and add the following:

DB_HOST=localhost
DB_PORT=5432
DB_NAME=tracking
DB_USER=postgres
DB_PASSWORD=iamgame25...
MONGO_URI=mongodb://localhost:27017/tracking_db
JWT_SECRET=password

4. Run the Backend Server

npm run dev

5. Database Setup

PostgreSQL

# Create database
CREATE DATABASE locationtracker;

# Create users table
CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    password VARCHAR(255) NOT NULL,
    role VARCHAR(50) DEFAULT 'user'
);

image

MongoDB

Ensure MongoDB is running Collections will be created automatically

image

6. Access the Frontend by going to register page and registering

Open http://localhost:3000/register.html in any browser.

A basic registration page has been set up

image

Register as new user or if already registered . Click on login here

image

Workflows

User Workflow

-Sign Up / Log In

The user registers an account or logs into the system using their credentials.

image

Start Tracking

Once authenticated, the user starts tracking their live location by enabling GPS on their device.

The location is periodically sent to the backend.

image

Stop Tracking

The user can stop tracking their location at any time.

Admin Workflow

Admin Log In

The admin logs in using an authorized account with elevated privileges.

image

View All User Locations

The admin accesses a dashboard displaying all active users and their live locations.

image

image

Apply Filters

The admin filters user data by date, username, or specific regions on the map.

##API Endpoints

Authentication

POST /api/auth/register - User registration
POST /api/auth/login - User login

Location

POST /api/location/track - Send live location
GET /api/location/logs/:userId - Fetch user location logs
GET /api/location/location-logs - Admin: Fetch all location logs

Security Features

-JWT-based authentication -Password hashing -Role-based access control -Input validation -Secure API endpoints

Scalability Enhancements

  • Implement database indexing

  • Use connection pooling

  • Optimize query performance

Cloud Deployment

Supported Platforms:

AWS Elastic Beanstalk

Heroku

Vercel

Performance Optimization

  • Implemented connection pooling

  • Efficient database indexing

  • Minimal payload transfer

  • Integrated logging middleware

  • Error tracking

Acknowledgements

  • Leaflet.js
  • Express.js
  • PostgreSQL
  • MongoDB

Troubleshooting

  • Ensure all environment variables are correctly set
  • Check network configurations
  • Verify database connections
  • Review authentication middleware
  • Check browser console for frontend errors

About

Location tracking for multiple clients at once

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published