Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

schem-tool 🗺️

A Java 17 CLI library that translates JSON/YAML graph definitions into Mermaid.js diagrams.


Features

  • JSON & YAML input — auto-detected from file extension
  • Two diagram types via the Strategy pattern:
    • flowchart — Mermaid flowchart TD with shaped nodes (start/end, decision, process)
    • sequence — Mermaid sequenceDiagram with participants and messages
  • Composite pattern — supports nested node groups rendered as Mermaid subgraph blocks
  • 23 JUnit 5 tests covering parsers, composite builder, and both strategies
  • GitHub Actions CI — runs on every push/PR

Quick Start

Build the fat JAR

mvn clean package

Run

# Flowchart (default)
java -jar target/schem-tool.jar input.json

# Sequence diagram
java -jar target/schem-tool.jar input.json --type sequence

# Custom output file
java -jar target/schem-tool.jar input.yaml --type flowchart --output diagram.mmd

Input Format

JSON (input.json)

{
  "nodes": [
    { "id": "start",  "label": "Start",       "type": "start",    "children": [] },
    { "id": "check",  "label": "Logged in?",  "type": "decision", "children": [] },
    { "id": "login",  "label": "Login Page",  "type": "process",  "children": [] },
    { "id": "end",    "label": "End",         "type": "end",      "children": [] }
  ],
  "edges": [
    { "from": "start", "to": "check", "label": "" },
    { "from": "check", "to": "login", "label": "No" },
    { "from": "check", "to": "end",   "label": "Yes" },
    { "from": "login", "to": "end",   "label": "" }
  ]
}

YAML (input.yaml)

The same structure in YAML format (.yaml / .yml extensions are supported).

Node types & Mermaid shapes

type Mermaid shape Example
start Stadium ([…]) A([Start])
end Stadium ([…]) Z([End])
decision Rhombus {…} D{Choice?}
process Rectangle […] P[Process]

Nested nodes (subgraphs)

Nodes with a non-empty children array are rendered as Mermaid subgraph blocks:

{ "id": "module", "label": "My Module", "type": "process", "children": [
    { "id": "step1", "label": "Step 1", "type": "process", "children": [] },
    { "id": "step2", "label": "Step 2", "type": "process", "children": [] }
]}

Output Examples

Flowchart

flowchart TD
    start([Start])
    check{Is user logged in?}
    login[Show Login Page]
    end([End])

    start --> check
    check -->|No| login
    check -->|Yes| end
    login --> end

Sequence Diagram

sequenceDiagram
    participant user as User
    participant server as Server
    participant db as Database

    user->>server: HTTP GET /api
    server->>db: SELECT query
    db->>server: result set
    server->>user: JSON response

Architecture

org.example
├── Main.java                      ← Picocli entry point
├── cli/
│   └── LogicPlotCommand.java      ← @Command wiring
├── model/
│   ├── GraphDefinition.java       ← Root deserialized object
│   ├── NodeDefinition.java        ← Node with optional children
│   └── EdgeDefinition.java        ← Directed edge with optional label
├── parser/                        ← Strategy: input parsing
│   ├── InputParser.java           ← Interface
│   ├── JsonInputParser.java
│   ├── YamlInputParser.java
│   └── ParserFactory.java
├── composite/                     ← Composite pattern: node tree
│   ├── DiagramComponent.java      ← Interface
│   ├── DiagramLeaf.java           ← Single node
│   ├── DiagramComposite.java      ← Node group / subgraph
│   └── CompositeBuilder.java      ← Builds tree from NodeDefinition list
├── strategy/                      ← Strategy pattern: diagram generation
│   ├── DiagramStrategy.java       ← Interface
│   ├── FlowchartStrategy.java
│   ├── SequenceDiagramStrategy.java
│   ├── DiagramType.java           ← Enum (FLOWCHART, SEQUENCE)
│   └── StrategyFactory.java
└── output/
    └── MmdFileWriter.java         ← Writes .mmd file

Running Tests

mvn test

All 23 tests across 5 test classes:

Test Class Tests
JsonInputParserTest 4
YamlInputParserTest 3
CompositeBuilderTest 5
FlowchartStrategyTest 5
SequenceDiagramStrategyTest 6

About

CLI library that translates JSON/YAML graph definitions into Mermaid.js diagrams.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages