How something0412/spacecraft_telemetry_pipeline works
1. System shape
- This repository implements a three-process telemetry pipeline: a Python simulator generates spacecraft readings, a FastAPI backend ingests and stores them, and a TypeScript dashboard reads them back for live visualization.
- The only integration path between components is HTTP; there is no message broker or streaming middleware.
2. Telemetry producer
- sc_simulator.py is the data source. It emits one telemetry packet per second and posts it to the backend’s POST /telemetry endpoint.
- The simulator uses a random-walk model for sensor values and occasionally injects out-of-bounds spikes to exercise anomaly detection.
3. Backend ingestion boundary
- server.py is the central control point. It validates incoming packets with Pydantic, applies anomaly checks at ingest time, and returns a success response only after the record is accepted.
- This is the main trust boundary: all data entering storage first passes through schema validation and nominal-range enforcement.
4. Stored data model
- The backend persists each telemetry record in telemetry.db, a local SQLite database created automatically on first run.
- Records include spacecraft identity, timestamp, sensor readings, and an anomaly flag, so the database serves both as a history log and as an audit trail.
5. Anomaly detection
- Anomaly detection is not a separate service; it is embedded in the ingest path.
- Readings outside the nominal sensor bounds for temperature, battery voltage, altitude, or attitude are marked anomalous immediately and stored that way.
6. Query path
- GET /telemetry exposes the historical data for retrieval.
- The endpoint supports filtering by spacecraft ID and time range, plus sort order and result limiting, which makes the database the source of truth for both recent and historical views.
7. Frontend dashboard
- The frontend/ package is a separate TypeScript application built with Vite and visualized with Chart.js.
- It is not server-rendered; it runs independently in the browser and pulls data from the backend API.
8. Live update model
- frontend/src/main.ts drives a polling loop that refreshes the dashboard every 2 seconds.
- frontend/src/api.ts handles API calls and data shaping, while frontend/src/charts.ts owns chart setup and incremental updates.
9. User-facing alerting
- The dashboard includes a red anomaly banner when the latest fetched telemetry contains flagged readings.
- That means the UI reflects backend-detected anomalies rather than re-deriving them locally.
10. Key architectural boundaries
- Backend responsibilities: validation, anomaly classification, persistence, and query serving.
- Frontend responsibilities: presentation and polling-based refresh.
- Simulator responsibilities: synthetic data generation and outbound POSTs.
- SQLite is the only persistent infrastructure, so the deployment model is lightweight and local rather than distributed.
11. Diagram cues
- Show the simulator as the sole writer of telemetry data, the FastAPI service as the ingest-and-query hub, and SQLite as the durable store behind it.
- Show the dashboard as a read-only consumer that polls the query endpoint and updates charts/alerts from the returned records.
Main entry points: api.ts API Client · server.py API Server · index.html Dashboard UI · sc_simulator.py Random Walk
Components 15
Telemetry Producer
Synthetic spacecraft telemetry generation and outbound posting
- Simulator · Emits synthetic telemetry packets and posts them to the backend
sc_simulator.py - Random Walk · Drives nominal sensor drift and occasional spikes
sc_simulator.py - POST ingest · Outbound request path from simulator to backend ingest endpoint
sc_simulator.py
Backend Service
FastAPI ingest, validation, anomaly classification, and query serving
- API Server · Central ingest and query boundary for telemetry records
server.py - Validate · Checks incoming telemetry packets before storage
server.py - Anomaly Check · Marks out-of-bounds sensor readings as anomalous during ingest
server.py - Telemetry API · Exposes telemetry ingest and filtered history queries
server.py - Telemetry DB · Persistent history and audit trail for accepted records
telemetry.db - Record Model · Spacecraft id, timestamp, sensor readings, and anomaly flag
server.py
Dashboard
Browser-based polling UI and chart rendering
- Main App · Starts the polling loop and coordinates UI updates
frontend/src/main.ts - API Client · Fetches telemetry data and reshapes responses for the UI
frontend/src/api.ts - Charts · Creates charts and applies incremental updates from fresh telemetry
frontend/src/charts.ts - Alert Banner · Shows a red warning when latest fetched telemetry is flagged anomalous
frontend/src/main.ts - Poll Loop · Refreshes the dashboard on a fixed interval
frontend/src/main.ts - Dashboard UI · Browser-based read-only visualization of telemetry history
frontend/index.html
Connections 17
- Simulator → Random Walk: generates · Produces synthetic readings from a random-walk source
- Random Walk → POST ingest: packages · Turns simulated sensor values into telemetry packets
- POST ingest → API Server: POST /telemetry · Sends telemetry records to the backend ingest endpoint
- API Server → Validate: validates · Rejects malformed packets before any persistence step
- Validate → Anomaly Check: passes · Only schema-accepted packets proceed to ingest rules
- Anomaly Check → Record Model: classifies · Attaches anomaly status to the telemetry record
- Record Model → Telemetry DB: stores · Persists accepted telemetry as durable history
- API Server → Telemetry API: serves · Implements ingest and query endpoints
- Telemetry API → Telemetry DB: queries · Reads historical telemetry with filters and limits
- Dashboard UI → Main App: bootstraps · Loads the browser application entry point
- Main App → Poll Loop: drives · Runs periodic refreshes every two seconds
- Poll Loop → API Client: fetches · Requests the latest telemetry history from the backend
- API Client → Telemetry API: GET /telemetry · Reads telemetry data through the query endpoint
- API Client → Charts: updates · Shapes fetched data for chart refreshes
- API Client → Alert Banner: flags · Surfaces backend-detected anomaly state to the UI
- Charts → Dashboard UI: renders · Displays live telemetry charts in the browser
- Alert Banner → Dashboard UI: alerts · Shows a visible warning when recent telemetry is anomalous