https://github.com/rudra496/worldsim-ai
๐ WorldSim AI โ AI-powered world simulation engine. Generate, explore & interact with dynamic virtual worlds. For research, gaming & creative storytelling.
https://github.com/rudra496/worldsim-ai
3d ai ai-simulation creative-ai digital-twin game-ai generative-ai hacktoberfest llm llm-agent machine-learning open-source predictive-modeling procedural-generation python reinforcement-learning simulation virtual-worlds world-generation
Last synced: 15 days ago
JSON representation
๐ WorldSim AI โ AI-powered world simulation engine. Generate, explore & interact with dynamic virtual worlds. For research, gaming & creative storytelling.
- Host: GitHub
- URL: https://github.com/rudra496/worldsim-ai
- Owner: rudra496
- License: mit
- Created: 2026-03-30T22:58:17.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-06-05T16:39:17.000Z (19 days ago)
- Last Synced: 2026-06-05T18:42:40.724Z (19 days ago)
- Topics: 3d, ai, ai-simulation, creative-ai, digital-twin, game-ai, generative-ai, hacktoberfest, llm, llm-agent, machine-learning, open-source, predictive-modeling, procedural-generation, python, reinforcement-learning, simulation, virtual-worlds, world-generation
- Language: Python
- Homepage: https://rudra496.github.io/worldsim-ai/
- Size: 194 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
- Support: SUPPORT.md
- Roadmap: ROADMAP.md
Awesome Lists containing this project
README

