# bitbybit-dev/bitbybit architecture

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

- Interactive diagram: https://gitdiagram.com/bitbybit-dev/bitbybit
- Repository: https://github.com/bitbybit-dev/bitbybit

## Overview

##### Main Components
- CAD Kernels/3D Algorithms: Represent the external or internal kernels such as JSCAD, Manifold, and OpenCascade.
- Rendering Engines: Represent BabylonJS and ThreeJS as separate integrated engines (or modules) that connect with the underlying geometry packages.
- Web Worker Layer: Highlight the worker packages that allow non-blocking asynchronous processing of geometry computations.

##### Relationships and Interactions
- That the “core” package aggregates functionality from various lower-level packages (such as “base” and the CAD kernel wrappers).
- “engine integrations” (BabylonJS and ThreeJS) as specialized layers – for example, the @bitbybit-dev/babylonjs and @bitbybit-dev/threejs packages have dependencies on the underlying CAD and core algorithms.
- Web worker packages with their corresponding main packages (for JSCAD, Manifold, and OCCT), indicating that calls to these libraries can be offloaded to the workers.
- That “base” provides foundational algorithms (like vector math) that feed into all upper-level components.
- From the core algorithm layer (and base) to the rendering engine layers.
- From the computational kernels to the worker wrappers that deliver asynchronous processing.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The refactoring away from a BabylonJS-dependent UI to a game-engine–independent core illustrates decoupling.
- Worker Offloading: The existence of dedicated “-worker” modules indicates a design pattern for concurrency and non-blocking operations.
- API Wrapping: Several packages serve as wrappers to enrich existing libraries or to add extended algorithms – show the layering where higher-level API wrappers depend on the lower-level geometry kernel services.

##### Relevant Technologies and Frameworks
- That TypeScript is used for these packages (visible by the .ts files and tsconfig files) and that Babel is used as a build/bundling tool (babel.config.cjs files).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Foundational Layers
    subgraph "Foundational Layers"
        base["@bitbybit-dev/base"]:::baseFoundation
        core["@bitbybit-dev/core"]:::core
        base -->|"aggregates"| core
    end

    %% CAD Kernel Wrappers
    subgraph "CAD Kernel Wrappers"
        jscad["@bitbybit-dev/jscad"]:::cadWrapper
        manifold["@bitbybit-dev/manifold"]:::cadWrapper
        occt["@bitbybit-dev/occt"]:::cadWrapper
        jscad -->|"provides"| core
        manifold -->|"provides"| core
        occt -->|"provides"| core
    end

    %% Engine Integrations
    subgraph "Engine Integrations"
        babylonjs["@bitbybit-dev/babylonjs"]:::engine
        threejs["@bitbybit-dev/threejs"]:::engine
        core -->|"renders_in"| babylonjs
        core -->|"renders_in"| threejs
    end

    %% Web Worker Layers
    subgraph "Web Worker Layers"
        jscad_worker["@bitbybit-dev/jscad-worker"]:::worker
        manifold_worker["@bitbybit-dev/manifold-worker"]:::worker
        occt_worker["@bitbybit-dev/occt-worker"]:::worker
        jscad -->|"asynchronous"| jscad_worker
        manifold -->|"asynchronous"| manifold_worker
        occt -->|"asynchronous"| occt_worker
    end

    %% Click Events
    click base "https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/base"
    click core "https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/core"
    click babylonjs "https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/babylonjs"
    click threejs "https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/threejs"
    click jscad "https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/jscad"
    click jscad_worker "https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/jscad-worker"
    click manifold "https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/manifold"
    click manifold_worker "https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/manifold-worker"
    click occt "https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/occt"
    click occt_worker "https://github.com/bitbybit-dev/bitbybit/tree/master/packages/dev/occt-worker"

    %% Styles
    classDef baseFoundation fill:#fde2e2,stroke:#b30000,stroke-width:2px;
    classDef core fill:#fff2cc,stroke:#b38f00,stroke-width:2px;
    classDef cadWrapper fill:#d0e0f0,stroke:#1a75ff,stroke-width:2px;
    classDef engine fill:#d9ead3,stroke:#38761d,stroke-width:2px;
    classDef worker fill:#f9cb9c,stroke:#e69138,stroke-width:2px;
```
