# worktile/plait architecture

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

- Interactive diagram: https://gitdiagram.com/worktile/plait
- Repository: https://github.com/worktile/plait

## Overview

##### Main Components
- Core Engine & Data Model: The heart of the framework is implemented in packages like “core” (handling board logic, plugin management, event handling, diffing, transforms, and utilities) and “common” (providing shared functionalities such as drawing utilities, algorithms, and constants).
- Layout & Algorithms: The “layouts” package implements mind map layout algorithms and supports tree and timeline arrangements.
- UI Framework Integrations: The repository contains dedicated integration packages like “angular-board”, “angular-text”, “react-board”, and “react-text”. They serve as the whiteboard view components and text editors, wrapping the core functionalities into the respective UI framework’s ecosystem.
- Sample/Demo Application: The “src” directory holds the Angular-based example application, including various UI components (editor, toolbar, menu, debug, and additional examples for flow, graph-viz, and rich text).

##### Relationships and Interactions
- The UI integration components (in Angular or React) interact with the core engine to render the board, apply plugins, and process events. These components use public APIs (from “core” and “common”) to drive board state and listen for changes.
- Layout algorithms (from “layouts”) serve as an independent module that the “mind” plugin and potentially others use to automatically arrange nodes.
- All packages expose their functionality via public-api files and use TypeScript configuration files (ng-package, tsconfig) to support compilation as reusable libraries.
- Utility components in “utils”, “generators”, and “transforms” serve as building blocks to process elements, manage histories, and enable collaboration features.

##### Highlighting Architectural Patterns and Design Principles
- Modular and Decoupled Design: The monorepo structure and separate packages promote modularity. Each package has its own responsibilities (core logic, drawing, layout, plugins, UI integration).
- Plugin-based Extension: The core engine is framework agnostic; plugins are registered to extend capabilities. This extends to the circuit pattern where the plugins “decorate” the board’s behavior.
- Separation of Concerns: There’s a clear demarcation between the drawing model (data and functional utilities) and the presentation layer (UI integration with Angular/React).
- Data-driven and Declarative Rendering: Inspired by Slate for text rendering, the board’s modifications are visible through board state and chaining plugin transformations.

##### Relevant Technologies, Frameworks, and Libraries
- Core: TypeScript, modular package design.
- UI Integrations: Angular and React (with implementations like “angular-board”, “angular-text”, etc).
- External Libraries: Slate for rich text, integration with popular UI frameworks, and possibly utilities like Rough (for freehand drawing).
- Build and Deployment: Configuration files (angular.json, tsconfig.json, package.json) indicate usage of modern build tools and CI/CD (GitHub Actions) for continuous integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Plait Framework"
        subgraph "Core Engine & Data Model"
            CORE["Core Engine"]:::core
            COMMON["Common"]:::core
        end

        subgraph "Plugin Modules"
            MIND["Mind Plugin"]:::plugin
            DRAW["Draw Plugin"]:::plugin
            FLOW["Flow Plugin"]:::plugin
            GRAPH["Graph-Viz Plugin"]:::plugin
            TEXT["Text Plugin"]:::plugin
        end

        subgraph "Layout & Algorithms"
            LAYOUTS["Layouts"]:::layout
        end

        subgraph "UI Integration Components"
            ANGULAR["Angular Board"]:::integration
            ANGULAR_TEXT["Angular Text"]:::integration
        end

        subgraph "Demo/Sample Application"
            DEMO["Demo App"]:::demo
        end
    end

    %% Relationships between UI Integrations and Core Engine
    ANGULAR -->|"calls"| CORE
    ANGULAR_TEXT -->|"calls"| CORE

    %% Core registers Plugin Modules
    CORE -->|"registers"| MIND
    CORE -->|"registers"| DRAW
    CORE -->|"registers"| FLOW
    CORE -->|"registers"| GRAPH
    CORE -->|"registers"| TEXT

    %% Plugin Modules interaction with Layouts (example for Mind Plugin)
    MIND -->|"uses"| LAYOUTS

    %% Core Common provides utilities to Plugins
    COMMON -->|"provides_utilities"| MIND
    COMMON -->|"provides_utilities"| DRAW
    COMMON -->|"provides_utilities"| FLOW
    COMMON -->|"provides_utilities"| GRAPH
    COMMON -->|"provides_utilities"| TEXT

    %% Demo Application demonstrates UI Integration Components
    DEMO -->|"demonstrates"| ANGULAR
    DEMO -->|"demonstrates"| ANGULAR_TEXT

    %% Click Events
    click CORE "https://github.com/worktile/plait/tree/develop/packages/core"
    click COMMON "https://github.com/worktile/plait/tree/develop/packages/common"
    click MIND "https://github.com/worktile/plait/tree/develop/packages/mind"
    click DRAW "https://github.com/worktile/plait/tree/develop/packages/draw"
    click FLOW "https://github.com/worktile/plait/tree/develop/packages/flow"
    click GRAPH "https://github.com/worktile/plait/tree/develop/packages/graph-viz"
    click TEXT "https://github.com/worktile/plait/tree/develop/packages/text-plugins"
    click LAYOUTS "https://github.com/worktile/plait/tree/develop/packages/layouts"
    click ANGULAR "https://github.com/worktile/plait/tree/develop/packages/angular-board"
    click ANGULAR_TEXT "https://github.com/worktile/plait/tree/develop/packages/angular-text"
    click DEMO "https://github.com/worktile/plait/tree/develop/src/app"

    %% Styles
    classDef core fill:#AED581,stroke:#333,stroke-width:2px;
    classDef plugin fill:#FFCC80,stroke:#333,stroke-width:2px;
    classDef layout fill:#90CAF9,stroke:#333,stroke-width:2px;
    classDef integration fill:#CE93D8,stroke:#333,stroke-width:2px;
    classDef demo fill:#FFF59D,stroke:#333,stroke-width:2px;
```