# ๐ WorldSim AI
**AI-Powered Digital Twin Simulation Platform**
Model, predict, and optimize real-world systems โ smart cities, factories, energy grids, logistics networks, and more. Feature-rich agent-based simulation with real-time 3D visualization, reinforcement learning, IoT data ingestion, distributed scaling, and digital twin capabilities. Free and open-source (MIT).
> If you find this project useful, please consider giving it a โญ star โ it helps more developers discover it!
[](https://github.com/rudra496/worldsim-ai/stargazers)
[](https://github.com/rudra496/worldsim-ai/network/members)
[](https://github.com/rudra496/worldsim-ai/watchers)
[](https://github.com/rudra496/worldsim-ai/discussions)
[](https://python.org)
[](https://fastapi.tiangolo.com)
[](https://reactjs.org)
[](https://threejs.org)
[](https://numpy.org)
[](https://pytorch.org)
[](LICENSE)
[](https://docker.com)
[](CONTRIBUTING.md)
[](https://github.com/rudra496/worldsim-ai/releases/tag/v0.1.0)
---
## โก One Command Start
```bash
git clone https://github.com/rudra496/worldsim-ai.git
cd worldsim-ai
docker-compose up --build
# ๐ Open http://localhost:3000
```
๐ฆ Alternative: Python-only (no frontend)
```bash
pip install -r requirements.txt
python run_demo.py
```
๐ง Alternative: Full local development
```bash
# Backend
pip install -r requirements.txt
uvicorn worldsim.api.main:app --reload --port 8000
# Frontend (separate terminal)
cd frontend && npm install && npm start
```
---
## โจ Complete Feature Set
### ๐งฌ Agent-Based Modeling
- **4 agent types**: Vehicle, Human, Machine, EnergyUnit โ each with customizable properties
- **Rule-based & probabilistic behaviors** โ deterministic or stochastic movement, production, consumption
- **Multi-agent AI system** โ autonomous Planner, Predictor, and Optimizer agents coordinate via AgentCoordinator
### ๐ Environment Modeling
- **2D grid & graph world** representations with configurable dimensions
- **8 zone types**: residential, industrial, commercial, road, park, power_plant, water_treatment, warehouse
- **Resource management** โ energy, water, materials, bandwidth with production/consumption tracking
### ๐ง AI & Machine Learning
- **PyTorch LSTM predictor** โ deep time-series forecasting (NumPy fallback when PyTorch unavailable)
- **Autoencoder anomaly detection** โ unsupervised drift and outlier detection
- **LP-based resource optimization** โ scipy linear programming for allocation
- **Priority scheduling** โ greedy heuristic for task ordering
- **Reinforcement learning** โ Gymnasium-compatible environment with PPO/Q-learning agents
- **Adaptive feedback loops** โ simulation โ AI prediction โ optimization โ correction cycle
### ๐ฎ 3D Visualization (Three.js)
- **Interactive 3D world** via React Three Fiber โ orbit, pan, zoom controls
- **3D zone rendering** โ translucent colored boxes with zone type labels
- **Agent 3D objects** โ vehicles (boxes), humans (spheres), machines (cylinders), energy (glowing spheres)
- **Day/night cycle** โ toggle between ambient lighting modes
- **2D โ 3D switcher** โ seamless view switching
### ๐ก Real-Time Data Ingestion
- **MQTT source** โ subscribe to IoT sensor topics with JSON parsing (requires `paho-mqtt`)
- **File source** โ CSV/JSON/JSONL ingestion with live tail support
- **REST API source** โ periodic polling of external endpoints
- **Simulator source** โ synthetic data with noise, drift, and failure injection
- **Alert manager** โ CRITICAL/WARNING/INFO with configurable callbacks
### ๐ฅ Distributed Simulation
- **Multi-node engine** โ extends core engine for horizontal scaling
- **Spatial partitioning** โ grid-based agent distribution across nodes
- **Load balancing** โ threshold-based rebalancing with migration plans
- **gRPC protocol** โ dataclass-based message serialization (no protoc required)
### ๐ Digital Twin
- **Live/replay/hybrid sync** modes โ mirror real-world data or replay historical patterns
- **GIS integration** โ GeoJSON loading, coordinate transforms, geofencing with ray-casting
- **Plugin system** โ hot-reloadable plugins with ABC interface
- **Built-in plugins** โ LoggingPlugin, MetricsExportPlugin (Prometheus), SlackNotifyPlugin
- **Plugin marketplace** โ local catalog with built-in plugins (extensible to remote registries)
- **REST + WebSocket connector** โ push/pull state, bidirectional sync
- **API key auth** with role-based access control
- **Rate limiting** โ token bucket algorithm
### ๐ Dashboard & API
- **React SPA** โ dark theme, responsive, works standalone in demo mode
- **Real-time WebSocket** โ live simulation streaming to frontend
- **9 API endpoints** โ scenarios, simulations, results, metrics, health + WebSocket
- **Metrics charts** โ recharts for throughput, efficiency, stability, utilization
- **CLI tool** โ `worldsim run`, `list`, `demo`, `serve`
### ๐ฌ Research Framework
- โ
**Deterministic mode** โ Same seed โ identical results (reproducible experiments)
- โ
**State snapshots** โ Checkpoint and restore at any tick
- โ
**Event bus** โ Full pub/sub for simulation events
- โ
**Multiple export formats** โ JSON, CSV, structured text reports
- โ
**Config-driven** โ YAML configs, no hardcoded values
---
## ๐บ Roadmap
| Version | Status | Description |
|---------|--------|-------------|
| **v0.1** | โ
Done | Core engine, 4 agent types, grid/graph worlds, AI prediction + optimization, 8 scenarios, REST + WebSocket API, React dashboard, Docker |
| **v0.2** | โ
Done | PyTorch LSTM predictor (NumPy fallback), autoencoder anomaly detection, Gymnasium RL env, PPO/Q-learning agents, multi-agent AI system, adaptive feedback loops |
| **v0.3** | โ
Done | Three.js 3D world (React Three Fiber), orbit controls, 3D zones/agents with glow, day/night cycle, 2Dโ3D view switcher |
| **v0.4** | โ
Done | MQTT/File/API/Simulator data sources, ingestion pipeline, ring buffer, data transformer, alert manager |
| **v0.5** | โ
Done | Multi-node distributed engine, spatial partitioning, load balancing, gRPC protocol, message serialization |
| **v1.0** | โ
Done | Digital twin core (live/replay/hybrid), GIS integration, plugin system + marketplace, REST/WebSocket connector, API auth, rate limiting |
> ๐ See [ROADMAP.md](ROADMAP.md) for detailed feature checklists.
---
## ๐ Architecture
```mermaid
graph TB
subgraph Presentation ["๐ฅ๏ธ Presentation Layer"]
UI["React Dashboard"]
Canvas["2D Canvas"]
Three["3D View (Three.js)"]
Charts["Metrics Charts"]
end
subgraph API ["๐ก API Layer"]
REST["REST Endpoints"]
WS["WebSocket"]
CLI["CLI Tool"]
end
subgraph Core ["โ๏ธ Simulation Core"]
Engine["Simulation Engine
S(t+1) = F(S(t), A(t), E(t))"]
Events["Event Bus"]
State["State Manager"]
end
subgraph Models ["๐งฌ Modeling Layer"]
Agents["Agent System (4 types)"]
Env["Environment (Grid + Graph)"]
Scenarios["Scenario Engine"]
end
subgraph AI ["๐ง Intelligence Layer"]
Predict["LSTM Predictor"]
Detect["Anomaly Detector"]
Optimize["LP Optimizer"]
RL["RL Agents (PPO)"]
MAS["Multi-Agent System"]
Feedback["Feedback Loops"]
end
subgraph DataIO ["๐ก Data Layer"]
MQTT_S["MQTT Source"]
File_S["File Source"]
API_S["API Source"]
Sim_S["Simulator Source"]
end
subgraph Twin ["๐ Digital Twin"]
GIS["GIS / GeoJSON"]
Plugins["Plugin System"]
Market["Marketplace"]
Connector["Twin Connector"]
end
subgraph Dist ["๐ Distributed"]
Nodes["Simulation Nodes"]
Partition["Spatial Partitioning"]
GRPC["gRPC Protocol"]
end
UI --> REST
UI --> WS
CLI --> Engine
REST --> Engine
WS --> Engine
Engine --> Agents
Engine --> Env
Engine --> Events
Engine --> State
Scenarios --> Engine
Predict --> Engine
Detect --> Engine
Optimize --> Engine
RL --> Engine
MAS --> Engine
Feedback --> Engine
MQTT_S --> Engine
File_S --> Engine
API_S --> Engine
Sim_S --> Engine
GIS --> Engine
Plugins --> Engine
Market --> Plugins
Connector --> Engine
Nodes --> Engine
Partition --> Nodes
GRPC --> Nodes
```
### Formal Model
Every simulation step follows:
```
S(t+1) = F(S(t), A(t), E(t))
```
- **S(t)** โ System state at time t (resources, metrics, counters)
- **A(t)** โ Agent actions at time t (movement, production, consumption)
- **E(t)** โ Environment factors at time t (zones, traffic, energy grid)
- **F** โ Transition function (combines all inputs โ next state)
---
## ๐ฎ Demo Scenarios
| # | Scenario | Description | Agents | Zones | Ticks |
|---|----------|-------------|--------|-------|-------|
| ๐๏ธ | **Smart City Traffic** | Urban traffic with vehicles & pedestrians across mixed-use city zones | 105 | 8 | 300 |
| ๐ญ | **Factory Optimization** | Production line with machines, workers, and energy constraints | 68 | 3 | 500 |
| โก | **Energy Balancing** | Multi-source energy grid with varying demand patterns | 85 | 8 | 400 |
| ๐ค๏ธ | **Weather System** | Weather patterns with temperature, precipitation, and wind feedback | 90 | 13 | 600 |
| ๐ฅ | **Population Dynamics** | Population growth, migration, and resource competition | 133 | 10 | 500 |
| ๐ | **Supply Chain** | Multi-node supply chain with factories, warehouses, and retail | 110 | 10 | 400 |
| ๐พ | **Smart Agriculture** | Precision agriculture with irrigation and automated harvesting | 65 | 10 | 500 |
| ๐จ | **Emergency Failure** | System resilience testing under power outages and breakdowns | 76 | 6 | 400 |
---
## ๐ Project Structure
```
worldsim-ai/
โโโ ๐ worldsim/ # Python simulation engine
โ โโโ core/ # Engine, state, events
โ โโโ agents/ # Agent-based modeling (4 types)
โ โโโ environment/ # World, zones, resources
โ โโโ ai/ # Intelligence layer
โ โ โโโ predictor.py # Linear regression, moving average
โ โ โโโ optimizer.py # LP resource allocation
โ โ โโโ ml_models.py # PyTorch LSTM, anomaly detection
โ โ โโโ reinforcement_learning.py # Gymnasium RL, PPO/Q-learning
โ โ โโโ multi_agent_system.py # Planner, Predictor, Optimizer agents
โ โ โโโ feedback.py # Adaptive feedback loops
โ โโโ scenarios/ # 4 demo scenario configs
โ โโโ api/ # FastAPI REST + WebSocket
โ โโโ io/ # Data ingestion (MQTT, File, API, Sim)
โ โโโ distributed/ # Multi-node simulation
โ โโโ twin/ # Digital twin, GIS, plugins, marketplace
โ โโโ data/ # Data pipeline & generation
โ โโโ utils/ # Config, metrics, CLI
โ โโโ cli.py # worldsim command-line tool
โ
โโโ โ๏ธ frontend/ # React visualization
โ โโโ src/
โ โ โโโ components/ # Canvas, Charts, Controls, World3D
โ โ โโโ services/api.js # Backend API client
โ โ โโโ utils/simulation.js # Color maps, demo data
โ โ โโโ App.js # Main dashboard (2D + 3D)
โ โโโ Dockerfile # Multi-stage build (node โ nginx)
โ โโโ nginx.conf # API proxy + SPA fallback
โ
โโโ ๐ config/ # YAML configurations
โโโ ๐งช tests/ # Test suite
โโโ ๐ docs/ # Architecture, simulation guide
โโโ ๐ณ docker-compose.yml # One-command deploy (4 services)
โโโ ๐ณ Dockerfile # Backend image
โโโ ๐ pyproject.toml # Python packaging + optional deps
โโโ ๐ฎ run_demo.py # Quick demo runner
```
---
## ๐ Tech Stack
| Layer | Technology |
|-------|-----------|
| **Simulation** | Python 3.11+, NumPy, SciPy |
| **AI/ML** | PyTorch (optional), Gymnasium (optional), stable-baselines3 (optional) |
| **API** | FastAPI, Uvicorn, WebSockets |
| **Frontend** | React 18, Three.js, React Three Fiber, recharts, HTML5 Canvas |
| **IoT** | paho-mqtt (optional) |
| **Distributed** | gRPC (optional), pickle/zlib |
| **Digital Twin** | GeoJSON, shapely (optional) |
| **Deployment** | Docker, Nginx |
---
## ๐ API Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| `GET` | `/` | API health & info |
| `GET` | `/scenarios` | List available scenarios |
| `POST` | `/simulations/start` | Start a new simulation |
| `GET` | `/simulations` | List all simulations |
| `GET` | `/simulations/{id}` | Get simulation status |
| `GET` | `/simulations/{id}/results` | Get simulation results |
| `GET` | `/simulations/{id}/metrics` | Get aggregated metrics |
| `GET` | `/health` | Health check |
| `WS` | `/ws/simulations/{id}` | Real-time updates |
---
## ๐ค Contributing
Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
- ๐ New agent types and behavior models
- ๐ New scenarios (epidemics, supply chain, climate...)
- ๐ Visualization improvements
- ๐ New plugins for the marketplace
- ๐ Documentation & tutorials
- ๐ Bug reports and feature requests
---
## ๐ License
[MIT License](LICENSE) โ free for personal and commercial use.
---
## ๐จโ๐ป Author
**Rudra Sarker**
[](https://github.com/rudra496)
[](https://twitter.com/Rudra496)
[](https://www.linkedin.com/in/rudrasarker)
[](https://www.facebook.com/rudrasarker130)
[](https://rudra496.github.io/site)
[](https://www.researchgate.net/profile/Rudra-Sarker-3)
[](https://www.sust.edu)
๐ Open Source Developer | AI tools, code analysis & developer education
Creator of TermMind, CodeVista, DevRoadmaps & SignLanguage Dataset Hub
*Model the world. Optimize the future. Open source forever.* ๐
## Connect
- [](https://github.com/rudra496)
- [](https://www.linkedin.com/in/rudrasarker)
- [](https://x.com/Rudra496)
- [](https://youtube.com/@rudrasarker9732)
- [](https://dev.to/rudra_sarker)