Ahmed Codes

Building a Real-Time Freight Train Tracker with MERN and Socket.IO

By Ahmed Sulaimon2024-12-07

In this project, I led the development of a real-time train tracking application using the MERN stack, Leaflet.js, and Socket.IO. The goal was to provide users with live updates of train journeys on a map of the UK rail network, allowing them to search, view, and interact with rich data such as journey status, delays, and timing breakdowns.


Tech Stack Overview


Core Features


The Development Process

We followed an Agile methodology with Kanban for planning and weekly stand-ups. As Scrum Master, I was responsible for:

We also used the SHU development process, applying techniques like:


Technical Highlights

1. Integrating Leaflet.js with MERN

We used Leaflet.js to visualize live train routes on a schematic map. Real-time data was streamed from the backend using Socket.IO and rendered using polylines.

L.polyline(trainCoords, {
  color: getPolylineColor(train.status)
}).addTo(map);

2. Secure API Access with Environment Variables

API keys were managed securely using .env files and ignored in Git using .gitignore, preventing accidental exposure.

3. Data Validation & UI Feedback

Robust handling of inconsistent API responses (e.g., missing fields) ensured the app remained stable. Popups were dynamically populated and adapted for incomplete journeys.


Feedback & Iteration

During the client demonstration, the following areas for improvement were identified:

We created a post-demo action plan to address these items in the next sprint.


What I’d Improve

If I were to approach this again, I’d:


What I Learned

This project helped sharpen both my technical and soft skills:


Conclusion

The freight train tracker was a rich, collaborative project that tackled real-world challenges—like live data handling, security, and responsive UI. By combining modern tools and structured agile development, we delivered a functional and well-received application.