# forefireapi/forefire architecture

> Architecture diagram of the GitHub repository forefireapi/forefire, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/forefireapi/forefire
- Repository: https://github.com/forefireapi/forefire

## Overview

#### Purpose and Deliverables
ForeFire is a C++ wildfire-spread simulation engine and embeddable library. It simulates fire-front propagation over geospatial, fuel, weather, and terrain inputs; supports fire–atmosphere coupling; and writes formats such as NetCDF, KML, and GeoJSON. The primary build graph is defined in `CMakeLists.txt`; the core library API starts at `src/CLibForeFire.h`.

#### Execution and Integration Entry Points
The main interactive/script interpreter is `app/forefire/ForeFire.cpp`, with line editing in `app/forefire/AdvancedLineEditor.cpp`. It accepts `.ff` command scripts and interactive commands, and can expose an HTTP command server via `src/HttpCommandServer.hpp`.  
Embedders use the C/C++ facade `src/CLibForeFire.cpp`. Python wraps this core through `bindings/python/src/pyforefire/_pyforefire.cpp` and provides a CLI in `bindings/python/src/pyforefire/_cli.py`; Java bindings are under `bindings/java/JLibForeFire.cpp`.

#### Simulation Orchestration
`src/Simulator.cpp` is the runtime coordinator: it advances simulation time and drives domain, events, data, and models. `src/FireDomain.cpp` owns the spatial/time simulation domain and its configured layers. `src/SimulationParameters.cpp` holds runtime parameters.  
Control flow is command-driven: parsed commands mutate/configure the simulator and domain, trigger ignition or model actions, then invoke stepping/output. Relevant paths: `src/Command.cpp`, `src/EventCommand.cpp`, `src/FFEvent.cpp`.

#### Fire Geometry and Evolution
The propagating state is represented as fire fronts composed of nodes and points. `src/FireFront.cpp` manages a front, `src/FireNode.cpp` models evolving front nodes, and `src/FFPoint.cpp` / `src/FFVector.cpp` supply spatial primitives. `src/BurningMap.cpp` provides gridded burn-state representation.  
The simulator queries local conditions, computes spread, advances node/front geometry, and updates burned-state/output layers.

#### Data-Layer Boundary
`src/DataBroker.cpp` mediates named data and model layers configured by scripts. The abstract layer contract is `src/DataLayer.h`; concrete layers cover fuel, weather, terrain-like gradients, time-varying fields, and NetCDF-backed data: `src/FuelDataLayer.h`, `src/WeatherDataLayer.h`, `src/NCXYZTDataLayer.h`.  
This separates model logic from data sources and permits external raster/NetCDF datasets to drive simulations.

#### Spread and Flux Model Plugins
`src/PropagationModel.cpp` defines the rate-of-spread model boundary. Alternative physical and empirical implementations live in `src/propagation/`, including `src/propagation/Rothermel.cpp`, `src/propagation/Balbi2020.cpp`, and `src/propagation/ANNPropagationModel.cpp`.  
Heat, vapor, spotting, and related fire-atmosphere source terms are abstracted by `src/FluxModel.cpp` and implementations in `src/flux/`, such as `src/flux/BurnupHeatFluxModel.cpp` and `src/flux/SpottingFluxBasicModel.cpp`.

#### Parallel and External Runtime Context
The CMake build can enable MPI for parallel execution and MesoNH fire–atmosphere coupling; parallel coordination is concentrated in `src/ParallelData.cpp` and `src/ParallelException.cpp`. NetCDF is a material data/output dependency, including for coupled scenarios. Python wheels intentionally disable MPI and bundle NetCDF.  
Deployment paths include `Dockerfile`, CMake-built native binaries/libraries, and Python packaging via `pyproject.toml`. Coupled-MesoNH installation guidance and case workflow assets are in `docs/mnh/coupledMNHInstall.md` and `tools/3nestFFCASE/`.

