# Mass Driver — Interplanetary Relay Network Simulator ## Project Structure Rust workspace + SvelteKit frontend compiled to WASM. ``` crates/ orbital-mechanics/ — Pure Rust: Kepler solver, Lambert solver, orbit propagation, Lagrange points mass-driver-core/ — Station placement, transfer matrix computation, Dijkstra routing mass-driver-wasm/ — Thin wasm-bindgen wrapper exposing core to JS mass-driver-backend/ — Axum cache server (Postgres) frontend/ — SvelteKit + Threlte (Three.js) + Canvas2D ``` ## Build Commands ```bash # Rust tests cargo test # Build WASM (required before frontend) cd crates/mass-driver-wasm && wasm-pack build --target web --release # Frontend dev server cd frontend && npm run dev -- --port 5173 # Frontend production build cd frontend && npx vite build # Backend (needs DATABASE_URL env var) cargo run -p mass-driver-backend ``` ## Key Architecture - Orbital mechanics runs in WASM (Rust compiled to WebAssembly) - Frontend loads WASM on mount, calls it every animation frame for body positions - Route computation: Lambert solver → transfer matrix → time-expanded graph → Dijkstra - 2D view: Canvas2D with manual drawing. 3D view: Threlte (Svelte Three.js wrapper) - Positions in AU (ecliptic coords), converted to screen pixels (2D) or Three.js units (3D) - Ecliptic→Three.js mapping: X→X, Y→-Z, Z→Y (Three.js is Y-up) ## WASM Rebuild After changing any Rust code in orbital-mechanics, mass-driver-core, or mass-driver-wasm: ```bash cd crates/mass-driver-wasm && wasm-pack build --target web --release ``` The frontend links to the WASM pkg via `file:../crates/mass-driver-wasm/pkg` in package.json. ## Coordinate Systems - Rust returns positions in AU, ecliptic frame (X=vernal equinox, Y=90° in ecliptic, Z=north pole) - Lambert solver works in km (positions × AU_KM constant) - 2D canvas: AU mapped to pixels via zoom factor - 3D scene: 1 AU = 50 Three.js units, Y-up convention