How bxrne/launchrail works
Project type and purpose
• Launchrail is an open-source, Go-based 6DOF rocket simulator with both a CLI entrypoint (cmd/launchrail, cmd/benchmark) and an HTTP server/web UI (cmd/server, static/, templates/).
• It ingests OpenRocket design files, fetches motor curves from the ThrustCurve API and weather data, runs a physics simulation (using internal/pkg modules), persists results, and renders reports/plots.
File-structure analysis
• Top-level command directories:
• cmd/launchrail – main CLI to run simulations interactively or script-driven.
• cmd/benchmark – CLI for performance benchmarks.
• cmd/server – HTTP server exposing REST endpoints and serving a browser UI.
• Core logic split into:
• internal/ – configuration, logging, HTTP client wrappers, plugin manager, simulation orchestration, storage, report generation, plot transformation.
• pkg/ – pure-logic libraries: physics (atmosphere, drag, thrustcurves, barrowman), state integration, entity definitions, OpenRocket schema parsing, plugin interfaces.
• UI assets and templates under static/ and templates/.
• API specification in docs/openapi.yaml with embedded Swagger UI.
• Config file: config.yaml; Dockerfile, GitHub workflows for CI/CD, Docker publish, linting, benchmarking.
Core components
a. CLI layer
• “launchrail” and “benchmark” binaries
• Triggers simulation engine directly, reads OpenRocket files, writes reports to disk.
b. HTTP server layer
• REST API handlers (cmd/server/handlers.go)
• Static asset server (HTML/JS/CSS) + Swagger UI
• JSON endpoints to start simulations, retrieve data, fetch reports.
c. Simulation engine
• Orchestrator (internal/simulation/manager.go)
• Calls into pkg/systems, pkg/simulation, pkg/* libraries for physics, thrust curves, state updates.
• Plugin manager (internal/plugin) loads/executes extension hooks (e.g., financial turbulence models).
d. Storage layer
• Storage abstraction (internal/storage) for saving simulation records, retrieving past runs.
e. Reporting & visualization
• Report generator (internal/reporting) produces markdown/HTML reports.
• Plot transformer (internal/plot_transformer) prepares chart data for UI.
f. Config & logging
• Config loader (internal/config)
• Logger (internal/logger)
g. External integrations
• OpenRocket file reader (pkg/openrocket) – ingestion, schema parsing.
• ThrustCurve API client (internal/http_client)
• Weather service client (internal/weather)
Relationships and data flows
• CLI or HTTP request → Config loader + Logger → Simulation manager
• Simulation manager ↔ pkg physics libraries → computes trajectories
• Simulation manager → Plugin manager → optional plugins → back to simulation manager
• Simulation manager → Storage layer → persist raw data
• Storage layer → Reporting module → generate report artifacts
• Reporting module + Plot transformer → UI or CLI output
• HTTP server also calls HTTP-client modules to fetch ThrustCurve and weather data before/during simulation.
• UI (browser) ↔ HTTP server via REST (JSON) and static assets for chart rendering.
Architectural patterns & principles
• Layered architecture: CLI/HTTP → Orchestrator → Core libs → Storage → Reporting
• Plugin-based extension: internal/plugin + plugins/ directory, uses Go interfaces for extensibility.
• Separation of concerns: pure-logic in pkg/, infrastructure in internal/.
• Configuration-driven: behavior controlled via config.yaml and flags.
• Web MVC for server: Handlers → Templates + Static assets → UI.