lib.rs— crate root, re-exports thegalaxymodulegalaxy.rs— core simulation logic:Galaxystruct withCellgrid, gravitational physics (Newton's law), acceleration, seeding, tick advancement. Exposed to JS viawasm-bindgen
Cell types by mass: Gas (below min_star_mass), Star (above). Planned but not yet implemented: Planet, White Hole.
The Galaxy is immutable-style — methods like seed(), tick() return new Galaxy instances.
- Built with
wasm-pack, output goes topkg/(gitignored) - The JS package.json references
"galaxy_gen_backend": "file:pkg"as a dev dependency
index.html— Bootstrap 5 dark theme shellindex.js— React entry pointlib/galaxy.ts—Frontendclass wrapping the WASM Galaxy, exposesseed(),tick(),cells()lib/application.tsx— React UI with inputs (galaxy size, seed mass, time modifier) and buttons (init, seed, advance time)lib/dataviz.tsx— D3 scatter plot visualization of cells, circle radius = log(mass)lib/styles.css— custom styles
- Rust:
cargo build,cargo test - WASM:
wasm-pack build(previouslywasm-pack init) - JS: webpack 5 with babel (React + TypeScript presets), dev server via
webpack-dev-server makefilehas convenience targets but some are outdated (referenceswasm-pack init)
- GitHub Actions (
.github/workflows/action.yml): two jobs —rust(build/check/test + wasm-pack) andjs(wasm-pack + npm ci)
# Rust
cargo build # compile
cargo check # type check
cargo test # run tests (there are many in galaxy.rs)
# WASM
wasm-pack build # compile to WASM, output in pkg/
# JS
npm install # install deps (requires pkg/ from wasm-pack)
npm run build # production webpack build
npm start # dev server- Rust code uses
wasm_bindgenfor the public API boundary; private methods are plainimplblocks - Galaxy grid is flat
Vec<Cell>indexed byrow * size + col - Physics uses magnitude + degrees (not x/y vectors) for acceleration storage, converting at computation boundaries
- Tests are organized in
mod tests_*blocks at the bottom ofgalaxy.rs - Frontend state is managed with React
useStatehooks (no state library) - No linting/formatting tools are actively enforced beyond
tslint.json(which is deprecated)
- Rust:
wasm-bindgen,specs/specs-derive(ECS, currently unused),rand,console_error_panic_hook - JS: React 18, D3 7, TypeScript 5, webpack 5, Bootstrap 5 (CDN)