This repository provides the backend for an interview exercise where a candidate builds a web frontend.
The expected frontend should include:
- The frontend should be built in the
fefolder of this - Using
ReactwithTypeScript - Map view that plots planes in real time. Possible options could be e.g.
MapLibre,MapBox,Leafletor any other map engine provider of your choice. - Planes can be selected/unselected to show/hide detailed information
- Consumes flight data exclusively from the provided WebSocket backend
- Node.js 18+
- npm
cd be
npm install
npm run devThe server listens at ws://localhost:4000 by default.
Create be/.env by copying the be/.env.example file:
PORT=4000
PLANES_COUNT=20
BASIC_UPDATE_INTERVAL_MS=1000
DETAILED_UPDATE_INTERVAL_MS=1000PORT: WebSocket server portPLANES_COUNT: Number of simulated planesBASIC_UPDATE_INTERVAL_MS: Basic data broadcast interval (ms)DETAILED_UPDATE_INTERVAL_MS: Detailed data interval (ms)
The server sends this response on ever configured BASIC_UPDATE_INTERVAL_MS.
{
"type": "planes",
"data": [
{
"id": "plane-1",
"latitude": 45.1234,
"longitude": -75.5678,
"altitude": 10668,
"color": "#FF6B6B"
}
]
}In order to receive detailed plane information, the client must subscribe by sending the request:
{
"type": "subscribe",
"planeId": "plane-1"
}When subscribed, the server will send the following response:
{
"type": "plane-details",
"data": {
"id": "plane-1",
"model": "Boeing 737",
"airline": "Airline Name",
"flightNumber": "AA123",
"registration": "N12345",
"latitude": 45.1234,
"longitude": -75.5678,
"altitude": 10668,
"speed": 283,
"heading": 180,
"verticalSpeed": 0,
"origin": { "airport": "JFK", "city": "New York" },
"destination": { "airport": "LAX", "city": "Los Angeles" },
"flightDuration": 125,
"estimatedArrival": 3600,
"numberOfPassengers": 180,
"maxPassengers": 200,
"status": "cruising",
"color": "#FF6B6B"
}
}The server sends this response on ever configured DETAILED_UPDATE_INTERVAL_MS
{
"type": "error",
"message": "Plane plane-1 not found"
}{
"type": "error",
"message": "Invalid message format. Expected { type: 'subscribe', planeId: string }"
}{
"type": "error",
"message": "Invalid JSON message"
}- Send a
subscribemessage after connecting. - Send a new
subscribeto switch planes. - Invalid plane IDs close the connection (code 1008) after an error message.
- Initial plane data (basic) is sent immediately, then updates at the configured interval.
These are the data models returned by the backend:
type PlaneBasic = {
id: string;
latitude: number;
longitude: number;
altitude: number;
color: string;
};
type PlaneDetailed = {
id: string;
model: string;
airline: string;
flightNumber: string;
registration: string;
latitude: number;
longitude: number;
altitude: number;
speed: number;
heading: number;
verticalSpeed: number;
origin: {
airport: string;
city: string
};
destination: {
airport: string;
city: string
};
flightDuration: number;
estimatedArrival: number;
numberOfPassengers: number;
maxPassengers: number;
status: "departed" | "enroute" | "cruising" | "landing";
color: string;
};