This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
- Start development server:
bun dev(runs on port 14000) - Build library:
bun build(builds library with vite.config.lib.ts) - Build site:
bun build:site(builds demo site with vite.config.ts) - Run tests:
bun run test(runs unit tests scoped tosrc/andtest/unit/, excluding E2E). Do NOT runbun testwithout arguments — it picks up Playwright E2E files and reports false failures. - Analyze E2E diff:
node scripts/analyze-compare-case.mjs --case <name> --json(structured diff attribution for compare-case pages;--output-dir <dir>saveshtml.png,svg.png,diff.png,report.json) - Run E2E tests:
bun pw(runs Playwright tests) - Run E2E tests (CI):
bun pw:ci(runs with GitHub reporter for CI) - Open Playwright UI:
bun pw:ui - Update Playwright snapshots:
bun pw:update - Install Playwright browsers:
bun pw:install - Run smoke tests:
bun pw:smoke - Lint code:
bun eslint(runs ESLint with auto-fix) - Format code:
bun prettier(runs Prettier) - Generate ANTLR parser:
bun antlr(generates JavaScript parser from grammar)
ZenUML is a JavaScript-based diagramming library for creating sequence diagrams from text definitions. The project has two main parts:
- Grammar files:
src/g4/contains ANTLR grammar definitions - Generated parser:
src/generated-parser/contains generated JavaScript parser - Parser enhancements:
src/parser/contains custom functionality layered on top of ANTLR
- Core entry point:
src/core.tsx- main library export and ZenUml class - Component structure:
src/components/- React components for rendering diagrams - Store management:
src/store/Store.ts- Jotai-based state management - Positioning engine:
src/positioning/- algorithms for layout and positioning
- DiagramFrame: Main container component that orchestrates the entire diagram
- SeqDiagram: Core sequence diagram renderer with layers:
- LifeLineLayer: Renders participants and their lifelines
- MessageLayer: Renders messages and interactions between participants
- Statement components: Individual renderers for different UML elements (interactions, fragments, etc.)
The parser uses a two-stage approach:
- ANTLR-generated parser: Converts text to parse tree
- Custom parser layer: Transforms parse tree into structured data for rendering
Key parser modules:
- Participants.ts: Manages participant detection and ordering
- MessageContext.ts: Handles message parsing and context
- FrameBuilder.ts: Builds the overall diagram structure
- Fragment handling: Support for UML fragments (alt, opt, loop, par, etc.)
The project uses Vite with two configurations:
- vite.config.ts: Development server and demo site build
- vite.config.lib.ts: Library build (ESM and UMD outputs)
Output formats:
- ESM:
dist/zenuml.esm.mjsfor modern bundlers - UMD:
dist/zenuml.jsfor browser scripts
- Unit tests: Vitest for parser and utility functions
- Component tests: React Testing Library for component logic
- E2E tests: Playwright for full integration testing with visual snapshots
- Test files: Co-located with source files using
.spec.ts/.spec.tsxextensions
Never update Playwright screenshots just to make a failing snapshot test pass. Before committing any updated E2E screenshot:
- Compare the before and after screenshots and identify exactly where the visual differences are.
- Use the existing diagram diff workflow where applicable: run
node scripts/analyze-compare-case.mjs --case <name> --jsonfor structured attribution, or--output-dir <dir>to savehtml.png,svg.png,diff.png, andreport.json. - For compare-case pages, treat the native diff panel / analyzer output as the source of truth. Locate connected diff clusters, their bounding boxes/centroids, and the nearest semantic targets such as labels, arrows, participant boxes, participant icons, stereotypes, groups, fragments, or comments.
- Judge the identified differences against the actual code change in the commit. Only update snapshots when the changed pixels are an intentional and correct consequence of the code change.
- In the PR or commit notes, state which elements changed, where they changed, and why the screenshot update is correct.
- React 19: UI framework
- ANTLR4: Parser generation
- Jotai: State management
- Tailwind CSS: Styling framework
- html-to-image: PNG export functionality
- Vite: Build tool and development server
Uses Bun as the package manager and JavaScript runtime. Bun is a fast all-in-one JavaScript runtime that includes a package manager, test runner, and bundler.
- Unit tests:
bun run test— runsbun test src test/unit, scoping to unit test folders only (excludes/testsE2E folder) - Vitest: Tests also support Vitest for IDE integration compatibility
- E2E tests:
bun pw- Runs Playwright tests in/testsfolder - Test setup:
test/setup.tsconfigures test environment (mocks IntersectionObserver, etc.) - Tests use
vimocking utilities from Vitest - Test files use
.spec.ts/.spec.tsxextensions and are co-located with source files
When starting work on a bug (especially from a GitHub issue):
- Reproduce first — write a minimal test case (unit test or Playwright E2E) that demonstrates the bug. The test must fail before any code changes.
- Capture a baseline — if the bug is visual, take a Playwright snapshot or screenshot of the broken state before fixing. This serves as evidence of what changed.
- Fix the code — make the minimal change to fix the bug.
- Verify the fix — the failing test from step 1 must now pass. All other existing tests must still pass.
Never skip the reproduction step. If you can't reproduce it, you don't understand the bug well enough to fix it.
NEVER claim what the codebase does, uses, or contains without first verifying by reading or grepping the code. Phrases like "if we're currently using X", "since we already have Y", or "the codebase uses Z pattern" are forbidden unless you have Read/Grep/Glob evidence from this conversation.
- Before making a claim about codebase state, verify it — use a subagent (Explore) if needed.
- General programming knowledge is fine. Claims about this codebase require evidence.
- The project builds both a library and a demo site
- Parser generation requires Java and ANTLR4
- E2E tests use visual snapshots for regression testing
- The library is published as
@zenuml/coreto npm - GitHub Pages deployment is automated via GitHub Actions