Main entry points: [`src/Simulator.cpp`](https://github.com/forefireapi/forefire/blob/master/src/Simulator.cpp) (Simulator), [`app/forefire/ForeFire.cpp`](https://github.com/forefireapi/forefire/blob/master/app/forefire/ForeFire.cpp) (ForeFire interpreter), [`src/CLibForeFire.cpp`](https://github.com/forefireapi/forefire/blob/master/src/CLibForeFire.cpp) (C/C++ facade), [`CMakeLists.txt`](https://github.com/forefireapi/forefire/blob/master/CMakeLists.txt) (CMake build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_interpreter["ForeFire interpreter<br/>native CLI<br/>[ForeFire.cpp]"]
  node_line_editor["Line editor<br/>CLI support"]
  node_http_server["HTTP command server<br/>command interface"]
  node_c_api["C/C++ facade<br/>embeddable API<br/>[CLibForeFire.cpp]"]
  node_python_binding["Python extension<br/>language binding<br/>[_pyforefire.cpp]"]
  node_python_cli["Python CLI<br/>package CLI<br/>[_cli.py]"]
  node_java_binding["Java binding<br/>language binding<br/>[JLibForeFire.cpp]"]
end

subgraph group_core["Simulation Core"]
  node_commands["Command &amp; event flow<br/>control layer<br/>[Command.cpp]"]
  node_simulator["Simulator<br/>runtime coordinator<br/>[Simulator.cpp]"]
  node_domain["Fire domain<br/>spatiotemporal domain<br/>[FireDomain.cpp]"]
  node_fire_front["Fire fronts<br/>evolving geometry<br/>[FireFront.cpp]"]
  node_burning_map["Burning map<br/>burn-state grid<br/>[BurningMap.cpp]"]
end

subgraph group_models["Models &amp; Data"]
  node_data_broker["Data broker<br/>layer registry<br/>[DataBroker.cpp]"]
  node_data_layers[("Data layers<br/>data boundary<br/>[DataLayer.h]")]
  node_propagation["Propagation models<br/>spread plugin boundary"]
  node_flux["Flux models<br/>atmospheric-source plugins<br/>[FluxModel.cpp]"]
end

subgraph group_runtime["Runtime &amp; Delivery"]
  node_cmake["CMake build<br/>build graph<br/>[CMakeLists.txt]"]
  node_parallel["Parallel runtime<br/>MPI coordination<br/>[ParallelData.cpp]"]
  node_netcdf[("NetCDF datasets &amp; output<br/>external data format<br/>[NCXYZTDataLayer.h]")]
  node_mesonh["MesoNH coupling<br/>atmosphere integration"]
end

node_cmake -->|"builds"| node_interpreter
node_cmake -->|"builds"| node_c_api
node_cmake -.->|"enables optionally"| node_parallel
node_interpreter -->|"uses"| node_line_editor
node_interpreter -->|"submits commands"| node_commands
node_interpreter -.->|"may expose"| node_http_server
node_http_server -->|"accepts commands"| node_commands
node_c_api -->|"embeds"| node_simulator
node_python_binding -->|"wraps"| node_c_api
node_python_cli -->|"invokes"| node_python_binding
node_java_binding -->|"wraps"| node_c_api
node_commands -->|"configures and triggers"| node_simulator
node_simulator -->|"advances"| node_domain
node_simulator -->|"queries layers"| node_data_broker
node_simulator -->|"computes spread"| node_propagation
node_simulator -->|"computes source terms"| node_flux
node_domain -->|"owns evolving fronts"| node_fire_front
node_fire_front -->|"updates burned state"| node_burning_map
node_data_broker -->|"resolves"| node_data_layers
node_data_layers -->|"reads"| node_netcdf
node_simulator -.->|"coordinates optionally"| node_parallel
node_flux -.->|"supports coupling"| node_mesonh
node_netcdf -.->|"exchanges coupled data"| node_mesonh

click node_cmake "https://github.com/forefireapi/forefire/blob/master/CMakeLists.txt"
click node_interpreter "https://github.com/forefireapi/forefire/blob/master/app/forefire/ForeFire.cpp"
click node_line_editor "https://github.com/forefireapi/forefire/blob/master/app/forefire/AdvancedLineEditor.cpp"
click node_http_server "https://github.com/forefireapi/forefire/blob/master/src/HttpCommandServer.hpp"
click node_c_api "https://github.com/forefireapi/forefire/blob/master/src/CLibForeFire.cpp"
click node_python_binding "https://github.com/forefireapi/forefire/blob/master/bindings/python/src/pyforefire/_pyforefire.cpp"
click node_python_cli "https://github.com/forefireapi/forefire/blob/master/bindings/python/src/pyforefire/_cli.py"
click node_java_binding "https://github.com/forefireapi/forefire/blob/master/bindings/java/JLibForeFire.cpp"
click node_commands "https://github.com/forefireapi/forefire/blob/master/src/Command.cpp"
click node_simulator "https://github.com/forefireapi/forefire/blob/master/src/Simulator.cpp"
click node_domain "https://github.com/forefireapi/forefire/blob/master/src/FireDomain.cpp"
click node_fire_front "https://github.com/forefireapi/forefire/blob/master/src/FireFront.cpp"
click node_burning_map "https://github.com/forefireapi/forefire/blob/master/src/BurningMap.cpp"
click node_data_broker "https://github.com/forefireapi/forefire/blob/master/src/DataBroker.cpp"
click node_data_layers "https://github.com/forefireapi/forefire/blob/master/src/DataLayer.h"
click node_propagation "https://github.com/forefireapi/forefire/blob/master/src/PropagationModel.cpp"
click node_flux "https://github.com/forefireapi/forefire/blob/master/src/FluxModel.cpp"
click node_parallel "https://github.com/forefireapi/forefire/blob/master/src/ParallelData.cpp"
click node_netcdf "https://github.com/forefireapi/forefire/blob/master/src/NCXYZTDataLayer.h"
click node_mesonh "https://github.com/forefireapi/forefire/blob/master/docs/mnh/coupledMNHInstall.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_interpreter,node_line_editor,node_http_server,node_c_api,node_python_binding,node_python_cli,node_java_binding toneBlue
class node_commands,node_simulator,node_domain,node_fire_front,node_burning_map toneAmber
class node_data_broker,node_data_layers,node_propagation,node_flux toneMint
class node_cmake,node_parallel,node_netcdf,node_mesonh toneRose
```

## Components

### Entry Points

- [ForeFire interpreter](https://github.com/forefireapi/forefire/blob/master/app/forefire/ForeFire.cpp): native CLI · Executes interactive commands and .ff scripts. · `app/forefire/ForeFire.cpp`
- [Line editor](https://github.com/forefireapi/forefire/blob/master/app/forefire/AdvancedLineEditor.cpp): CLI support · `app/forefire/AdvancedLineEditor.cpp`
- [HTTP command server](https://github.com/forefireapi/forefire/blob/master/src/HttpCommandServer.hpp): command interface · `src/HttpCommandServer.hpp`
- [C/C++ facade](https://github.com/forefireapi/forefire/blob/master/src/CLibForeFire.cpp): embeddable API · `src/CLibForeFire.cpp`
- [Python extension](https://github.com/forefireapi/forefire/blob/master/bindings/python/src/pyforefire/_pyforefire.cpp): language binding · `bindings/python/src/pyforefire/_pyforefire.cpp`
- [Python CLI](https://github.com/forefireapi/forefire/blob/master/bindings/python/src/pyforefire/_cli.py): package CLI · `bindings/python/src/pyforefire/_cli.py`
- [Java binding](https://github.com/forefireapi/forefire/blob/master/bindings/java/JLibForeFire.cpp): language binding · `bindings/java/JLibForeFire.cpp`

### Simulation Core

- [Command & event flow](https://github.com/forefireapi/forefire/blob/master/src/Command.cpp): control layer · Parses commands and creates simulation events. · `src/Command.cpp`
- [Simulator](https://github.com/forefireapi/forefire/blob/master/src/Simulator.cpp): runtime coordinator · Advances time and coordinates domain, events, data, and models. · `src/Simulator.cpp`
- [Fire domain](https://github.com/forefireapi/forefire/blob/master/src/FireDomain.cpp): spatiotemporal domain · Owns configured simulation layers and spatial state. · `src/FireDomain.cpp`
- [Fire fronts](https://github.com/forefireapi/forefire/blob/master/src/FireFront.cpp): evolving geometry · Fronts and nodes represent propagating fire perimeter state. · `src/FireFront.cpp`
- [Burning map](https://github.com/forefireapi/forefire/blob/master/src/BurningMap.cpp): burn-state grid · `src/BurningMap.cpp`

### Models & Data

- [Data broker](https://github.com/forefireapi/forefire/blob/master/src/DataBroker.cpp): layer registry · Resolves named data and model layers configured by scripts. · `src/DataBroker.cpp`
- [Data layers](https://github.com/forefireapi/forefire/blob/master/src/DataLayer.h): data boundary · Abstract fuel, weather, terrain, temporal, and NetCDF inputs. · `src/DataLayer.h`
- [Propagation models](https://github.com/forefireapi/forefire/blob/master/src/PropagationModel.cpp): spread plugin boundary · Selects rate-of-spread implementations such as Rothermel or Balbi. · `src/PropagationModel.cpp`
- [Flux models](https://github.com/forefireapi/forefire/blob/master/src/FluxModel.cpp): atmospheric-source plugins · Provides heat, vapor, and spotting source terms. · `src/FluxModel.cpp`

### Runtime & Delivery

- [CMake build](https://github.com/forefireapi/forefire/blob/master/CMakeLists.txt): build graph · Builds native binaries, library, and optional MPI/coupling features. · `CMakeLists.txt`
- [Parallel runtime](https://github.com/forefireapi/forefire/blob/master/src/ParallelData.cpp): MPI coordination · Optional parallel execution and coupled-runtime coordination. · `src/ParallelData.cpp`
- [NetCDF datasets & output](https://github.com/forefireapi/forefire/blob/master/src/NCXYZTDataLayer.h): external data format · Material raster/coupled input and simulation output dependency. · `src/NCXYZTDataLayer.h`
- [MesoNH coupling](https://github.com/forefireapi/forefire/blob/master/docs/mnh/coupledMNHInstall.md): atmosphere integration · Optional fire–atmosphere coupled execution. · `docs/mnh/coupledMNHInstall.md`

## Connections

- CMake build → ForeFire interpreter: builds
- CMake build → C/C++ facade: builds
- CMake build → Parallel runtime: enables optionally
- ForeFire interpreter → Line editor: uses
- ForeFire interpreter → Command & event flow: submits commands
- ForeFire interpreter → HTTP command server: may expose
- HTTP command server → Command & event flow: accepts commands
- C/C++ facade → Simulator: embeds
- Python extension → C/C++ facade: wraps
- Python CLI → Python extension: invokes
- Java binding → C/C++ facade: wraps
- Command & event flow → Simulator: configures and triggers
- Simulator → Fire domain: advances
- Simulator → Data broker: queries layers
- Simulator → Propagation models: computes spread
- Simulator → Flux models: computes source terms
- Fire domain → Fire fronts: owns evolving fronts
- Fire fronts → Burning map: updates burned state
- Data broker → Data layers: resolves
- Data layers → NetCDF datasets & output: reads
- Simulator → Parallel runtime: coordinates optionally
- Flux models → MesoNH coupling: supports coupling
- NetCDF datasets & output → MesoNH coupling: exchanges coupled data
