Add Grand Simulations: FastAPI backend, simulation engine, SQLite storage and React + Vite frontend - #2
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9c05c0fbf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| universe_rng = _rng(seed, "universe") | ||
| systems = [_system_summary(seed, index) for index in range(universe_rng.randint(3, 5))] | ||
| state = { | ||
| "id": f"sim-{seed}", |
There was a problem hiding this comment.
Generate a unique ID for each saved simulation
If a user creates a second simulation with the same seed—which is the natural way to compare alternate intervention paths—generate_simulation() emits the same id, and save_simulation() upserts on that key in backend/app/storage.py:39-44. The new POST silently replaces the existing row, so save/load cannot preserve multiple checkpoints for one deterministic universe.
Useful? React with 👍 / 👎.
| metrics["avg_temperature"] = round(_clamp(metrics["avg_temperature"] + climate_delta, 0.0, 1.0), 3) | ||
| metrics["avg_moisture"] = round(_clamp(metrics["avg_moisture"] + moisture_delta, 0.0, 1.0), 3) | ||
| metrics["water_ratio"] = round(_clamp(metrics["water_ratio"] + moisture_delta * 0.18, 0.0, 1.0), 3) |
There was a problem hiding this comment.
Recompute planet metrics from the surface after each step
These aggregate values are advanced here instead of being recomputed from planet.surface, while _apply_surface_feedback() only applies influence deltas to cells and never updates has_water or biome. After a few normal steps, the backend can report one temperature/moisture/water ratio for a planet while the UI map and hover cells still show the old surface, so the simulation state becomes internally contradictory.
Useful? React with 👍 / 👎.
Motivation
Description
backend/app/main.pyexposing/api/health,/api/simulations, creation, retrieval, stepping (/step) and planet influence endpoints, with request/response models inbackend/app/models.py.backend/app/simulation.pythat generates systems/planets, computes surface grids, species, life/civilization progression, alerts, and supportsstep_simulationandapply_influenceoperations.backend/app/storage.pywithinit_db,save_simulation,load_simulation, andlist_simulations, and ensure DB path underdata/is created automatically.frontend/(Vite config,App.tsx,api.ts, types, styles, and build config) that talks to the API and a simpleindex.htmlentry.backend/requirements.txt,backend/tests/test_api.pyintegration tests for API flows,README.mdwith setup notes, and a.gitignorefor common artifacts.Testing
pytest backend/testswhich executed the API integration tests inbackend/tests/test_api.py(2 tests) and they passed.POST /api/simulationsto create,GET /api/simulations/{id}to load,POST /api/simulations/{id}/planets/{planet_id}/influencefor interventions, andPOST /api/simulations/{id}/stepto advance time, all returning expected responses.Codex Task