Show HN: A self-running space economy SIM in Rust and Bevy

Hacker News Top Products

Summary

A self-running space economy simulator built in Rust and Bevy, featuring autonomous agents, dynamic markets, and full simulation, now open-sourced under MIT.

I built this with Claude cause I always wanted to tinker with a simulation economoy and I love space themes.<p>A space-economy sim where nothing is scripted. A few hundred autonomous ships each run their own planner. Some chase the best trade route, take a delivery contract, refuel, retrofit at a shipyard, or dock so the crew can rest before morale tanks.<p>Markets price everything off supply with shortage-urgency multipliers, factions tax and subsidize, populations migrate when they&#x27;re unhappy, and stations that go broke get abandoned and rot.<p>It started as an Elixir&#x2F;Phoenix prototype, but the BEAM scheduler struggled on Windows gaming PCs, so I had Claude rewrite the engine in Rust.<p>The sim core is pure, synchronous, IO-free (its own hecs ECS), and the Bevy client embeds it directly as a library, sim and renderer share one world with zero marshalling. Ship AI is a GOAP planner over a world state; ships replan mid-flight when a better option appears. ~485 agents today at p50 ~10-20ms&#x2F;tick, architected to push toward 100k+. Single native binary, bundled SQLite, no runtime deps. Getting into 100k has been a struggle, but I have pushed it into the thousand and it was running fine.<p>It&#x27;s a sandbox, not a game yet, there&#x27;s no objective yet, and I&#x27;m not actively pushing it toward &quot;shippable.&quot; Anyone can fork it and take it over. Or it can stay as some type of AI slop, but part of me thinks it is already in a pretty good shape for a simulation use for various games or ideas.<p>(Full disclosure: a lot of this was built pairing with Claude. That&#x27;s how I had the bandwidth to take it this far. Happy to talk about what that workflow actually looked like.)
Original Article
View Cached Full Text

Cached at: 07/21/26, 09:40 PM

Kalcode/spaceprojectsim

Source: https://github.com/Kalcode/spaceprojectsim

🚀 The Space Project

A self-running space-economy simulator, in Rust + Bevy.

Hundreds of autonomous ships trade, mine, haul cargo, take out contracts, run out of fuel, and occasionally go bankrupt across a living solar economy — markets find their own prices, factions tax and subsidize, populations migrate when they’re unhappy, and abandoned stations rot. It all runs in one native binary with no runtime dependencies.


License: MIT Rust Bevy 0.18 Platforms Single binary Status


The Space Project — inner solar system with live ship trails


What is this?

The Space Project is an agent-driven economic simulation wrapped in a native 3D client. There’s no scripted storyline and no player objective — you’re an observer (and god-mode admin) watching an economy run itself.

Every ship is an autonomous agent with its own credits, crew, fuel, cargo hold, and a GOAP planner that decides what to do next: chase the highest-margin trade route, accept a delivery contract, seek out a shipyard to retrofit, or dock and let its crew rest before morale collapses. Facilities run production recipes, degrade and self-repair, level up, and get abandoned when they go broke. Factions collect taxes and post subsidies. Populations consume food, produce labor, and pack up and leave when sentiment craters. Markets price everything off a coverage model with shortage urgency multipliers — no fixed prices anywhere.

It started as an Elixir/Phoenix prototype and was rewritten in Rust because the BEAM scheduler struggled on Windows gaming PCs. The engine (sim_core) is pure, synchronous, IO-free Rust; the Bevy client embeds it directly as a library, so the simulation and the renderer share the same ECS world with zero marshalling between them.

Scale today: ~485 live agents (282 ships · 93 facilities · 27 populations · 8 factions · 60 celestial bodies), ticking at p50 ≈ 10–20 ms inside a 125 ms budget. The architecture is built to push toward 100k+.


🌌 A note on where this is going

Nowhere, on its own — and that’s kind of the point.

