{"id":50818196,"url":"https://github.com/sc2in/pozeiden","last_synced_at":"2026-06-13T11:30:51.967Z","repository":{"id":352664993,"uuid":"1205221892","full_name":"sc2in/pozeiden","owner":"sc2in","description":"Port of MermaidJS for zig. Don't render your charts with fish.","archived":false,"fork":false,"pushed_at":"2026-06-02T23:13:31.000Z","size":296,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-03T00:16:51.604Z","etag":null,"topics":["graphs","mermaid","zig"],"latest_commit_sha":null,"homepage":"https://pozeiden.sc2.in","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sc2in.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-08T18:53:25.000Z","updated_at":"2026-04-21T15:52:14.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/sc2in/pozeiden","commit_stats":null,"previous_names":["sc2in/pozeiden"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sc2in/pozeiden","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sc2in%2Fpozeiden","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sc2in%2Fpozeiden/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sc2in%2Fpozeiden/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sc2in%2Fpozeiden/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sc2in","download_url":"https://codeload.github.com/sc2in/pozeiden/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sc2in%2Fpozeiden/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34283387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-13T02:00:06.617Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphs","mermaid","zig"],"created_at":"2026-06-13T11:30:51.379Z","updated_at":"2026-06-13T11:30:51.958Z","avatar_url":"https://github.com/sc2in.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pozeiden\n\n[![CI](https://github.com/sc2in/pozeiden/actions/workflows/ci.yml/badge.svg)](https://github.com/sc2in/pozeiden/actions/workflows/ci.yml)\n\nA pure-Zig drop-in replacement for [mermaid.js](https://mermaid.js.org). Parses mermaid diagram text and produces self-contained SVG — no JavaScript runtime, no npm, no external processes. Compiles to a \\~295 KB WebAssembly module (vs mermaid.js's \\~1 MB+) and runs at sub-millisecond speeds.\n\nSupported interfaces: Zig library, C shared library, WebAssembly (wasm32-wasi), CLI.\n\n## Supported diagram types\n\n| Type | Keyword |\n|---|---|\n| Pie chart | `pie` |\n| Flowchart | `graph` / `flowchart` |\n| Sequence diagram | `sequenceDiagram` |\n| Git graph | `gitGraph` |\n| Class diagram | `classDiagram` |\n| State diagram | `stateDiagram-v2` |\n| ER diagram | `erDiagram` |\n| Gantt chart | `gantt` |\n| Timeline | `timeline` |\n| XY chart | `xychart-beta` |\n| Quadrant chart | `quadrantChart` |\n| Mindmap | `mindmap` |\n| Sankey diagram | `sankey-beta` |\n| C4 architecture | `C4Context` / `C4Container` / `C4Component` / `C4Dynamic` / `C4Deployment` |\n| Block diagram | `block-beta` |\n| Requirement diagram | `requirementDiagram` |\n| Kanban board | `kanban` |\n\n## Requirements\n\n- Zig **0.15.2** or later\n\n## Installation\n\nAdd pozeiden as a dependency in your `build.zig.zon`:\n\n```zig\n.dependencies = .{\n    .pozeiden = .{\n        .url = \"https://github.com/sc2in/pozeiden/archive/refs/tags/v0.1.0.tar.gz\",\n        .hash = \"...\",  // run: zig fetch --save \u003curl\u003e\n    },\n},\n```\n\nWire it up in `build.zig`:\n\n```zig\nconst pozeiden_dep = b.dependency(\"pozeiden\", .{\n    .target = target,\n    .optimize = optimize,\n});\nyour_module.addImport(\"pozeiden\", pozeiden_dep.module(\"pozeiden\"));\n```\n\n## Zig library usage\n\n```zig\nconst pozeiden = @import(\"pozeiden\");\n\npub fn example(allocator: std.mem.Allocator) !void {\n    const mermaid =\n        \\\\pie title Pets\n        \\\\\"Dogs\" : 60\n        \\\\\"Cats\" : 40\n    ;\n    const svg = try pozeiden.render(allocator, mermaid);\n    defer allocator.free(svg);\n    // svg is a self-contained SVG string\n}\n```\n\n`render` returns a heap-allocated slice that the caller owns. All internal\nallocations use a short-lived arena that is freed before the function returns.\n\nYou can also detect the diagram type without rendering:\n\n```zig\nconst kind = pozeiden.detectDiagramType(mermaid);\n// kind is a DiagramType enum: .pie, .flowchart, .sequence, etc.\n```\n\n## C shared library\n\nBuild and install:\n\n```sh\nzig build lib\n# zig-out/lib/libpozeiden.so\n# zig-out/include/pozeiden.h\n```\n\nAPI:\n\n```c\n#include \"pozeiden.h\"\n\n// Render mermaid text to SVG.\n// Returns 0 on success; *out_svg is heap-allocated, free with pozeiden_free().\n// Returns -1 on failure; call pozeiden_last_error() for the message.\nint pozeiden_render(const char *input, size_t input_len,\n                    char **out_svg, size_t *out_len);\n\n// Free an SVG string returned by pozeiden_render(). NULL is a safe no-op.\nvoid pozeiden_free(char *svg);\n\n// Return the last error message on this thread. Do NOT free the pointer.\nconst char *pozeiden_last_error(void);\n\n// Detect diagram type. Returns a string constant (\"flowchart\", \"pie\", etc.),\n// or \"unknown\". Do NOT free the pointer.\nconst char *pozeiden_detect(const char *input, size_t input_len);\n```\n\nExample:\n\n```c\nchar *svg = NULL;\nsize_t svg_len = 0;\nif (pozeiden_render(src, src_len, \u0026svg, \u0026svg_len) == 0) {\n    fwrite(svg, 1, svg_len, stdout);\n    pozeiden_free(svg);\n} else {\n    fprintf(stderr, \"pozeiden error: %s\\n\", pozeiden_last_error());\n}\n```\n\n## WebAssembly\n\nBuild:\n\n```sh\nzig build playground\n# zig-out/playground/pozeiden.wasm  (~295 KB)\n# zig-out/playground/index.html\n```\n\nJavaScript interface:\n\n```js\nconst { instance } = await WebAssembly.instantiateStreaming(fetch(\"pozeiden.wasm\"));\nconst wasm = instance.exports;\n\n// Write mermaid source into the 1 MB input buffer\nconst encoder = new TextEncoder();\nconst bytes = encoder.encode(mermaidText);\nconst inputPtr = wasm.get_input_ptr();\nnew Uint8Array(wasm.memory.buffer, inputPtr, bytes.length).set(bytes);\n\n// Render — returns SVG byte length (0 on error)\nconst svgLen = wasm.render(bytes.length);\n\n// Read SVG from the 512 KB output buffer\nconst outputPtr = wasm.get_output_ptr();\nconst svg = new TextDecoder().decode(\n    new Uint8Array(wasm.memory.buffer, outputPtr, svgLen)\n);\n```\n\n## CLI usage\n\n```sh\n# stdin → stdout\necho 'pie title Pets\n\"Dogs\" : 60\n\"Cats\" : 40' | pozeiden \u003e out.svg\n\n# explicit files\npozeiden -i diagram.mmd -o diagram.svg\n\n# JSON envelope: {\"svg\":\"...\",\"diagram_type\":\"...\"}\npozeiden -i diagram.mmd --format json\n\n# version\npozeiden --version\n\n# help\npozeiden --help\n```\n\n## Playground\n\nA live browser playground is included. It compiles pozeiden to WebAssembly and\nserves a split-pane editor where edits render instantly.\n\n```sh\nnix run .#playground          # build WASM + serve on http://localhost:8080\nnix run .#playground -- 3000  # custom port\n```\n\nWithout Nix:\n\n```sh\nzig build playground\ncd zig-out/playground \u0026\u0026 python3 -m http.server\n```\n\nAll 17 diagram types are available as presets in the example dropdown.\n\n## Build steps\n\n| Step | Command | Output |\n|---|---|---|\n| CLI binary | `zig build` | `zig-out/bin/pozeiden` |\n| Unit tests | `zig build test` | — |\n| Semantic check | `zig build check` | — |\n| C shared library | `zig build lib` | `zig-out/lib/libpozeiden.so` + `zig-out/include/pozeiden.h` |\n| WASM playground | `zig build playground` | `zig-out/playground/` |\n| Example SVGs | `zig build examples` | `zig-out/examples/*.svg` |\n| Fuzz (smoke) | `zig build fuzz` | — |\n| Fuzz (coverage) | `zig build fuzz --fuzz` | — |\n| Benchmark | `zig build bench` | timing output to stdout |\n| Update README bench | `nix run .#bench` | rewrites the Performance section |\n| API docs | `zig build docs` | `zig-out/docs/` |\n\n## Examples\n\nThe `examples/` directory contains one `.mmd` source file per diagram type.\nRun `zig build examples` to render them all to `zig-out/examples/*.svg`.\n\n```text\nexamples/\n  block.mmd       c4.mmd          class.mmd       er.mmd\n  flowchart.mmd   gantt.mmd       gitgraph.mmd    kanban.mmd\n  mindmap.mmd     pie.mmd         quadrant.mmd    requirement.mmd\n  sankey.mmd      sequence.mmd    state.mmd       timeline.mmd\n  xychart.mmd\n```\n\n## Performance\n\nRun `nix run .#bench` to regenerate (requires Linux with mermaid-cli available via the dev shell).\n\n\u003c!-- bench-start --\u003e\n\n\\_Last updated: 2026-04-20 - run: nix run .\\#bench\n\n### Render time\n\n| diagram | iters | min\\_µs | mean\\_µs | max\\_µs |\n|---|---|---|---|---|\n| pie | 1000 | 205.4 | 300.7 | 3432.9 |\n| flowchart | 1000 | 267.3 | 369.0 | 1785.5 |\n| sequence | 1000 | 156.5 | 192.7 | 1137.3 |\n| gitgraph | 1000 | 724.5 | 808.4 | 1341.5 |\n| class | 1000 | 96.1 | 114.3 | 617.1 |\n| state | 1000 | 140.4 | 163.4 | 792.5 |\n| er | 1000 | 109.5 | 141.8 | 925.1 |\n| gantt | 1000 | 65.1 | 93.2 | 771.8 |\n| timeline | 1000 | 44.2 | 75.9 | 528.3 |\n| xychart | 1000 | 26.9 | 42.2 | 573.7 |\n| quadrant | 1000 | 29.3 | 38.3 | 752.6 |\n| mindmap | 1000 | 152.7 | 206.0 | 845.1 |\n| sankey | 1000 | 100.4 | 111.4 | 472.3 |\n| c4 | 1000 | 136.4 | 158.3 | 608.5 |\n| block | 1000 | 60.9 | 72.2 | 1001.2 |\n| requirement | 1000 | 77.6 | 95.8 | 605.9 |\n| kanban | 1000 | 53.4 | 87.0 | 723.5 |\n\n### vs mermaid-cli (3 iterations each)\n\n| diagram | poz\\_µs | mmdc\\_µs | speedup |\n|---|---|---|---|\n| pie | 279.6 | 2376285.4 | 8499.8x |\n| flowchart | 600.1 | 2638367.3 | 4396.9x |\n| sequence | 212.7 | 2144423.0 | 10081.4x |\n| gitgraph | 1582.1 | 2506957.1 | 1584.6x |\n| class | 117.1 | 2312115.2 | 19740.6x |\n| state | 190.1 | 2755229.2 | 14491.2x |\n| er | 119.2 | 2455002.7 | 20600.5x |\n| gantt | 169.0 | 2300938.5 | 13611.2x |\n| timeline | 62.3 | 3198155.0 | 51339.7x |\n| xychart | 74.5 | 2270786.0 | 30473.0x |\n| quadrant | 40.1 | 2073034.2 | 51679.9x |\n| mindmap | 191.3 | 3386923.6 | 17700.4x |\n| sankey | 119.5 | 2085439.2 | 17450.8x |\n| c4 | 360.9 | 1973762.7 | 5468.7x |\n| block | 76.6 | 2197381.3 | 28679.7x |\n| requirement | 96.1 | 2170166.8 | 22589.0x |\n| kanban | 65.7 | 2577871.5 | 39219.1x |\n\n\u003c!-- bench-end --\u003e\n\n## Architecture\n\n```text\nsrc/\n  root.zig              Public API: detect type, parse, dispatch to renderer\n  detect.zig            First-line diagram type detection\n  main.zig              CLI entry point\n  wasm.zig              WebAssembly entry point (get_input_ptr / render / get_output_ptr)\n  capi.zig              C ABI exports (pozeiden_render, pozeiden_free, ...)\n  diagram/\n    value.zig           Generic AST value (string | number | bool | node | list)\n  svg/\n    writer.zig          Low-level SVG string builder\n    theme.zig           Mermaid default theme constants\n    layout.zig          DAG layout (simplified Sugiyama) for flowcharts\n  renderers/\n    pie.zig             Pie chart\n    flowchart.zig       Flowchart / graph (shapes, edge labels, dashed/thick edges)\n    sequence.zig        Sequence diagram (activation bars, notes, autonumber)\n    gitgraph.zig        Git graph\n    class.zig           Class diagram (stereotypes, generics, visibility)\n    state.zig           State diagram (fork/join bars, choice diamonds)\n    er.zig              Entity-relationship diagram\n    gantt.zig           Gantt chart (today marker, section backgrounds)\n    timeline.zig        Timeline\n    xychart.zig         XY chart (bar + line)\n    quadrant.zig        Quadrant chart\n    mindmap.zig         Mindmap (radial tree)\n    sankey.zig          Sankey diagram\n    c4.zig              C4 architecture diagrams (ext dashed borders, enterprise boundaries)\n    block.zig           Block diagram (grid layout)\n    requirement.zig     Requirement diagram (two-section boxes)\n    kanban.zig          Kanban board (column + card layout)\n  langium/              Parser for .langium grammar files\n  jison/                Parser for .jison grammar files\ngrammars/               Embedded .langium and .jison grammar definitions\nexamples/               Source .mmd files for each diagram type\nplayground/             HTML + JS source for the live browser playground\ninclude/                C API header (pozeiden.h)\n```\n\nTwo grammar backends are used:\n\n- **Langium backend**: for diagram types with a formal `.langium` grammar\n  (pie, gitGraph). Parses the grammar file at compile time via `@embedFile`,\n  then tokenises and interprets diagram text at runtime.\n- **Direct parsers**: all other diagram types use hand-written line-oriented\n  parsers in `root.zig`, which are simpler and faster for the formats mermaid uses.\n\n## Nix\n\n```sh\nnix run .                     # render stdin → stdout\nnix run .#playground          # build WASM + serve playground\nnix run .#bench               # run benchmarks and update README (Linux)\nnix build .#pozeiden-safe     # ReleaseSafe binary in result/\nnix build .#pozeiden-fast     # ReleaseFast binary\nnix build .#pozeiden-small    # ReleaseSmall binary\nnix flake check               # run test suite\n```\n\n## License\n\n[PolyForm Noncommercial 1.0.0](LICENSE) — free for noncommercial use.\nCommercial licensing: [\u003cinquiries@sc2.in\u003e](mailto:inquiries@sc2.in)\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## Security\n\nSee [SECURITY.md](SECURITY.md). Report vulnerabilities to [\u003csecurity@sc2.in\u003e](mailto:security@sc2.in).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsc2in%2Fpozeiden","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsc2in%2Fpozeiden","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsc2in%2Fpozeiden/lists"}