-
Notifications
You must be signed in to change notification settings - Fork 0
System Architecture
Sofia Engine is engineered as an offline-first, modular edge runtime for industrial telemetry, condition monitoring, digital signal processing (DSP), and safe technical automation. This document describes the runtime components, data flows, dependency constraints, and failure containment mechanisms.
The runtime consists of six strictly decoupled layers:
SOFIA ENGINE
|
+-----------------------+
| Engine Runtime |
| (edge/runtime.py) |
+-----------------------+
|
+-------------------------------+-------------------------------+
| | |
TELEMETRY LAYER SIGNAL PIPELINE MODEL RUNTIME
telemetry/ signal/ + features/ inference/
| | |
TelemetrySource (ABC) windowing ModelBackend (ABC)
|- CsvSource filters |- ThresholdDetector
|- JsonlSource resample |- ZScoreDetector
|- SyntheticSource detrend |- MadDetector
|- ReplaySource envelope |- EwmaDetector
|- MqttSource [extra] spectral |- CusumDetector
|- ModbusSource [extra] ----- |- OnnxBackend [extra]
|- SerialSource [extra] statistical features |- TorchBackend [extra]
|- registry (plugins) spectral features |- registry (plugins)
| rotating-machinery ext |
| | |
+-------------------------------+----------------------------+
|
DECISION ENGINE
diagnostics/ + decision/
|
evidence -> severity -> confidence -> uncertainty
|
+-----------+-----------+
| |
HealthEvent CommandRequest
| |
| PolicyEngine
| (default DENY)
| |
| +--------+--------+
| DENY APPROVE
| | |
v v v
+-------------------+---------------+-----------------+----------------+
| | | |
API CLI Observability Edge runtime
(FastAPI extra) cli/main.py observability/ edge/{buffer,
| | logging, metrics, store_forward,
| | health reconnect}
| | |
+-------------------+----------------------------------------------------+
|
Embedded Export
embedded/ (C99 reference runtime,
fixed-point Q16.16, golden vectors)
All telemetry samples, signal windows, feature vectors, inference results, and command requests use strongly typed dataclasses defined in sofia_ai.core.contracts:
-
TelemetrySample:-
timestamp: float(wall-clock event time in seconds) -
device_id: str(unique asset identifier) -
channel: str(sensor channel, e.g.vibration_x) -
value: float(physical measurement, validated$\notin {\text{NaN}, \pm\infty}$ ) -
unit: str(physical unit, e.g.g,mm/s,RPM) -
quality: DataQuality(GOOD,STALE,MISSING,INVALID,OUT_OF_RANGE,DUPLICATE) -
sequence_number: int(monotonic counter for replay detection) -
ingestion_time: float(local monotonic processing timestamp)
-
-
SignalWindow:- Fixed-length array of contiguous samples aligned by index, carrying sample rate
$f_s$ , start timestamp, and quality mask.
- Fixed-length array of contiguous samples aligned by index, carrying sample rate
-
FeatureVector:- Named, ordered vector of physical and spectral metrics (deterministic tuple ordering, never derived from dictionary key order).
- Carries
extractor_idand semanticextractor_version.
-
InferenceResult:- Carries
model_id,model_version, anomaly classification outcome (NORMAL,ANOMALY), numericscore,confidence$\in [0, 1]$ , anduncertainty$\in [0, 1]$ .
- Carries
-
HealthEvent:- Produced by the
DiagnosticEngine. Maps evidence, severity (NORMAL,LOW,MEDIUM,HIGH,CRITICAL), confidence, and human-readable recommendations.
- Produced by the
-
CommandRequest/CommandDecision:- Formal actuation intents evaluated by the
PolicyEngine.
- Formal actuation intents evaluated by the
Sofia enforces strict architectural isolation via automated AST checks in tests/architecture/test_boundaries.py:
| Module | Purpose | Allowed Imports | Forbidden Imports |
|---|---|---|---|
core/ |
Contracts, units, time, quality, errors |
stdlib, numpy
|
Any other Sofia module, any protocol, any ML framework |
signal/ |
Pure DSP algorithms |
core, numpy
|
telemetry, inference, torch, onnxruntime
|
features/ |
Feature extraction |
core, signal, numpy
|
inference, decision, telemetry
|
inference/ |
Detectors & ML backends |
core, features, security
|
telemetry, decision, copilot
|
diagnostics/ |
Evidence fusion & health scoring |
core, features, inference
|
decision, telemetry, copilot
|
decision/ |
Safety gate (PolicyEngine) |
core |
inference, copilot, torch
|
edge/ |
Buffers, store-forward, runtime | all core modules | none |
-
Core isolation:
core/imports nothing from any other Sofia module. -
Zero framework pollution: No core module imports
torch,onnxruntime,paho.mqtt,pymodbus,pyserial, orfastapi. -
No insecure deserialization:
pickle.load/pickle.loadsare forbidden across the codebase. -
No global seeding: Neither
random.seednornp.random.seedare called globally; RNGs are injected.
Industrial reproducibility requires exact determinism:
-
Pure DSP Functions: Every signal routine satisfies
$f(\mathbf{x}, \text{config}) \to \mathbf{y}$ with no internal clocks or hidden state. -
Injected Time Sources: Clocks are accessed strictly through
TimeSourceinterfaces (e.g.FixedTimeSourcefor test suites). -
Sample-Rate Time Axis: All frequency and time-domain DSP coordinates derive from discrete sample indices
$n$ and sampling rate$f_s$ ($t = n / f_s$ ), never from operating system wall-clock deltas.
Sofia Engine declares explicit ceilings for all dynamic structures:
| Structure | Default Ceiling | Config Key | Overflow Behavior |
|---|---|---|---|
| Ingest Buffer | 4,096 samples | buffer.max_samples |
Drop oldest sample, increment drop counter |
| Window Length | 1,024 samples | window.length |
Bounded sliding window |
| Store-and-Forward File | 64 MiB | store_forward.max_bytes |
File rotation, oldest log archived/evicted |
| Reconnect Attempts | 8 retries | reconnect.max_attempts |
Exponential backoff capped at 30 s |
| Payload Size | 1 MiB | transport.max_payload_bytes |
Reject frame immediately |
| Metric History | 10,000 samples | metrics.max_samples |
Ring buffer FIFO eviction |
The engine declares three standard failure classifications:
-
REJECT: Malformed or non-finite inputs ($\text{NaN}, \pm\infty$ ). The sample is rejected, counted asmalformed, and logged once per window. -
DEGRADE: Incomplete or stale data. Processing continues, but data quality is taggedSTALEorESTIMATED, degrading diagnostic confidence. -
FAIL: Component or transport failure (e.g., disconnected sensor bus). The error raises a typedTelemetryError, containment logic logs the event, and the edge runtime maintains pipeline continuity without crashing.