How meetmendapara09/tracking_app works
Purpose and Runtime Shape
Real-Time Delivery Tracker is a two-process application: a Next.js frontend for customers and delivery personnel, and an Express + Socket.IO backend for order, location, and delivery updates. Root development entry is scripts/dev-all.js; frontend starts from src/app/page.tsx; backend boots through backend/src/index.ts and assembles middleware/routes in backend/src/app.ts.
Frontend Application
The Next.js App Router provides role-oriented flows:
• Customer tracking route: src/app/customer/track/[orderId]/page.tsx
• Delivery login and dashboard: src/app/delivery/login/page.tsx, src/app/delivery/dashboard/page.tsx
• Shared application shell and visual components: src/app/layout.tsx, src/app/components/AntLayout.tsx, src/app/components/Map.tsx
Ant Design is the primary UI framework. The frontend is a browser client rather than an API host.
Client API and Realtime Boundary
Frontend HTTP calls are centralized in src/app/lib/api.ts; Socket.IO client setup is in src/app/lib/socket.ts and consumed through src/app/hooks/useSocket.ts. Authentication state is handled by src/app/hooks/useAuth.ts and src/app/utils/auth.ts. This layer bridges browser UI state to backend REST endpoints and live location/order events.
Backend HTTP and Authentication Pipeline
Express controllers expose domain operations through route modules:
• API and delivery operations: backend/src/routes/apiRoutes.ts, backend/src/controllers/apiController.ts, backend/src/controllers/deliveryController.ts
• Authentication: backend/src/routes/authRoutes.ts, backend/src/controllers/authController.ts
• Orders and locations: backend/src/routes/orderRoutes.ts, backend/src/routes/locationRoutes.ts
Requests pass authentication and validation boundaries in backend/src/middleware/auth.ts and backend/src/middleware/validators.ts before controller logic. An OpenAPI contract is published at backend/openapi.json.
Domain and Persistence
The core persisted entities are users, orders, and location records, represented by backend/src/models/User.ts, backend/src/models/Order.ts, and backend/src/models/Location.ts. The repository retains MongoDB-oriented data access through backend/src/services/db.ts, while PostgreSQL/PostGIS support is represented by Prisma configuration in backend/prisma/schema.prisma and backend/src/services/prisma.ts. Migration paths are explicit in backend/scripts/migrate-mongo-to-postgres.ts and backend/scripts/enable-postgis.ts.
Live Location Processing
Socket.IO is hosted alongside the Express backend from backend/src/index.ts. Location-specific HTTP handling resides in backend/src/controllers/locationController.ts; asynchronous/background processing is isolated in backend/src/workers/locationWorker.ts. This boundary supports ingesting courier location updates, persisting or processing them, and broadcasting delivery-tracking state to subscribed clients.
Operations, Observability, and Deployment
The backend can run containerized via backend/Dockerfile and backend/docker-compose.yml. Prometheus metrics are exposed from backend/src/metrics.ts, with database and Bull-related metric collectors in backend/src/metrics/postgres_stats.ts and backend/src/metrics/bull_poll.ts. OpenTelemetry and Sentry integrations are isolated in backend/src/services/opentelemetry.ts and backend/src/services/sentry.ts; Grafana/Prometheus local monitoring assets live under backend/grafana and backend/prometheus/prometheus.yml. Kubernetes deployment is packaged as Helm resources under deploy/helm/tracking-app/templates/deployment.yaml, deploy/helm/tracking-app/templates/service.yaml, and deploy/helm/tracking-app/templates/ingress.yaml.
Main entry points: index.ts Backend bootstrap · auth.ts Auth & validation · layout.tsx App shell & UI · page.tsx Customer tracking
Components 21
Next.js Frontend
- App shell & UI
src/app/layout.tsx - Customer tracking
src/app/customer/track/[orderId]/page.tsx - Delivery dashboard
src/app/delivery/dashboard/page.tsx - HTTP client
src/app/lib/api.ts - Realtime client · Socket setup consumed by the client hook.
src/app/lib/socket.ts
Express + Socket.IO Backend
- Backend bootstrap
backend/src/index.ts - Express app
backend/src/app.ts - Domain API routes
backend/src/routes/apiRoutes.ts - Authentication routes
backend/src/routes/authRoutes.ts - Auth & validation
backend/src/middleware/auth.ts - Order & delivery logic
backend/src/controllers/apiController.ts - Location ingest
backend/src/controllers/locationController.ts - OpenAPI contract
backend/openapi.json
Data & Processing
- Location worker
backend/src/workers/locationWorker.ts - Domain entities · Users, orders, and locations.
backend/src/models/Order.ts - MongoDB access
backend/src/services/db.ts - PostgreSQL / PostGIS
backend/prisma/schema.prisma
Operations
- Metrics & telemetry · Prometheus metrics plus OpenTelemetry and Sentry integrations.
backend/src/metrics.ts - Container runtime
backend/docker-compose.yml - Kubernetes deployment
deploy/helm/tracking-app/templates/deployment.yaml
Other components
- Dev launcher · Starts both application processes.
scripts/dev-all.js
Connections 27
- Dev launcher → App shell & UI: starts frontend
- Dev launcher → Backend bootstrap: starts backend
- App shell & UI → Customer tracking: renders route
- App shell & UI → Delivery dashboard: renders route
- Customer tracking → HTTP client: queries order state
- Delivery dashboard → HTTP client: uses REST operations
- Customer tracking → Realtime client: subscribes to updates
- Delivery dashboard → Realtime client: publishes live location
- HTTP client → Backend bootstrap: HTTP
- Realtime client → Backend bootstrap: Socket.IO
- Backend bootstrap → Express app: hosts
- Express app → Domain API routes: mounts
- Express app → Authentication routes: mounts
- Domain API routes → Auth & validation: passes through
- Authentication routes → Auth & validation: protects requests
- Auth & validation → Order & delivery logic: authorizes
- Auth & validation → Location ingest: validates ingest
- Order & delivery logic → Domain entities: reads and writes
- Location ingest → Location worker: queues processing
- Location worker → Domain entities: persists locations
- Domain entities → MongoDB access: accesses
- Order & delivery logic → PostgreSQL / PostGIS: supports Prisma storage
- Location worker → Backend bootstrap: broadcasts tracking state
- Backend bootstrap → OpenAPI contract: publishes contract
- Backend bootstrap → Metrics & telemetry: emits metrics and telemetry
- Container runtime → Backend bootstrap: runs
- Kubernetes deployment → Container runtime: deploys image