BoardKitCore
Core Overview
Overview of the @hfu.digital/boardkit-core package — zero-dependency shared kernel
The @hfu.digital/boardkit-core package is the shared kernel of BoardKit. It has zero runtime dependencies and provides all types, data structures, algorithms, and protocol definitions used by both the backend and frontend packages.
What's Included
| Module | Description |
|---|---|
| Types | Board, Page, Element (7 types), Participant, styles, events |
| Scene Graph | Immutable SceneState with pure mutation functions |
| Tools | Abstract Tool class, state machine, ToolRegistry with 8 built-in tools |
| Operations | LWW merge, undo/redo History, clipboard serialization |
| Protocol | Typed ClientMessage/ServerMessage for Socket.IO |
| Drawing | Point simplification, pressure mapping, stroke smoothing |
| Grid & Alignment | Snap-to-grid, alignment guides for element positioning |
| Validation | Board limit checks, asset size validation |
| Renderer | Abstract BoardRenderer class and RenderContext interface |
| Constants | TOOL_IDS, LIMITS, default styles |
| Fixtures | emptyBoard, simpleBoard, denseBoard for testing |
Installation
bun add @hfu.digital/boardkit-coreThis package is also installed automatically as a dependency of @hfu.digital/boardkit-nestjs and @hfu.digital/boardkit-react.
Usage
import {
createScene,
addElement,
ToolRegistry,
TOOL_IDS,
LIMITS,
} from '@hfu.digital/boardkit-core';
import type { Board, Element, SceneState } from '@hfu.digital/boardkit-core';
// Create an empty scene
const scene: SceneState = createScene();
// Create the default tool registry (all 8 built-in tools)
const tools = ToolRegistry.createDefault();
const pen = tools.get(TOOL_IDS.PEN);