# mxbuilder

> A library that allows you to build C4 MX drawing files with auto placement of entities.

Latest version **0.2.7** (published 2026-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install mxbuilder
pnpm add mxbuilder
yarn add mxbuilder
bun add mxbuilder
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.7 |
| Published | 2026-08-29 |
| First published | 2023-05-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 82.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Gerry Rohling |
| Maintainers | gfrohling |

## Links

- npm: https://www.npmjs.com/package/mxbuilder
- Repository: https://github.com/gerry-rohling/mxbuilder
- Issues: https://github.com/gerry-rohling/mxbuilder/issues
- npm.io page: https://npm.io/package/mxbuilder

## Dependencies (4)

- [elkjs](https://npm.io/package/elkjs.md) ^0.11.1
- [xpath](https://npm.io/package/xpath.md) ^0.0.34
- [xmlbuilder2](https://npm.io/package/xmlbuilder2.md) ^4.0.3
- [fast-xml-parser](https://npm.io/package/fast-xml-parser.md) ^5.11.1

## Recent versions

- 0.2.7 (latest) — 2026-08-29
- 0.2.6 — 2026-03-28
- 0.2.5 — 2026-02-18
- 0.2.4 — 2026-01-31
- 0.2.3 — 2024-09-21
- 0.2.2 — 2024-05-02
- 0.2.1 — 2024-05-01
- 0.2.0 — 2024-04-21
- 0.1.6 — 2024-04-13
- 0.1.5 — 2023-10-21
- 0.1.4 — 2023-06-13
- 0.1.3 — 2023-05-29
- 0.1.1 — 2023-05-13
- 0.1.0 — 2023-05-13

## README

# MX Builder

## Description

This library was built to allow for the easy generation of diagrams.net MX based files supporting the C4 diagram style. It is constrained to only support:

- C4 Stencil object styles
- Nesting of objects, such that containers can be placed inside a Software System, for example
- Auto layout of entities so that they are reasonably easy to start editing in diagrams.net

## Installation

Install with npm:

```bash
npm install --save-prod mxbuilder
```

Install with yarn:

```bash
yarn add mxbuilder
```

## Usage

To generate an MX file you create an instance of mxbuilder and then make calls to add specific C4 entities. When you are done, call `toDiagram()` to fetch the resulting diagrams.net file.

Example:
```js
var mx = new MxBuilder();
var id = mx.placeSoftwareSystem('System Name', 'System Description', 'ss001');
var str = await mx.toDiagram();
```

## Credits

This project relies on [elkjs](https://www.npmjs.com/package/elkjs) to implement the diagram layout function.

## License

This package is released under the MIT license.

## How to Contribute

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## Tests

Tests are written assuming the Jest test framework.

---
_Source: https://npm.io/package/mxbuilder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