This started as a fun idea: a from-scratch space economy that actually simulates itself instead of faking it. It grew way past what I expected, mostly in late-night sessions pairing with Claude. But I’m not pretending it’s a game with a roadmap, and I’m not actively pushing it toward “shippable.”

I’m putting it out under MIT because the bones are genuinely good and I’d rather someone do something with it than let it sit in a private repo. So: fork it, gut it, rename it, bolt a game on top of it, rip the economy engine out and use it somewhere else entirely. Build the thing I didn’t.

PRs and issues are welcome and I’ll look at them, but I can’t promise a cadence. If you want to take it somewhere real, see CONTRIBUTING.md — there’s a “directions you could take this” section written exactly for you.


Screenshots

Title screen
Title screen — start a fresh universe or load a save.
System overview map
System overview — orbital rings across Sol and neighboring systems.
Asteroid mining cluster
Mining cluster — tumbling asteroids, foundries, and ship trails.
Outer systems with nebulae
Outer reaches — distant belts and stations against nebula backdrops.
Factions and contracts inspector panels
Live inspector — faction ledger, relations matrix, full contract board.
Live events stream
Events stream — market crises, dockings, deliveries, tick by tick.

What it simulates

SystemWhat happens
Ship AI (GOAP)A forward planner scores every goal — trade, deliver, refuel, retrofit, rest, explore — over an abstract world state, then builds a behavior tree to execute the cheapest plan. Ships replan mid-flight when a better option appears.
EconomyAn order-book market per station prices 13 commodities off a coverage model with shortage-urgency multipliers. Ships move real supply between markets as they trade.
ContractsSix kinds — Delivery, Courier, Passenger, Subsidy, Supply, CrewMission — with a full posted → accepted → paid lifecycle, reputation gating, auto-renewal, and age-escalating payments.
FacilitiesRun production recipes (smelting, refining, manufacturing, farming, mining), degrade over time, self-repair with tools, level up 1–10, restock from local markets, and get abandoned when chronically broke.
FactionsCollect taxes on member facilities, post subsidy contracts for chronic shortages, fund construction of new facilities where demand is unmet, and hold pairwise relations.
PopulationsConsume food and fuel, produce labor, post food and passenger contracts under stress, and physically migrate to happier systems when sentiment collapses.
CrewAggregate hunger / fatigue / morale with derived tasks (piloting, engineering, trading, eating, resting), skill progression, wages, and a morale death-spiral guard.
ConstructionChronic shortages spawn construction sites that accrete delivered cargo 0 → 1.0, then materialize into a real, persistent facility.
PersistenceEverything flushes to SQLite; a sim resumes from the exact tick it left off. A per-universe world_seed keeps the nebula backdrop and landmarks stable across restarts.
Spatial LODDistant ships tick less often (with rate-scaled state changes) so the frame budget goes where you’re looking.

For the deep dive — tick phase ordering, the AI stack, the economic feedback loop, runtime ownership — see docs/ARCHITECTURE.md, which has mermaid diagrams for all of it.


Quick start

You need a Rust toolchain (stable). Then:

make run
# equivalent to: cargo run -p client_bevy

That boots the Bevy app into the main menu. Start opens a fresh universe (name it, or take the default); Load Game lists every save in the binary’s directory. Saves live next to the binary as <universe-name>.db — default sim.db.

Other entry points:

GoalCommand
Windowed client (debug)make run
Release buildmake build → binary at target/release/client_bevy
Headless (no window, for CI / smoke tests)cargo run -p client_bevy -- --headless
Verify (build + test + clippy, strict)make verify
Smoke test (boot headless, print DB counts)scripts/smoke.sh [secs]

One binary, one process. client_bevy is the whole thing — the simulation runs in-process. Headless mode spins up the HTTP/WebSocket server (from the sim_server library crate) for scripted and CI use; there is no separate server binary to run.


Controls

