How enming73/digital-twin works
SMT Digital Twin Studio is a synthetic SMT-line demonstration with a standalone browser workflow and an optional remote stack. In the browser, users run or control a deterministic production simulation, inspect the 3D line and analytics, and trace boards; remote mode instead displays read-only backend state and supports historical seek and MES trace lookup. The optional Go simulator publishes events to a twin backend, which exposes APIs and can add durable history and offline recovery. Some backend and simulator connections are documented in the README but their implementation excerpts were not sampled.
Main entry points: App.tsx Studio app · engine.ts Simulation engine · http.go REST and WebSocket API · mqtt.go MQTT ingestion
Components 33
Browser experience
- Studio app
src/app/App.tsx - Factory scene
src/scene/Factory.tsx - Station model
src/data/stations.ts - Production dashboard
src/components/Dashboard.tsx - Remote trace UI
src/components/RemoteTrace.tsx
Local production demo
- Simulation engine
src/simulation/engine.ts - Scenario data
src/data/scenario.ts - Production analytics
src/domain/analytics.ts - Local replay
src/domain/replay.ts - Guided presentation
src/presentation/presentation.ts
Remote twin view
- Remote client
src/twin/remoteClient.ts - Remote projection
src/twin/projection.ts - Remote scene adapter
src/twin/remoteAdapter.ts - Remote motion
src/scene/remoteMotion.ts - History client
src/twin/historicalClient.ts - MES client
src/twin/mesClient.ts
Simulator and ingestion
- Go simulator
simulator/cmd/simulator/main.go - Simulation engine
simulator/internal/engine/engine.go - Scenario runner
simulator/internal/runner/runner.go - Durable outbox
simulator/internal/outbox/service.go - MQTT publisher
simulator/internal/publisher/mqtt.go
Twin backend
- Backend service
backend/cmd/twin-backend/main.go - MQTT ingestion
backend/internal/ingest/mqtt.go - Event contract
backend/internal/contract/event.go - Twin state
backend/internal/twin/store.go - REST and WebSocket API
backend/internal/api/http.go - Mock MES fixtures
backend/internal/mes/fixtures.go - PostgreSQL history
backend/internal/persistence/events.go - Historical replay
backend/internal/replay/historical.go - Offline recovery
backend/internal/recovery/coordinator.go
Other components
- Viewer
- MQTT broker
- Durable source API
Connections 35
- Viewer → Studio app: uses
README.md - Studio app → Simulation engine: runs locally
src/app/App.tsx - Studio app → Remote client: starts remote
src/app/App.tsx - Studio app → History client: seeks history
src/app/App.tsx - Studio app → Factory scene: renders
src/app/App.tsx - Studio app → Production dashboard: renders
src/app/App.tsx - Studio app → Remote trace UI: renders
src/app/App.tsx - Scenario data → Simulation engine: configures
src/data/scenario.ts - Simulation engine → Production analytics: supplies events
src/domain/analytics.ts - Simulation engine → Local replay: supplies events
src/domain/replay.ts - Simulation engine → Guided presentation: drives
src/presentation/presentation.ts - Factory scene → Station model: uses layout
src/scene/Factory.tsx - Production dashboard → Production analytics: computes metrics
src/components/Dashboard.tsx - Remote client → Remote projection: applies messages
src/twin/remoteClient.ts - Studio app → Remote scene adapter: adapts state
src/app/App.tsx - Remote scene adapter → Remote motion: updates motion
src/twin/remoteAdapter.ts - Remote trace UI → MES client: requests trace
src/components/RemoteTrace.tsx - History client → Remote projection: validates snapshot
src/twin/historicalClient.ts - Go simulator → Scenario runner: runs scenarios
README.md - Scenario runner → Simulation engine: advances
README.md - Go simulator → Durable outbox: persists events
README.md - Go simulator → MQTT publisher: publishes events
README.md - MQTT publisher → MQTT broker: publishes MQTT
README.md - MQTT broker → MQTT ingestion: delivers events
README.md - Backend service → MQTT ingestion: starts ingestion
README.md - MQTT ingestion → Event contract: validates events
README.md - MQTT ingestion → Twin state: updates state
README.md - Backend service → REST and WebSocket API: serves APIs
README.md - REST and WebSocket API → Twin state: reads projection
README.md - REST and WebSocket API → Mock MES fixtures: serves trace data
README.md - Twin state → PostgreSQL history: persists events
README.md - Historical replay → PostgreSQL history: reads history
README.md - REST and WebSocket API → Historical replay: serves replay
README.md - Offline recovery → Durable source API: repairs from
README.md - Studio app → REST and WebSocket API: reads remotely
README.md