How josh-weston-g/orbit-sandbox works
1. Repository shape
- This is a desktop simulation app, not a web service.
- The architecture is split into four main areas: app shell (main.py), physics/domain (orbit/), UI/views (ui/), and data/assets (data/, assets/).
2. Runtime and UI stack
- The app is built in Python 3.8+ and uses NumPy for vector math.
- Rendering and interaction are handled by Pygame, with pygame_gui used for menus and UI widgets.
- The UI is therefore a real-time game/simulation loop rather than a request/response interface.
3. Application entry and orchestration
- main.py is the top-level entry point and is responsible for the main loop, resolution selection, and switching between views/screens.
- It acts as the coordinator between the menu system, system loading, and the live simulation view.
4. Domain model
- orbit/body.py defines the core physical entity: a body with mass, position, velocity, acceleration, name, and type.
- This is the smallest unit shared by the loader, physics engine, and renderer.
5. Physics layer
- orbit/physics.py contains the Newtonian gravity logic and orbital mechanics formulas.
- This layer is the pure math boundary: it computes forces/accelerations without handling UI, file I/O, or rendering.
6. Simulation engine
- orbit/simulation.py owns the N-body integration loop and state evolution over time.
- It uses Velocity Verlet integration for position/velocity updates and maintains a history stack for rewind.
- This is the main stateful core of the app: it consumes bodies and physics, then produces successive simulation states.
7. Units and constants
- orbit/units.py centralizes the simulation’s unit system and gravitational constant defaults.
- The repo uses astronomical units and solar-mass style scaling, which keeps the physics readable and consistent across presets and custom systems.
8. System loading boundary
- orbit/loader.py bridges file-based configuration into runtime simulation objects.
- It reads JSON system definitions from data/default_systems/ and user-defined systems from data/custom_systems/, then instantiates bodies/simulations from those definitions.
- This is the repository’s key data ingestion boundary.
9. UI structure
- ui/views.py defines screen-level views such as the main menu, load-system menu, and simulation view.
- ui/visualize.py contains the live simulation runner, handling drawing, camera controls, overlays, and user interaction during playback.
- The UI layer consumes simulation state; it should not own the physics rules.
10. Assets and presentation data
- assets/fonts/, assets/images/, and assets/themes/ are presentation resources used by the menu and simulation HUD.
- The theme JSON files are particularly important because they define pygame_gui styling and visual consistency across menus.
11. Simulation data sets
- data/default_systems/ contains the built-in scenarios such as binary stars, solar-system variants, escape trajectories, and three-body setups.
- data/custom_systems/ is the extension point for user-created scenarios, making system definitions content-driven rather than code-driven.
12. Main data flow
- At startup, the app discovers available system JSON files.
- The user selects a system in the UI.
- The loader turns JSON into bodies and simulation parameters.
- The simulation engine advances the system state each frame.
- The renderer draws the current state and reacts to camera/time-control input.
13. Architectural boundaries
- The strongest boundary is between pure simulation logic (orbit/) and presentation/UI (ui/).
- File-based scenario definitions form a second boundary: the app can add or change systems without changing physics code.
- There is no evidence of persistence beyond JSON files, and no network or server layer.
14. Diagram takeaway
- For an architecture diagram, show one top-level desktop app loop feeding three subsystems: UI/navigation, system loading, and physics simulation.
- Under physics, show body model + unit constants + gravitational acceleration + time integration/history.
- Under UI, show menu screens, simulation visualization, and input controls.
- Under data, show built-in and custom JSON systems plus theme/image/font assets.
Main entry points: views.py Views · visualize.py Visualizer · simulation.py Integrator · loader.py Loader
Components 16
App shell
Entry point and runtime orchestration.
- Main loop · Starts the app, selects resolution, and switches between screens.
main.py
Physics core
Domain model, math, integration, and loading.
- Body · Core physical entity shared across loading, simulation, and rendering.
orbit/body.py - Units · Simulation unit system and gravitational defaults.
orbit/units.py - Gravity · Newtonian gravity and orbital mechanics calculations.
orbit/physics.py - Integrator · N-body evolution, velocity Verlet updates, and rewind history.
orbit/simulation.py - Loader · Reads system JSON and builds runtime simulation objects.
orbit/loader.py
UI layer
Menus, screen views, and real-time visualization.
- Views · Defines the menu and simulation screen-level views.
ui/views.py - Visualizer · Draws live simulation state and handles camera and playback interaction.
ui/visualize.py
Content
Scenario definitions and presentation assets.
- Default systems · Built-in JSON presets for common orbital setups.
data/default_systems - Custom systems · User-defined JSON scenarios added without code changes.
data/custom_systems - Themes · pygame_gui theme files for menus and HUD styling.
assets/themes - Fonts · Typeface resources used by the interface.
assets/fonts - Images · Image resources for menus and simulation presentation.
assets/images - Menu theme · Theme configuration for the main menu UI.
assets/themes/main_menu_theme.json - Load theme · Theme configuration for the load-system menu.
assets/themes/load_system_theme.json - Pause theme · Theme configuration for the pause menu.
assets/themes/pause_menu_theme.json
Connections 20
- Main loop → Views: navigates · Routes between menu and simulation screens.
- Main loop → Loader: loads system · Turns the selected scenario into runtime objects.
- Main loop → Integrator: runs · Advances the active simulation each frame.
- Views → Default systems: lists · Shows built-in scenarios in the menu.
- Views → Custom systems: lists · Exposes user-created scenarios in the menu.
- Loader → Body: creates · Builds bodies from system definitions.
- Loader → Units: applies · Uses the shared unit system when constructing simulations.
- Loader → Integrator: initializes · Creates simulation state from loaded scenario data.
- Integrator → Gravity: uses · Computes forces and accelerations for each update.
- Integrator → Body: updates · Mutates body positions and velocities over time.
- Gravity → Units: depends on · Uses the shared constants and scaling choices.
- Visualizer → Integrator: renders · Reads current state for drawing and overlays.
- Visualizer → Views: receives input · Handles playback, camera, and UI interactions.
- Views → Visualizer: opens · Switches into the live simulation view.
- Views → Menu theme: styles · Uses menu styling for the main menu.
- Views → Load theme: styles · Uses menu styling for load-system screens.
- Views → Pause theme: styles · Uses menu styling for pause screens.
- Visualizer → Fonts: uses · Loads fonts for HUD and labels.
- Visualizer → Images: uses · Loads image assets for presentation.
- Views → Themes: loads · Consumes theme resources for pygame_gui widgets.