InputAction
Left-dragOrbit camera
Right-drag / WASDPan
ScrollZoom
Left-clickSelect ship or facility → opens its details panel
Right-clickContext menu (Inspect / Follow / POV / Destroy)
SpacePause / resume
EscClose top panel · clear selection · open pause menu
PPause menu
F12Screenshot
Top barToggle panels (Ships, Markets, Factions, Contracts, Events, …), set speed (1× / 2× / 5× / 10×), spawn ships/facilities

Every panel reads the ECS world live — the inspector is effectively a real-time debugger with full component access. Click a ship to see its credits, crew, fuel, current goal, fitting, route memory, and its last few AI commands.


Architecture

Five crates in one Cargo workspace:

sim_core     Pure simulation logic — hecs ECS, GOAP planner, economy,
             contracts. No async, no IO, no framework. Trivially testable.
sim_db       SQLite persistence (sqlx) — pool, seeder, ECS loader,
             persistence worker, migrations.
sim_server   Library crate — HTTP/WebSocket handlers + engine apply
             helpers. Drives headless mode; embedded by the client.
sim_protocol WebSocket wire types (headless / CI only).
client_bevy  The binary. Bevy 0.18 + egui. Embeds sim_core as a Bevy
             Resource; the renderer queries the hecs world directly.

Three rules keep it honest:

  1. sim_core never imports tokio, sqlx, or axum. Pure logic only, so the whole simulation is reasoned about and unit-tested without async.
  2. hecs is the source of truth during a tick. The tick loop holds exclusive mutable access — no per-agent locks.
  3. Cross-entity effects go through a command buffer (SimCommand). A phase reads world state and writes commands; the next phase applies them. Deterministic, no mid-phase write conflicts.

The full tick phase order, ownership model, and feedback loops are diagrammed in docs/ARCHITECTURE.md.

The original Godot client lives on in history as a parity reference, but it’s no longer the front end — the pivot to an embedded Bevy client removed the socket boundary entirely, and every feature now lands in client_bevy.


Building & packaging

The Makefile wraps cargo + rustup + codesign + packaging:

make build              # release binary (host target)
make build-mac          # arm64 macOS  (also: build-mac-intel, build-mac-universal)
make build-win          # Windows MSVC (run on a Windows host)
make build-linux        # Linux        (best on a Linux host)

make package-mac        # .app bundle + ad-hoc codesign + Info.plist
make dmg                # macOS .dmg
make package-win        # Windows .zip
make package-linux      # Linux .tar.gz

The workspace version in the root Cargo.toml is the single source of truth — the binary reads it via env!("CARGO_PKG_VERSION") and the Makefile greps the same field for Info.plist and archive names, so packaged builds never drift.


Tech stack

  • Rust (edition 2021) — the whole thing
  • Bevy 0.18 — renderer, ECS-driven main loop, custom WGSL shaders (procedural planets, sun corona, nebulae, starfield)
  • hecs — the simulation’s own ECS (separate from Bevy’s, deliberately)
  • egui (via bevy_egui) — every inspector panel
  • bevy_hanabi — GPU particle trails and explosions
  • sqlx + SQLite — persistence, bundled so there’s no runtime dependency
  • axum + tokio — the headless HTTP/WebSocket harness

Contributing

Contributions are welcome — see CONTRIBUTING.md for dev setup, the conventions that keep the codebase clean, and a list of concrete directions if you want to take this somewhere real.

The fastest sanity check before any PR:

make verify   # build + ~250 tests + clippy, strict

License

MIT © 2026 Kalcode (David Clausen). Do whatever you like with it.


Built for fun in Rust & Bevy · By Kalcode & Claude · Made with ❤️ in Illinois

Similar Articles

Agent Bazaar: Enabling Economic Alignment in Multi-Agent Marketplaces

Hugging Face Daily Papers

Introduces Agent Bazaar, a multi-agent simulation framework for evaluating economic alignment of LLMs, identifying failure modes like algorithmic instability and Sybil deception, and training a 9B model that outperforms frontier models using targeted reinforcement learning.