Skip to content

Add Grand Simulations: FastAPI backend, simulation engine, SQLite storage and React + Vite frontend - #2

Open
Kskip310 wants to merge 1 commit into
mainfrom
codex/build-cosmic-god-simulation-sandbox-baseline-1f7cd1
Open

Add Grand Simulations: FastAPI backend, simulation engine, SQLite storage and React + Vite frontend#2
Kskip310 wants to merge 1 commit into
mainfrom
codex/build-cosmic-god-simulation-sandbox-baseline-1f7cd1

Conversation

@Kskip310

Copy link
Copy Markdown
Owner

Motivation

  • Provide a playable, seeded cosmic sandbox with a REST API and interactive frontend to observe and influence simulated worlds.
  • Persist simulation state so universes can be saved, loaded, stepped, and influenced over time.
  • Expose a compact API surface for creating simulations, stepping time, and applying overseer influences.

Description

  • Add a FastAPI application at backend/app/main.py exposing /api/health, /api/simulations, creation, retrieval, stepping (/step) and planet influence endpoints, with request/response models in backend/app/models.py.
  • Implement a deterministic procedural simulation engine in backend/app/simulation.py that generates systems/planets, computes surface grids, species, life/civilization progression, alerts, and supports step_simulation and apply_influence operations.
  • Add persistent storage using SQLite in backend/app/storage.py with init_db, save_simulation, load_simulation, and list_simulations, and ensure DB path under data/ is created automatically.
  • Provide a React + TypeScript frontend scaffold under frontend/ (Vite config, App.tsx, api.ts, types, styles, and build config) that talks to the API and a simple index.html entry.
  • Add backend/requirements.txt, backend/tests/test_api.py integration tests for API flows, README.md with setup notes, and a .gitignore for common artifacts.

Testing

  • Ran the backend test suite with pytest backend/tests which executed the API integration tests in backend/tests/test_api.py (2 tests) and they passed.
  • Exercised the main flows covered by tests: POST /api/simulations to create, GET /api/simulations/{id} to load, POST /api/simulations/{id}/planets/{planet_id}/influence for interventions, and POST /api/simulations/{id}/step to advance time, all returning expected responses.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread backend/app/simulation.py
universe_rng = _rng(seed, "universe")
systems = [_system_summary(seed, index) for index in range(universe_rng.randint(3, 5))]
state = {
"id": f"sim-{seed}",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread backend/app/simulation.py
Comment on lines +722 to +724
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant