cd /news/ai-agents/show-hn-a-self-running-space-economy… Β· home β€Ί topics β€Ί ai-agents β€Ί article
[ARTICLE Β· art-67451] src=github.com β†— pub= topic=ai-agents verified=true sentiment=Β· neutral

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

The Space Project, an agent-driven space economy simulation built in Rust and Bevy, is now open-source under MIT. The simulation runs hundreds of autonomous ships, facilities, populations, and factions in a single native binary with no runtime dependencies, featuring a GOAP planner for ship AI and a coverage-model market system. Creator 'kettlecorn' released the code after rewriting it from Elixir/Phoenix to Rust, aiming for others to build upon the simulation engine.

read7 min views1 publishedJul 21, 2026
Show HN: A self-running space economy SIM in Rust and Bevy
Image: source

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.

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+.

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

waypast 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.

System What 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.
Economy
An 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.
Contracts
Six kinds β€” Delivery, Courier, Passenger, Subsidy, Supply, CrewMission β€” with a full posted β†’ accepted β†’ paid lifecycle, reputation gating, auto-renewal, and age-escalating payments.
Facilities
Run 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.
Factions
Collect taxes on member facilities, post subsidy contracts for chronic shortages, fund construction of new facilities where demand is unmet, and hold pairwise relations.
Populations
Consume food and fuel, produce labor, post food and passenger contracts under stress, and physically migrate to happier systems when sentiment collapses.
Crew
Aggregate hunger / fatigue / morale with derived tasks (piloting, engineering, trading, eating, resting), skill progression, wages, and a morale death-spiral guard.
Construction
Chronic shortages spawn construction sites that accrete delivered cargo 0 β†’ 1.0, then materialize into a real, persistent facility.
Persistence
Everything 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 LOD
Distant 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.

You need a Rust toolchain (stable). Then:

make run

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:

Goal Command
Windowed client (debug) make run
Release build make 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

isthe whole thing β€” the simulation runs in-process. Headless mode spins up the HTTP/WebSocket server (from thesim_server

library crate) for scripted and CI use; there is no separate server binary to run.

Input Action
Left-drag
Orbit camera
Right-drag / WASD
Pan
Scroll
Zoom
Left-click
Select ship or facility β†’ opens its details panel
Right-click
Context menu (Inspect / Follow / POV / Destroy)
Space
/ resume
Esc
Close top panel Β· clear selection Β· open menu
P
menu
F12
Screenshot
Top bar Toggle 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.

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 ,
             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:

Pure logic only, so the whole simulation is reasoned about and unit-tested without async.sim_core

never imports tokio, sqlx, or axum.hecs is the source of truth during a tick. The tick loop holds exclusive mutable access β€” no per-agent locks.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

Godotclient 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 inclient_bevy

.

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.

(edition 2021) β€” the whole thingRustβ€” renderer, ECS-driven main loop, custom WGSL shaders (procedural planets, sun corona, nebulae, starfield)Bevy 0.18β€” the simulation's own ECS (separate from Bevy's, deliberately)hecs(viaeguibevy_egui

) β€” every inspector panelβ€” GPU particle trails and explosionsbevy_hanabi+ SQLite β€” persistence, bundled so there's no runtime dependencysqlx+ tokio β€” the headless HTTP/WebSocket harnessaxum

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

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

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

── more in #ai-agents 4 stories Β· sorted by recency
── more on @the space project 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/show-hn-a-self-runni…] indexed:0 read:7min 2026-07-21 Β· β€”