A real-time device monitoring and IP tracking system built with Next.js, MongoDB, and Node.js.
- π₯οΈ 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
- Node.js 18+ and pnpm
- MongoDB (local or cloud)
- Environment variables configured
# 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 devThe server runs at http://localhost:3000 with auto-refresh.
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 changestracks-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
GET /api/devices- Fetch all active devices (deduplicated per deviceId)POST /api/register- Register a new devicePOST /api/heartbeat- Send device heartbeat (updates lastSeen)POST /api/update- Update device info
Validation Rules:
deviceIdandassignedEmployeeare requiredassignedEmployeecannot be "User" or empty- Devices with same
deviceIdare deduplicated; newest wins
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"
}'The laptop agent runs on client devices and sends periodic heartbeats.
cd laptop-agent
pnpm install
node agent.jsThe agent:
- Sends heartbeat every 30 seconds
- Auto-detects device hostname, local IP, and public IP
- Updates lastSeen timestamp
{
deviceId: String (unique, required),
assignedEmployee: String (required),
publicIP: String,
localIP: String,
location: String,
status: "Active" | "Inactive",
lastSeen: Date,
timestamps: { createdAt, updatedAt }
}# 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# 1. Build
pnpm build
# 2. Start production server
pnpm start- β Use environment variables for sensitive data
- β Validate all inputs on register/heartbeat endpoints
- β
Use unique indexes on
deviceIdto prevent duplicates - β Implement rate limiting on API endpoints (TODO)
- β Add authentication to admin routes (TODO)
- β HTTPS enforced in production
# Run linting
pnpm lint
# Fix linting issues
pnpm lint:fix
# Format code
pnpm format
# Check formatting
pnpm format:checkCI/CD: GitHub Actions runs lint, format checks, and builds on every push.
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)
MongooseError: Cannot connect to MongoDB
Fix:
- Check
MONGODB_URIin.env.local - Ensure MongoDB cluster is running and accessible
- Whitelist your IP in MongoDB Atlas
# Kill process on port 3000 (Windows)
netstat -ano | findstr :3000
taskkill /PID <PID> /F
# Linux/Mac
lsof -i :3000
kill -9 <PID>- Clone the repo
- Create a feature branch:
git checkout -b feature/amazing-feature - Run linting and format:
pnpm lint:fix && pnpm format - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
Code Style: ESLint + Prettier enforced via CI
This project is licensed under the MIT License.
For issues or questions:
- Open a GitHub issue
- Check existing issues for solutions
- Review the documentation above
Last Updated: March 2026
Status: β
Production Ready