This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
JBZoo Mermaid-PHP is a PHP library for generating Mermaid diagrams and flowcharts. It provides PHP objects to programmatically create various types of diagrams including Graph/Flowcharts, ER Diagrams, Class Diagrams, and Timeline diagrams, which are then rendered as Mermaid syntax or HTML.
make update # Install/update all dependencies
composer update # Alternative to make updatemake test # Run PHPUnit tests
make test-all # Run all tests and code style checks
phpunit # Run tests directly with PHPUnitmake codestyle # Run all code quality checks (linting, static analysis)make report-all # Generate all reports (coverage, static analysis, etc.)
make report-coveralls # Upload coverage to CoverallsThe library is organized around four main diagram types, each in its own namespace (30 total source files):
- Graph (
src/Graph.php) - Flowcharts and basic graphs with nodes and links - ERDiagram (
src/ERDiagram/) - Entity-Relationship diagrams for database schemas - ClassDiagram (
src/ClassDiagram/) - UML class diagrams with classes, relationships, namespaces, and cardinality - Timeline (
src/Timeline/) - Timeline diagrams for chronological data
Render(src/Render.php) - Central rendering engine that converts diagrams to HTML- Supports multiple themes (default, forest, dark, neutral)
- Generates standalone HTML with embedded Mermaid.js
- Provides live editor URLs for debugging
Node(src/Node.php) - Individual graph nodes with various shapes (square, circle, round)Link(src/Link.php) - Connections between nodes with optional labelsGraph- Container for nodes, links, and subgraphs with ordering and styling options
Entity(src/ERDiagram/Entity/Entity.php) - Database entities with propertiesEntityProperty- Entity attributes with types, constraints, and descriptionsRelationclasses - Various relationship types (OneToOne, OneToMany, ManyToOne, ManyToMany)
Concept(src/ClassDiagram/Concept/Concept.php) - UML classes with attributes and methodsAttribute/Method/Argument- Class members with visibility and type informationConceptNamespace- Namespace grouping for organizing classesRelationship- Class relationships with RelationType enum (inheritance, composition, etc.)Cardinalityenum - Relationship cardinality (ONE, ZERO_OR_ONE, ONE_OR_MORE, MANY, etc.)Linkenum - Link styles (SOLID, DASHED)Visibilityenum - Member visibility (PUBLIC, PRIVATE, PROTECTED, PACKAGE)
Timeline- Container for timeline sections and markersMarker- Time points with associated eventsEvent- Individual timeline events
All diagram classes use method chaining for building:
$graph = (new Graph(['title' => 'My Graph']))
->addNode($nodeA)
->addNode($nodeB)
->addLink(new Link($nodeA, $nodeB));All diagram types support:
__toString()- Returns Mermaid syntaxrenderHtml($options)- Returns complete HTML with Mermaid.jsgetLiveEditorUrl()- Returns URL to Mermaid live editor
Helper(src/Helper.php) - String escaping and formatting utilities for Mermaid syntaxDirection(src/Direction.php) - Enum for diagram directions (TOP_TO_BOTTOM, BOTTOM_TOP, LEFT_RIGHT, RIGHT_LEFT)Exception(src/Exception.php) - Base exception class for library-specific errors- Timeline exceptions - Specialized exceptions for timeline validation (e.g., SectionHasNoTitleException)
- Tests follow PSR-4 autoloading in
tests/directory (7 test files) - Test namespace:
JBZoo\PHPUnit\ - Test coverage: ClassDiagramTest, ERDiagramTest, FlowchartTest, TimelineTest
- Utility tests: MermaidPackageTest, MermaidPhpStormProxyTest
- All tests extend custom PHPUnit base class with helper methods
- PHPUnit configuration in
phpunit.xml.dist - Tests include HTML output generation for visual verification
- Runtime: PHP 8.3+, ext-json
- Development: jbzoo/toolbox-dev (includes PHPUnit, code style tools, etc.)
- Uses JBZoo ecosystem tools for consistent development experience