# thatopen/engine_fragment architecture

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

- Interactive diagram: https://gitdiagram.com/thatopen/engine_fragment
- Repository: https://github.com/thatopen/engine_fragment

## Overview

##### Project type and purpose
- This is an open-source, node/ browser library (“Fragments”) for storing, displaying, navigating, and editing massive BIM (Building Information Modeling) data.
- It provides:
- A binary format defined via FlatBuffers schemas
- A TypeScript/JavaScript importer/exporter (IfcImporter) for IFC data
- A high-performance 3D viewer built atop Three.js
- Utility modules, multithreading support via Web Workers
- Example/demo pages illustrating integration pathways

##### File structure
- Top-level monorepo layout:
- /.github, CI/CD configs, package.json, babel/vite/jest configs, examples/ (demo HTML + JS bundles)
- /packages/fragments: the main library
– /flatbuffers: the .fbs schema + FlatBuffers compiler
– /src: core modules, subdivided into
· Importers/IfcImporter (geometry & property processors, file readers)
· Schema (TS definitions mirroring .fbs)
· Utils (event bus, data maps, converters)
– build configs (tsconfig, vite configs)
- Key patterns:
- Layered architecture: Importer → Data Format → Core Engine → Rendering
- Web Worker threads to offload heavy computation (multithreading folder, vite.config-worker.ts)
- Examples folder demonstrating consumption in a browser environment

##### README for additional insights
- Emphasizes FlatBuffers for cross-platform serialization
- Mentions support for frontend and backend (Node.js) via the same Importer
- Highlights core features: filtering, raycasting, highlighting, snap interactions

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Systems"
        IFC["IFC Data Source"]:::external
        FLAT_RT["Google FlatBuffers Runtime"]:::external
        THREE["Three.js"]:::external
        WORKER_ENV["Web Worker Env"]:::external
        NODE["Node.js (optional)"]:::external
    end

    subgraph "Library Modules"
        subgraph "Importers"
            IfcImporter["IfcImporter Module"]:::importer
        end
        subgraph "Data Format Schema"
            FB_Schema["FlatBuffers Schema"]:::schema
            FB_Compiler["Schema Compiler"]:::schema
            TS_Bindings["TS FlatBuffers Bindings"]:::schema
        end
        subgraph "Utils"
            Utils["Utility Modules"]:::utils
            FB_JSON["FlatBuffers JSON Converter"]:::utils
        end
        subgraph "Core Engine"
            CoreIndex["FragmentsModels Entry"]:::core
            subgraph "Managers"
                Bounding["Bounding-Box Managers"]:::core
                LOD["LOD Managers"]:::core
                ModelMgr["Model Managers"]:::core
            end
            subgraph "Multithreading"
                MT["Multithreading Support"]:::core
                MT_Helper["Multithreading Helper"]:::core
            end
            subgraph "Virtual Model"
                Virtual["Virtual Model Layer"]:::core
            end
            subgraph "Core Utils"
                GeoUtils["Geometry Utils & Event Bus"]:::core
            end
        end
        subgraph "Rendering Layer"
            Renderer["Three.js Scene/Camera/Renderer"]:::render
        end
    end

    subgraph "Examples/Demos"
        DemoCore["Core Engine Demos"]:::example
        DemoImp["Importer Demos"]:::example
        MonoExamples["Monorepo Examples"]:::example
    end

    IFC -->|"load IFC"| IfcImporter
    IfcImporter -->|"raw geometry + props"| FB_Schema
    FB_Schema -->|"compile .fbs"| FB_Compiler
    FB_Schema -->|"generate binary"| TS_Bindings
    TS_Bindings -->|"JS objects"| CoreIndex
    CoreIndex -->|"manage models"| Bounding
    CoreIndex -->|"manage LOD"| LOD
    CoreIndex -->|"manage meshes"| ModelMgr
    CoreIndex -->|"use utils"| GeoUtils
    CoreIndex -->|"spawnWorker()"| MT
    MT -->|"helper functions"| MT_Helper
    CoreIndex -->|"virtualize"| Virtual
    CoreIndex -->|"renderFrame()"| Renderer
    Renderer -->|"renders via"| THREE
    IfcImporter -->|"serialize()"| FB_JSON
    IfcImporter -->|"run in Node.js"| NODE
    CoreIndex -->|"offload"| WORKER_ENV
    FLAT_RT -->|"runtime support"| FB_Schema
    DemoCore -->|"demo uses"| CoreIndex
    DemoImp -->|"demo uses"| IfcImporter
    MonoExamples -->|"various demos"| DemoCore

    click IfcImporter "https://github.com/thatopen/engine_fragment/tree/main/packages/fragments/src/Importers/IfcImporter"
    click FB_Schema "https://github.com/thatopen/engine_fragment/blob/main/packages/fragments/flatbuffers/index.fbs"
    click FB_Compiler "https://github.com/thatopen/engine_fragment/blob/main/packages/fragments/flatbuffers/delete-schema.mjs"
    click TS_Bindings "https://github.com/thatopen/engine_fragment/tree/main/packages/fragments/src/Schema"
    click CoreIndex "https://github.com/thatopen/engine_fragment/blob/main/packages/fragments/src/FragmentsModels/index.ts"
    click Bounding "https://github.com/thatopen/engine_fragment/tree/main/packages/fragments/src/FragmentsModels/src/bounding-boxes"
    click LOD "https://github.com/thatopen/engine_fragment/tree/main/packages/fragments/src/FragmentsModels/src/lod"
    click ModelMgr "https://github.com/thatopen/engine_fragment/tree/main/packages/fragments/src/FragmentsModels/src/model"
    click MT "https://github.com/thatopen/engine_fragment/tree/main/packages/fragments/src/FragmentsModels/src/multithreading"
    click MT_Helper "https://github.com/thatopen/engine_fragment/blob/main/packages/fragments/src/FragmentsModels/src/multithreading/multithreading-helper.ts"
    click Virtual "https://github.com/thatopen/engine_fragment/tree/main/packages/fragments/src/FragmentsModels/src/virtual-model"
    click GeoUtils "https://github.com/thatopen/engine_fragment/tree/main/packages/fragments/src/FragmentsModels/src/utils"
    click Renderer "https://github.com/thatopen/engine_fragment/blob/main/packages/fragments/src/FragmentsModels/src/index.ts"
    click Utils "https://github.com/thatopen/engine_fragment/tree/main/packages/fragments/src/Utils"
    click FB_JSON "https://github.com/thatopen/engine_fragment/blob/main/packages/fragments/src/Utils/flatbuffers-json-converter.ts"
    click DemoCore "https://github.com/thatopen/engine_fragment/blob/main/packages/fragments/src/FragmentsModels/example.html"
    click DemoImp "https://github.com/thatopen/engine_fragment/blob/main/packages/fragments/src/Importers/IfcImporter/example.html"
    click MonoExamples "https://github.com/thatopen/engine_fragment/tree/main/examples/FragmentsModels"

    classDef external fill:#f9c784,stroke:#e69500,color:#000
    classDef importer fill:#a8d0e6,stroke:#216583,color:#000
    classDef schema fill:#a8d0e6,stroke:#216583,color:#000
    classDef utils fill:#b8e0d2,stroke:#2e7d32,color:#000
    classDef core fill:#d0bdf4,stroke:#5e35b1,color:#000
    classDef render fill:#c8facc,stroke:#388e3c,color:#000
    classDef example fill:#ffd1dc,stroke:#c2185b,color:#000
```
