# gasmith/foxglove-lunar-lander architecture

> Architecture diagram of the GitHub repository gasmith/foxglove-lunar-lander, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gasmith/foxglove-lunar-lander
- Repository: https://github.com/gasmith/foxglove-lunar-lander

## Overview

Step 1. Identify the Main Components
────────────────────────────────────────────
Based on both the file tree and README, the key parts of this project include:

A. Simulation Engine (Main Process)
- Represented by src/main.rs and coordinated modules.
- It ties together physics, control input, asset handling, and output communication.

B. Lander Physics/Simulation Module
- Located in src/lander (includes controllers.rs) and other related files.
- Handles the physics of the Apollo lunar lander including attitude, velocity, and landing behavior.

C. Landscape and Environment Module
- Found in src/landscape (e.g., height_map.rs, landing_zone.rs).
- Responsible for generating/handling the simulation’s terrain and landing zones.

D. Controls and Gamepad Input Module
- Seen in src/controls and src/controls/gamepad.rs.
- Processes input data from gamepads (like the PS4 controller as described in the README).

E. Foxglove Integration and Communication Module
- Likely implemented in modules such as src/listener.rs.
- Creates and maintains the live websocket connection (ws://localhost:8765) to Foxglove Desktop for UI and visualization.

F. Assets Module
- Referenced by src/assets.rs and the assets directory (apollo.dae, apollo.stl).
- Provides the 3D model data required for rendering within Foxglove.

G. External Foxglove Desktop UI
- Although external to the core simulation, it is crucial since the simulator publishes data invoked by the Foxglove SDK and consumed by the desktop app layouts.

Step 2. Define Relationships and Data Flow
────────────────────────────────────────────
- D (Controls/Input) sends data (e.g., joystick commands) to A (Simulation Engine), which uses this input to update the state of B (Lander Physics) and C (Landscape).
- The updated simulation state, including positional data and other telemetry, flows from A/B/C to E (Foxglove Communication), which then publishes it to G (Foxglove Desktop UI).
- F (Assets) is utilized by A (Simulation Engine) whenever a reference to models, such as the Apollo lunar lander, is needed for rendering or state referencing.
- Additionally, there can be feedback loops (if applicable) where the desktop UI commands or user interactions could cause changes back in the simulation loop.

Step 3. Recognize Architectural Patterns & Principles
────────────────────────────────────────────
- The project follows a modular design pattern with clear separation of responsibilities:
– Simulation Core (A, B, C) which handles the game logic.
– Input Layer (D) decoupled from simulation logic.
– Communication Layer (E) that isolates the specifics of interfacing with Foxglove.
- This separation enables independent development, testing, and potential future extension (for example, embedding more features in the Foxglove UI).

────────────────────────────────────────────
- Since this is a simulation server leveraging an external UI, emphasize the clear separation between the simulation (A, B, C, D, F) and the visualization/interaction component (G).
– A → E to show that the simulation pushes data for visualization.
– D → A to represent controller input affecting simulation state.
- Assign each component a single character ID:
A: Simulation Engine (Main)
B: Lander Physics
C: Landscape Environment
D: Controls/Gamepad Input
E: Foxglove Communication (Websocket Server)
F: Assets (Apollo Models)
G: External Foxglove Desktop UI

────────────────────────────────────────────
##### F (Assets) linked to A to reflect dependency on external models.
– From D to A and from A to B, C, E, and from E to G.

## Diagram (Mermaid)

```mermaid
flowchart TD
    D["D – Controls"]:::input
    A["A – Engine"]:::engine
    F["F – Assets"]:::engine
    B["B – Physics"]:::engine
    C["C – Env"]:::engine
    E["E – Foxglove Comm"]:::comm
    G["G – Foxglove Desktop UI"]:::ui

    D -->|"input"| A
    A -->|"models"| F
    A -->|"update"| B
    A -->|"update"| C
    A -->|"publish"| E
    B -->|"state"| E
    C -->|"state"| E
    E -->|"send"| G

    click A "https://github.com/gasmith/foxglove-lunar-lander/blob/main/src/main.rs"
    click B "https://github.com/gasmith/foxglove-lunar-lander/tree/main/src/lander"
    click C "https://github.com/gasmith/foxglove-lunar-lander/tree/main/src/landscape"
    click D "https://github.com/gasmith/foxglove-lunar-lander/tree/main/src/controls"
    click E "https://github.com/gasmith/foxglove-lunar-lander/blob/main/src/listener.rs"
    click F "https://github.com/gasmith/foxglove-lunar-lander/blob/main/src/assets.rs"

    classDef engine fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef input fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef comm fill:#FFB6C1,stroke:#000,stroke-dasharray: 5,5,stroke-width:2px;
    classDef ui fill:#90EE90,stroke:#000,stroke-width:2px;
```
