A full-stack web application designed to manage customer orders and fully automate their status transitions using a background scheduling system.
- Frontend: https://order-tracking-81rw.vercel.app
- Backend API:
https://order-tracking-silk.vercel.app/api
- Database: MongoDB (Atlas)
- Why: Selected for its highly flexible, NoSQL document structure that pairs seamlessly with Node.js/Express. Native JSON-like documents enable rapid development and easy horizontal scaling in a serverless environment.
To ensure robust system design and performance, the data is normalized across three distinct collections rather than utilizing a fixed, generic schema:
orders: Stores the primary customer data, product details, and the current state of the order. Enforces strict business logic via Mongoose enums (PLACED,PROCESSING,READY_TO_SHIP).orderstatushistories: An append-only audit log. Instead of storing massive arrays inside the main order document, history is stored here and linked viaorderIdto ensure the mainorderscollection remains performant.schedulerlogs: Tracks the execution history of the background cron job for diagnostic purposes.
- Duplicates: Handled via UI locking (disabling submit buttons during network requests) and MongoDB's mathematical enforcement of unique
_idvalues. - Race Conditions: Mitigated using Idempotent Logic. Before the scheduler transitions an order, it explicitly queries the
timeSinceLastUpdateand the current status. Node.js's single-threaded event loop ensures synchronous processing within a single execution block.
- Scheduler: HTTP-Triggered architecture pinged via an external cron service (cron-job.org).
- Why: Traditional
node-cronlibraries fail in Serverless environments (like Vercel) because the server sleeps when inactive. Exposing a secure endpoint (/api/scheduler/run) authenticated by anx-scheduler-secretheader is the industry standard for serverless task scheduling.
The system is built on a stateless Serverless Architecture. It relies on Vercel Edge networks for instant compute scaling and MongoDB Atlas for distributed database scaling. Serverless database connections are explicitly cached to prevent connection pool exhaustion during warm-starts.
- Frontend: React, Vite, CSS (Glassmorphism UI), Lucide Icons
- Features: Real-time data fetching, Interactive Status Timeline Modal, Scheduler Execution Dashboard.
- Backend: Node.js, Express.js, Mongoose
- Database: MongoDB
- Deployment: Vercel (Serverless Functions)
git clone https://github.com/Prajwal00300/Order-Tracking
cd order-trackingcd backend
npm installCreate a .env file in the backend directory:
PORT=8000
MONGODB_URI=your_mongodb_atlas_connection_string
SCHEDULER_SECRET=your_scheduler_secret Start the backend server:
npm run devOpen a new terminal and navigate to the frontend:
cd frontend
npm installEnsure src/config.js points to your local backend (http://localhost:8000/api).
Start the frontend development server:
npm run devGET /api/orders- Fetch all orders (Supports pagination?page=1&limit=10and search?search=name)POST /api/orders- Create a new orderPUT /api/orders/:id- Update an existing orderDELETE /api/orders/:id- Delete an orderGET /api/orders/:id/history- Get the status transition history (timeline) of a specific order
POST /api/scheduler/run- Manually trigger the status update logic (Requires Header:x-scheduler-secret)GET /api/scheduler/logs- Fetch the execution logs of the scheduler (Supports pagination)