# bhom/bhom_engine architecture

> Architecture diagram of the GitHub repository bhom/bhom_engine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bhom/bhom_engine
- Repository: https://github.com/bhom/bhom_engine

## Overview

##### Project type and purpose
- This is not a web app or database-backed system, but a monorepo of .NET/C# class-library projects that together form the “core engine” of the Buildings and Habitats object Model (BHoM).
- The README explains that each subproject (“Geometry_Engine”, “Spatial_Engine”, “Facade_Engine”, etc.) implements domain-specific processing functions for BHoM objects. Consumers (UIs, adapters, toolkits) reference these compiled assemblies or NuGet packages.

##### File structure
- Top‐level folders:
- <ci>: CI scripts, test datasets, build & packaging pipelines (AppVeyor, Azure DevOps, PowerShell).
- .github: templates and code‐owners.
- *.Engine subfolders: dozens of independent engine modules (each a .csproj library following a common folder layout: Compute, Create, Modify, Query, Objects, Convert).
- BHoM_Engine.sln: Visual Studio solution that ties all subprojects together.
- unit-tests, code: verification projects, solution files.
- Each engine project compiles into an assembly; they all reference a shared core (“BHoM_Engine” project) which provides base types (IObject, fragments, extension‐method runner), then domain modules add extension methods and algorithms.
- The CI folder holds JSON datasets for compliance tests, PowerShell scripts to build/test and .yml pipelines to orchestrate builds, unit tests, and NuGet packaging.

##### README insights
- The repo is the “Engine” layer of a larger ecosystem (other repos include the object definitions, adapters, UIs).
- There are links to documentation for how engines extend core objects via distributed extension-method algorithms.
- The build status badges show multi-stage CI (AppVeyor + Azure) culminating in a NuGet package.

a. Main components
- Core library (BHoM_Engine): defines shared types & the extension‐method execution engine.
- Domain engine libraries: Geometry_Engine, Spatial_Engine, Analytical_Engine, etc. (each a plugin implementing Compute/Create/Modify/Query).
- Test projects & datasets: unit-tests folder (C# test assemblies) and compliance datasets (.ci/Datasets JSON).
- CI/CD pipelines: .ci scripts & YAML definitions, AppVeyor + Azure DevOps.
b. Relationships and interactions
- CI pipelines trigger: clone → build solution → run unit tests using datasets → package domain and core into NuGet → publish.
c. Architectural patterns & design principles
- Modular plugin pattern: each domain is a separate assembly grouping related algorithms.
- Extension‐method dispatch: core engine uses reflection to discover and run Compute/Create/Modify/Query methods in domain modules.
- Separation of concerns: algorithms (Compute, Modify, Query) are distinguished by folder naming and interface conventions.
d. Key technologies, frameworks, libraries
- Language & runtime: C# targeting .NET Framework/Core.
- Build: MSBuild/Visual Studio solution (.sln, .csproj).
- CI/CD: AppVeyor & Azure DevOps pipelines, PowerShell scripts (.ps1), YAML definitions.
- Packaging: NuGet (.nuspec in .ci/Nuget).
- Testing: xUnit/NUnit (via Visual Studio .runsettings), JSON datasets for compliance tests.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Engine"
        Core["BHoM_Engine (Core)"]:::codeLibrary
    end

    subgraph "Domain Engines"
        Geometry["Geometry_Engine"]:::codeLibrary
        Spatial["Spatial_Engine"]:::codeLibrary
        Facade["Facade_Engine"]:::codeLibrary
        Analytical["Analytical_Engine"]:::codeLibrary
        Environment["Environment_Engine"]:::codeLibrary
        Serialiser["Serialiser_Engine"]:::codeLibrary
    end

    subgraph "Tests & Datasets"
        TestSuite["Unit-Test Projects"]:::test
        Datasets["Compliance Datasets"]:::test
    end

    subgraph "CI/CD Pipeline"
        Clone["Clone Repo"]:::ci
        Restore["Restore & Build"]:::ci
        RunTests["Run Tests"]:::ci
        Package["Package & Publish"]:::ci
    end

    NuGet["NuGet Registry"]:::ci

    subgraph "External Consumers"
        UI["BHoM_UI"]:::external
        Adapter["BHoM_Adapter"]:::external
        Toolkits["Other Toolkits"]:::external
    end

    Core -->|"compile-time reference"| Geometry
    Core -->|"compile-time reference"| Spatial
    Core -->|"compile-time reference"| Facade
    Core -->|"compile-time reference"| Analytical
    Core -->|"compile-time reference"| Environment
    Core -->|"compile-time reference"| Serialiser

    Core -->|"build & test"| TestSuite
    Geometry -->|"build & test"| TestSuite
    Spatial -->|"build & test"| TestSuite
    Facade -->|"build & test"| TestSuite
    Analytical -->|"build & test"| TestSuite
    Environment -->|"build & test"| TestSuite
    Serialiser -->|"build & test"| TestSuite

    Datasets -->|"feeds tests"| TestSuite

    Clone --> Restore
    Restore --> RunTests
    RunTests --> Package

    Core -->|"code source"| Restore
    Geometry -->|"code source"| Restore
    Spatial -->|"code source"| Restore
    Facade -->|"code source"| Restore
    Analytical -->|"code source"| Restore
    Environment -->|"code source"| Restore
    Serialiser -->|"code source"| Restore

    TestSuite -->|"test execution"| RunTests
    Datasets -->|"dataset input"| RunTests

    Package -->|"publish artifact"| NuGet

    NuGet -->|"runtime consumption"| UI
    NuGet -->|"runtime consumption"| Adapter
    NuGet -->|"runtime consumption"| Toolkits

    click Core "https://github.com/bhom/bhom_engine/tree/develop/BHoM_Engine/"
    click Geometry "https://github.com/bhom/bhom_engine/tree/develop/Geometry_Engine/"
    click Spatial "https://github.com/bhom/bhom_engine/tree/develop/Spatial_Engine/"
    click Facade "https://github.com/bhom/bhom_engine/tree/develop/Facade_Engine/"
    click Analytical "https://github.com/bhom/bhom_engine/tree/develop/Analytical_Engine/"
    click Environment "https://github.com/bhom/bhom_engine/tree/develop/Environment_Engine/"
    click Serialiser "https://github.com/bhom/bhom_engine/tree/develop/Serialiser_Engine/"
    click TestSuite "https://github.com/bhom/bhom_engine/tree/develop/.ci/unit-tests/"
    click Datasets "https://github.com/bhom/bhom_engine/tree/develop/.ci/Datasets/"
    click Clone "https://github.com/bhom/bhom_engine/blob/develop/.ci/CloneTest.ps1"
    click Package "https://github.com/bhom/bhom_engine/blob/develop/.ci/BHoMBot/Nuget/BHoM.Engine.nuspec"

    classDef codeLibrary fill:#cfe2f3,stroke:#036;
    classDef ci fill:#d9ead3,stroke:#090;
    classDef test fill:#fff2cc,stroke:#d89600;
    classDef external fill:#fce5cd,stroke:#e36c0a;
```
