GeoSentinel tracks vessel movements in real time through a dedicated ais-relay microservice that maintains a persistent WebSocket connection to the AISStream global AIS feed. AIS (Automatic Identification System) is a transponder-based vessel identification and tracking system mandated for commercial ships above 300 GT by the IMO — it broadcasts position, speed, heading, vessel type, and identity on VHF radio every 2–10 seconds. The ais-relay is a FastAPI microservice running on port 8003 that normalizes incoming AIS frames into a typed vessel cache and serves bounding-box queries to the main GeoSentinel backend.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danizd/GeoSentinel/llms.txt
Use this file to discover all available pages before exploring further.
What AIS Is
AIS transponders broadcast VHF radio messages containing:- MMSI — Maritime Mobile Service Identity (9-digit vessel identifier)
- Position — latitude and longitude (WGS84)
- Speed Over Ground (SOG) — in knots
- Course Over Ground (COG) — in degrees
- True Heading — in degrees (0–360)
- Navigational Status — underway, anchored, moored, restricted maneuverability, etc.
- Ship Type — encoded as an ITU type code (cargo, tanker, passenger, military, etc.)
- Ship Name and Callsign — from static AIS messages
- Flag — derived from MMSI prefix (ITU country code mapping)
Architecture
AISSTREAM_API_KEY never leaves the relay. The main backend communicates with the relay over an internal HTTP API and never touches the AISStream WebSocket directly.
WebSocket Connection and Subscription
The relay connects towss://stream.aisstream.io/v0/stream and sends a subscription message containing the API key and a list of bounding boxes to subscribe to:
RECONNECT_BACKOFF_BASE and RECONNECT_BACKOFF_MAX).
Mock Fallback
IfAISSTREAM_API_KEY is not set or AISStream is unavailable, the relay falls back to serving mock vessel data. This allows the frontend to display vessel layer UI during development without a live AIS subscription.
Message Parsing
OnlyPositionReport and PositionReportInterval message types are processed. Each parsed vessel record is stored in the VesselStore indexed by MMSI:
| ITU code | Status string |
|---|---|
| 0 | under_way_using_engine |
| 1 | anchored |
| 2 | not_under_command |
| 3 | restricted_maneuverability |
| 4 | constrained_by_draught |
| 5 | moored |
| 6 | aground |
| 7 | engaged_in_fishing |
| 8 | under_way_sailing |
| 15 | not_defined |
Vessel Type Mapping
AIS ship type codes are mapped to named categories. Selected examples:| AIS type code | Vessel type string |
|---|---|
| 35 | military_ops |
| 51 | search_and_rescue |
| 52 | tug |
| 55 | law_enforcement |
| 60–69 | passenger |
| 70–79 | cargo |
| 80–89 | tanker |
Dark Ship Detection
A vessel is markedisDark=true if no AIS update has been received within the threshold window (default: 20 minutes):
DARK_SHIP_THRESHOLD_MIN environment variable (default 20) is configurable.
Querying Vessels by Bounding Box
The relay’s vessel list endpoint filters theVesselStore by geographic bounding box:
Frontend API Endpoint
The main backend exposes AIS data through:ThreadPoolExecutor with 8 workers, then deduplicates the aggregated vessel list by vessel id (MMSI-based). If the relay has not received any updates recently, the response includes:
X-Stale Header
The relay sets X-Stale: true in its response when the VesselStore has not received any update from the AISStream WebSocket within the cache TTL window. The ingestor logs a warning when it receives stale data and records stale_cache in source_refs for any events processed from it.
Relay Configuration
| Environment variable | Default | Description |
|---|---|---|
AISSTREAM_API_KEY | (empty) | AISStream API key — relay will use mock if unset |
AIS_RELAY_PORT | 8003 | Listening port for the relay HTTP server |
AIS_RELAY_URL | http://localhost:8003 | URL the main backend uses to reach the relay |
AIS_SOURCE | mock | Set to aisstream to enable live WebSocket |
DARK_SHIP_THRESHOLD_MIN | 20 | Minutes without update before isDark=true |
AISSTREAM_WS_URL | wss://stream.aisstream.io/v0/stream | AISStream WebSocket URL |
RECONNECT_BACKOFF_BASE | 2 | Initial reconnect delay in seconds |
RECONNECT_BACKOFF_MAX | 60 | Maximum reconnect delay in seconds |
AIS_SUBSCRIBE_BBOX | (empty) | JSON array of subscription bounding boxes |
Environment Variable Required
AISStream commercial plans are required for high-frequency production use. The free tier provides limited throughput. For GeoSentinel deployments serving multiple active AOIs simultaneously, verify your AISStream plan covers the message rate for your combined bounding box area.
