# something0412/spacecraft_telemetry_pipeline architecture

> Architecture diagram of the GitHub repository something0412/spacecraft_telemetry_pipeline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/something0412/spacecraft_telemetry_pipeline
- Repository: https://github.com/something0412/spacecraft_telemetry_pipeline

## Overview

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: [`frontend/src/api.ts`](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/api.ts) (API Client), [`server.py`](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py) (API Server), [`frontend/index.html`](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/index.html) (Dashboard UI), [`sc_simulator.py`](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/sc_simulator.py) (Random Walk)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_producer["Telemetry Producer"]
  node_sc_simulator["Simulator<br/>Python generator<br/>[sc_simulator.py]"]
  node_sim_model(("Random Walk<br/>signal model<br/>[sc_simulator.py]"))
  node_post_telemetry["POST ingest<br/>HTTP client<br/>[sc_simulator.py]"]
end

subgraph group_backend["Backend Service"]
  node_server["API Server<br/>FastAPI app<br/>[server.py]"]
  node_schema_validation["Validate<br/>Pydantic schema<br/>[server.py]"]
  node_anomaly_checks{{"Anomaly Check<br/>ingest rule<br/>[server.py]"}}
  node_telemetry_api["Telemetry API<br/>REST endpoints<br/>[server.py]"]
  node_sqlite_db[("Telemetry DB<br/>SQLite store<br/>[telemetry.db]")]
  node_record_model["Record Model<br/>telemetry schema<br/>[server.py]"]
end

subgraph group_frontend["Dashboard"]
  node_frontend_main["Main App<br/>TypeScript entry<br/>[main.ts]"]
  node_api_client["API Client<br/>HTTP client<br/>[api.ts]"]
  node_charts["Charts<br/>Chart.js layer<br/>[charts.ts]"]
  node_anomaly_banner{{"Alert Banner<br/>UI state<br/>[main.ts]"}}
  node_poll_loop(("Poll Loop<br/>refresh cycle<br/>[main.ts]"))
  node_frontend_ui["Dashboard UI<br/>Vite app<br/>[index.html]"]
end

node_sc_simulator -->|"generates"| node_sim_model
node_sim_model -->|"packages"| node_post_telemetry
node_post_telemetry -->|"POST /telemetry"| node_server
node_server -->|"validates"| node_schema_validation
node_schema_validation -->|"passes"| node_anomaly_checks
node_anomaly_checks -->|"classifies"| node_record_model
node_record_model -->|"stores"| node_sqlite_db
node_server -->|"serves"| node_telemetry_api
node_telemetry_api -->|"queries"| node_sqlite_db
node_frontend_ui -->|"bootstraps"| node_frontend_main
node_frontend_main -->|"drives"| node_poll_loop
node_poll_loop -->|"fetches"| node_api_client
node_api_client -->|"GET /telemetry"| node_telemetry_api
node_api_client -->|"updates"| node_charts
node_api_client -->|"flags"| node_anomaly_banner
node_charts -->|"renders"| node_frontend_ui
node_anomaly_banner -->|"alerts"| node_frontend_ui

click node_sc_simulator "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/sc_simulator.py"
click node_sim_model "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/sc_simulator.py"
click node_post_telemetry "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/sc_simulator.py"
click node_server "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py"
click node_schema_validation "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py"
click node_anomaly_checks "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py"
click node_telemetry_api "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py"
click node_sqlite_db "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/telemetry.db"
click node_record_model "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py"
click node_frontend_main "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/main.ts"
click node_api_client "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/api.ts"
click node_charts "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/charts.ts"
click node_anomaly_banner "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/main.ts"
click node_poll_loop "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/main.ts"
click node_frontend_ui "https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/index.html"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sc_simulator,node_sim_model,node_post_telemetry toneBlue
class node_server,node_schema_validation,node_anomaly_checks,node_telemetry_api,node_sqlite_db,node_record_model toneAmber
class node_frontend_main,node_api_client,node_charts,node_anomaly_banner,node_poll_loop,node_frontend_ui toneMint
```

## Components

### Telemetry Producer

Synthetic spacecraft telemetry generation and outbound posting

- [Simulator](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/sc_simulator.py): Python generator · Emits synthetic telemetry packets and posts them to the backend · `sc_simulator.py`
- [Random Walk](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/sc_simulator.py): signal model · Drives nominal sensor drift and occasional spikes · `sc_simulator.py`
- [POST ingest](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/sc_simulator.py): HTTP client · Outbound request path from simulator to backend ingest endpoint · `sc_simulator.py`

### Backend Service

FastAPI ingest, validation, anomaly classification, and query serving

- [API Server](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py): FastAPI app · Central ingest and query boundary for telemetry records · `server.py`
- [Validate](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py): Pydantic schema · Checks incoming telemetry packets before storage · `server.py`
- [Anomaly Check](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py): ingest rule · Marks out-of-bounds sensor readings as anomalous during ingest · `server.py`
- [Telemetry API](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py): REST endpoints · Exposes telemetry ingest and filtered history queries · `server.py`
- [Telemetry DB](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/telemetry.db): SQLite store · Persistent history and audit trail for accepted records · `telemetry.db`
- [Record Model](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/server.py): telemetry schema · Spacecraft id, timestamp, sensor readings, and anomaly flag · `server.py`

### Dashboard

Browser-based polling UI and chart rendering

- [Main App](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/main.ts): TypeScript entry · Starts the polling loop and coordinates UI updates · `frontend/src/main.ts`
- [API Client](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/api.ts): HTTP client · Fetches telemetry data and reshapes responses for the UI · `frontend/src/api.ts`
- [Charts](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/charts.ts): Chart.js layer · Creates charts and applies incremental updates from fresh telemetry · `frontend/src/charts.ts`
- [Alert Banner](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/main.ts): UI state · Shows a red warning when latest fetched telemetry is flagged anomalous · `frontend/src/main.ts`
- [Poll Loop](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/src/main.ts): refresh cycle · Refreshes the dashboard on a fixed interval · `frontend/src/main.ts`
- [Dashboard UI](https://github.com/something0412/spacecraft_telemetry_pipeline/blob/main/frontend/index.html): Vite app · Browser-based read-only visualization of telemetry history · `frontend/index.html`

## Connections

- 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
