How shrankhalalala/digital_twin works
This is a supply-chain digital twin: operators inspect a network, inject disruptions, run simulations, and review risk, inventory, routing recommendations, and explanations. The browser dashboard presents graph and map views alongside simulation, metrics, routing, and explainability controls; backend APIs manage the graph and dispatch simulation work. The simulation worker runs the in-memory timestep engine and publishes state to Redis. Graph persistence uses Neo4j. The README documents causal scoring, optimization, and telemetry capabilities, but sampled code does not establish all their wiring; those uncertain connections are omitted.
Main entry points: page.tsx Dashboard page · main.py FastAPI application · simulation_service.py Simulation engine · simulation_worker.py Simulation worker
Components 27
Operator dashboard
- Dashboard page
frontend/src/app/page.tsx - Graph canvas
frontend/src/components/graph/GraphCanvas.tsx - Geographic map
frontend/src/components/graph/MapCanvas.tsx - Client state
frontend/src/store/graphStore.ts - Simulation controls
frontend/src/components/dashboard/SimulationPanel.tsx - Metrics panel
frontend/src/components/dashboard/MetricsPanel.tsx - Routing controls
frontend/src/components/dashboard/RoutingControlPanel.tsx - Explainability panel
frontend/src/components/dashboard/ExplainabilityPanel.tsx
API and graph domain
- FastAPI application
backend/app/main.py - Graph API
backend/app/api/graph.py - Development API
backend/app/api/dev.py - Routing API
backend/app/api/routing.py - Simulation API
backend/app/api/simulation.py - Graph operations
backend/app/services/graph_service.py - Graph seeding
backend/app/services/dev_service.py - Graph data schema
backend/app/schemas/graph.py
Simulation and intelligence
- Simulation engine
backend/app/services/simulation_service.py - Causal risk analysis
backend/app/services/ml_causal_service.py - Inventory optimization
backend/app/services/ml_optimization_service.py - Delay prediction
backend/app/services/ml_routing_service.py
Persistence and jobs
- Simulation worker
backend/app/workers/simulation_worker.py - Neo4j connection
backend/app/db/neo4j.py - Supply network
- Redis connection
backend/app/db/redis.py - Simulation state
- Celery task queue
backend/app/celery_app.py
Other components
- Supply-chain operator
Connections 31
- Supply-chain operator → Dashboard page: uses
README.md - Dashboard page → Graph canvas: renders
README.md - Dashboard page → Geographic map: renders
README.md - Dashboard page → Simulation controls: renders
README.md - Dashboard page → Metrics panel: renders
README.md - Dashboard page → Routing controls: renders
README.md - Dashboard page → Explainability panel: renders
README.md - Graph canvas → Client state: shares state
README.md - Geographic map → Client state: shares state
README.md - Client state → FastAPI application: HTTP / WS
README.md - FastAPI application → Graph API: registers
backend/app/main.py - FastAPI application → Development API: registers
backend/app/main.py - FastAPI application → Routing API: registers
backend/app/main.py - FastAPI application → Simulation API: registers
backend/app/main.py - Graph API → Graph operations: delegates to
backend/app/api/graph.py - Graph operations → Neo4j connection: uses session
backend/app/services/graph_service.py - Neo4j connection → Supply network: reads / writes
README.md - Graph operations → Graph data schema: validates data
backend/app/services/graph_service.py - Development API → Graph seeding: delegates to
backend/app/api/dev.py - Graph seeding → Graph operations: imports subgraph
backend/app/services/dev_service.py - Graph seeding → Graph data schema: builds seed data
backend/app/services/dev_service.py - Routing API → Delay prediction: predicts delay
backend/app/api/routing.py - Simulation API → Simulation worker: dispatches task
backend/app/api/simulation.py - Simulation worker → Simulation engine: runs
backend/app/workers/simulation_worker.py - Simulation worker → Celery task queue: registered task
backend/app/workers/simulation_worker.py - Simulation engine → Causal risk analysis: predicts propagation
backend/app/services/simulation_service.py - Simulation engine → Inventory optimization: requests actions
backend/app/services/simulation_service.py - Simulation engine → Neo4j connection: loads network
- Simulation engine → Redis connection: writes updates
backend/app/services/simulation_service.py - Simulation worker → Redis connection: updates status
backend/app/workers/simulation_worker.py - Redis connection → Simulation state: reads / writes
README.md