Skip to content

akshayweb18/tracks-ip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎯 Tracks IP - Device Monitoring Dashboard

A real-time device monitoring and IP tracking system built with Next.js, MongoDB, and Node.js.

✨ Features

  • πŸ–₯️ Real-time Device Monitoring - Track active/inactive devices with live status
  • πŸ“Š Dashboard - View employee devices, IPs, and connection status
  • πŸ”„ Auto Refresh - Devices update every 10 seconds
  • πŸ” Secure Registration - Upsert-based device registration to prevent duplicates
  • πŸ“± Responsive Design - Works on desktop and mobile with Tailwind CSS
  • 🎨 Modern UI - Built with Shadcn/UI and Radix components

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and pnpm
  • MongoDB (local or cloud)
  • Environment variables configured

Installation

# 1. Clone the repository
git clone <repo-url>
cd tracks-ip

# 2. Install dependencies
pnpm install

# 3. Create .env.local file
cat > .env.local << EOF
MONGODB_URI=mongodb+srv://<user>:<password>@<cluster>.mongodb.net/tracks-ip
NEXT_PUBLIC_API_URL=http://localhost:3000
EOF

# 4. Start development server
pnpm dev

The server runs at http://localhost:3000 with auto-refresh.

πŸ“‹ Available Scripts

pnpm dev              # Start development server (includes heartbeat)
pnpm build            # Build for production
pnpm start            # Start production server
pnpm heartbeat        # Run heartbeat agent standalone
pnpm lint             # Run ESLint checks
pnpm lint:fix         # Auto-fix linting issues
pnpm format           # Format code with Prettier
pnpm format:check     # Check formatting without changes

πŸ—οΈ Project Structure

tracks-ip/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/              # Next.js app router
β”‚   β”‚   β”œβ”€β”€ api/          # API routes
β”‚   β”‚   β”œβ”€β”€ devices/      # Device pages
β”‚   β”‚   └── login/        # Admin pages
β”‚   β”œβ”€β”€ components/       # React components
β”‚   β”œβ”€β”€ lib/              # Utilities (db, deviceStatus, utils)
β”‚   β”œβ”€β”€ models/           # Mongoose schemas
β”‚   └── middleware.js     # Auth middleware
β”œβ”€β”€ laptop-agent/         # Laptop heartbeat agent
β”œβ”€β”€ public/               # Static assets
β”œβ”€β”€ .github/workflows/    # CI/CD pipelines
β”œβ”€β”€ package.json
└── next.config.mjs

πŸ”Œ API Endpoints

Devices

  • GET /api/devices - Fetch all active devices (deduplicated per deviceId)
  • POST /api/register - Register a new device
  • POST /api/heartbeat - Send device heartbeat (updates lastSeen)
  • POST /api/update - Update device info

Validation Rules:

  • deviceId and assignedEmployee are required
  • assignedEmployee cannot be "User" or empty
  • Devices with same deviceId are deduplicated; newest wins

πŸ‘€ Device Registration Example

curl -X POST http://localhost:3000/api/register \
  -H "Content-Type: application/json" \
  -d '{
    "deviceId": "<YOUR_DEVICE_ID>",
    "assignedEmployee": "John Doe",
    "publicIP": "203.0.113.1",
    "localIP": "192.168.1.100",
    "location": "Office"
  }'

πŸ’» Laptop Agent

The laptop agent runs on client devices and sends periodic heartbeats.

cd laptop-agent
pnpm install
node agent.js

The agent:

  • Sends heartbeat every 30 seconds
  • Auto-detects device hostname, local IP, and public IP
  • Updates lastSeen timestamp

πŸ“¦ Database Models

Device Schema

{
  deviceId: String (unique, required),
  assignedEmployee: String (required),
  publicIP: String,
  localIP: String,
  location: String,
  status: "Active" | "Inactive",
  lastSeen: Date,
  timestamps: { createdAt, updatedAt }
}

πŸš€ Deployment

Vercel (Recommended)

# 1. Push to GitHub
git push origin main

# 2. Connect to Vercel
# - Go to vercel.com β†’ Import Project
# - Select your repository
# - Configure environment variables
# - Deploy

# 3. Set environment variables in Vercel:
# MONGODB_URI=mongodb+srv://<user>:<password>@<cluster>.mongodb.net/tracks-ip

Manual Deployment

# 1. Build
pnpm build

# 2. Start production server
pnpm start

πŸ”’ Security Best Practices

  • βœ… Use environment variables for sensitive data
  • βœ… Validate all inputs on register/heartbeat endpoints
  • βœ… Use unique indexes on deviceId to prevent duplicates
  • βœ… Implement rate limiting on API endpoints (TODO)
  • βœ… Add authentication to admin routes (TODO)
  • βœ… HTTPS enforced in production

πŸ§ͺ Testing & Quality

# Run linting
pnpm lint

# Fix linting issues
pnpm lint:fix

# Format code
pnpm format

# Check formatting
pnpm format:check

CI/CD: GitHub Actions runs lint, format checks, and builds on every push.

πŸ› Troubleshooting

Duplicate Devices Appearing

Issue: Same device appears multiple times in the dashboard.

Fix: The /api/devices endpoint now deduplicates by deviceId and filters out invalid records:

  • Ensures only the most recent device record per ID is shown
  • Filters out records with missing/invalid assignedEmployee
  • Requires valid employee name (not "User" or empty)

MongoDB Connection Error

MongooseError: Cannot connect to MongoDB

Fix:

  1. Check MONGODB_URI in .env.local
  2. Ensure MongoDB cluster is running and accessible
  3. Whitelist your IP in MongoDB Atlas

Port Already in Use

# Kill process on port 3000 (Windows)
netstat -ano | findstr :3000
taskkill /PID <PID> /F

# Linux/Mac
lsof -i :3000
kill -9 <PID>

πŸ“ Contributing

  1. Clone the repo
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Run linting and format: pnpm lint:fix && pnpm format
  4. Commit changes: git commit -m 'Add amazing feature'
  5. Push to branch: git push origin feature/amazing-feature
  6. Open a Pull Request

Code Style: ESLint + Prettier enforced via CI

πŸ“„ License

This project is licensed under the MIT License.

πŸ“ž Support

For issues or questions:

  • Open a GitHub issue
  • Check existing issues for solutions
  • Review the documentation above

Last Updated: March 2026
Status: βœ… Production Ready

About

No description, website, or topics provided.

Resources

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors