@brainwav/diagram 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +300 -0
- package/package.json +57 -0
- package/src/diagram.js +1118 -0
- package/src/video.js +388 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jamie Craik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
# diagram-cli
|
|
2
|
+
|
|
3
|
+
Generate codebase architecture diagrams from source files. No AI required.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Install](#install)
|
|
8
|
+
- [Quick start](#quick-start)
|
|
9
|
+
- [Commands](#commands)
|
|
10
|
+
- [Diagram types](#diagram-types)
|
|
11
|
+
- [Output formats](#output-formats)
|
|
12
|
+
- [Video and animation prerequisites](#video-and-animation-prerequisites)
|
|
13
|
+
- [Architecture Testing](#architecture-testing)
|
|
14
|
+
- [Documentation](#documentation)
|
|
15
|
+
- [Development](#development)
|
|
16
|
+
- [License](#license)
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Clone and link locally
|
|
22
|
+
git clone https://github.com/jscraik/diagram-cli.git
|
|
23
|
+
cd diagram-cli
|
|
24
|
+
npm install
|
|
25
|
+
npm link
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick start
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Analyze repository structure
|
|
32
|
+
diagram analyze .
|
|
33
|
+
|
|
34
|
+
# Generate architecture diagram (default type)
|
|
35
|
+
diagram generate .
|
|
36
|
+
|
|
37
|
+
# Generate all diagram types into ./diagrams
|
|
38
|
+
diagram all .
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
### `diagram analyze [path]`
|
|
44
|
+
|
|
45
|
+
Analyze file structure and dependencies without rendering a diagram.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
diagram analyze ./my-project
|
|
49
|
+
diagram analyze . --json
|
|
50
|
+
diagram analyze . --patterns "**/*.py,**/*.go"
|
|
51
|
+
diagram analyze . --max-files 200
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Options:
|
|
55
|
+
|
|
56
|
+
- `-p, --patterns <list>` file patterns (default: `**/*.ts,**/*.tsx,**/*.js,**/*.jsx,**/*.py,**/*.go,**/*.rs`)
|
|
57
|
+
- `-e, --exclude <list>` exclude patterns
|
|
58
|
+
- `-m, --max-files <n>` max files to analyze (default: `100`)
|
|
59
|
+
- `-j, --json` JSON output
|
|
60
|
+
|
|
61
|
+
### `diagram generate [path]`
|
|
62
|
+
|
|
63
|
+
Generate one Mermaid diagram and print a preview URL.
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
diagram generate .
|
|
67
|
+
diagram generate . --type sequence
|
|
68
|
+
diagram generate . --focus src/api
|
|
69
|
+
diagram generate . --theme dark
|
|
70
|
+
diagram generate . --output diagram.mmd
|
|
71
|
+
diagram generate . --output diagram.svg
|
|
72
|
+
diagram generate . --open
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Options:
|
|
76
|
+
|
|
77
|
+
- `-t, --type <type>` `architecture|sequence|dependency|class|flow` (default: `architecture`)
|
|
78
|
+
- `-f, --focus <module>` focus on one module or directory
|
|
79
|
+
- `-o, --output <file>` write `.mmd`, `.svg`, or `.png`
|
|
80
|
+
- `-m, --max-files <n>` max files to analyze
|
|
81
|
+
- `--theme <theme>` `default|dark|forest|neutral`
|
|
82
|
+
- `--open` open generated preview URL
|
|
83
|
+
|
|
84
|
+
### `diagram all [path]`
|
|
85
|
+
|
|
86
|
+
Generate all diagram types in one run.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
diagram all .
|
|
90
|
+
diagram all . --output-dir ./docs/diagrams
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Options:
|
|
94
|
+
|
|
95
|
+
- `-o, --output-dir <dir>` output directory (default: `./diagrams`)
|
|
96
|
+
|
|
97
|
+
### `diagram video [path]`
|
|
98
|
+
|
|
99
|
+
Generate an animated video (`.mp4`, `.webm`, `.mov`) from a Mermaid diagram.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
diagram video .
|
|
103
|
+
diagram video . --type dependency --output architecture.mp4
|
|
104
|
+
diagram video . --duration 8 --fps 60 --width 1920 --height 1080
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Options:
|
|
108
|
+
|
|
109
|
+
- `-t, --type <type>` `architecture|sequence|dependency|class|flow` (default: `architecture`)
|
|
110
|
+
- `-o, --output <file>` output file (default: `diagram.mp4`)
|
|
111
|
+
- `-d, --duration <sec>` video duration in seconds (default: `5`)
|
|
112
|
+
- `-f, --fps <n>` frames per second (default: `30`)
|
|
113
|
+
- `--width <n>` output width in pixels (default: `1280`)
|
|
114
|
+
- `--height <n>` output height in pixels (default: `720`)
|
|
115
|
+
- `--theme <theme>` `default|dark|forest|neutral` (default: `dark`)
|
|
116
|
+
- `-m, --max-files <n>` max files to analyze (default: `100`)
|
|
117
|
+
|
|
118
|
+
### `diagram animate [path]`
|
|
119
|
+
|
|
120
|
+
Generate an animated SVG with CSS animations.
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
diagram animate .
|
|
124
|
+
diagram animate . --type sequence --output sequence-animated.svg
|
|
125
|
+
diagram animate . --theme forest
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Options:
|
|
129
|
+
|
|
130
|
+
- `-t, --type <type>` `architecture|sequence|dependency|class|flow` (default: `architecture`)
|
|
131
|
+
- `-o, --output <file>` output file (default: `diagram-animated.svg`)
|
|
132
|
+
- `--theme <theme>` `default|dark|forest|neutral` (default: `dark`)
|
|
133
|
+
- `-m, --max-files <n>` max files to analyze (default: `100`)
|
|
134
|
+
|
|
135
|
+
## Diagram types
|
|
136
|
+
|
|
137
|
+
| Type | Description | Best for |
|
|
138
|
+
| --- | --- | --- |
|
|
139
|
+
| `architecture` | Component hierarchy by directory | Overall structure |
|
|
140
|
+
| `sequence` | Service or module interactions | API and flow analysis |
|
|
141
|
+
| `dependency` | Internal and external imports | Dependency review |
|
|
142
|
+
| `class` | Class-oriented relationships | OOP-heavy codebases |
|
|
143
|
+
| `flow` | Process/data flow | Control-flow mapping |
|
|
144
|
+
|
|
145
|
+
## Output formats
|
|
146
|
+
|
|
147
|
+
- Terminal Mermaid output
|
|
148
|
+
- `.mmd` Mermaid source files
|
|
149
|
+
- `.svg`/`.png` rendered images (requires Mermaid CLI)
|
|
150
|
+
- `.mp4`/`.webm`/`.mov` video export (requires Playwright + ffmpeg)
|
|
151
|
+
- Animated `.svg` export (requires Playwright)
|
|
152
|
+
|
|
153
|
+
Install Mermaid CLI for image export:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm install -g @mermaid-js/mermaid-cli
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Video and animation prerequisites
|
|
160
|
+
|
|
161
|
+
Install Playwright browser dependencies:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
npm install
|
|
165
|
+
npx playwright install chromium
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Install ffmpeg for `diagram video`:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
brew install ffmpeg
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Quick verification:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
diagram video . --duration 2 --output smoke-test.mp4
|
|
178
|
+
diagram animate . --output smoke-test-animated.svg
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Architecture Testing
|
|
182
|
+
|
|
183
|
+
Validate codebase architecture against declarative YAML rules
|
|
184
|
+
to prevent architectural drift.
|
|
185
|
+
|
|
186
|
+
### Architecture test quick start
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Generate starter configuration
|
|
190
|
+
diagram test --init
|
|
191
|
+
|
|
192
|
+
# Run validation
|
|
193
|
+
diagram test
|
|
194
|
+
|
|
195
|
+
# Preview file matching without validating
|
|
196
|
+
diagram test --dry-run
|
|
197
|
+
|
|
198
|
+
# CI-friendly output
|
|
199
|
+
diagram test --format junit --output test-results.xml
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Configuration (`.architecture.yml`)
|
|
203
|
+
|
|
204
|
+
```yaml
|
|
205
|
+
version: "1.0"
|
|
206
|
+
|
|
207
|
+
rules:
|
|
208
|
+
- name: "Domain isolation"
|
|
209
|
+
description: "Domain logic should not depend on UI"
|
|
210
|
+
layer: "src/domain"
|
|
211
|
+
must_not_import_from: ["src/ui", "src/components"]
|
|
212
|
+
|
|
213
|
+
- name: "API contract"
|
|
214
|
+
description: "API routes only use domain and shared"
|
|
215
|
+
layer: "src/api"
|
|
216
|
+
may_import_from: ["src/domain", "src/shared", "src/types"]
|
|
217
|
+
must_not_import_from: ["src/ui"]
|
|
218
|
+
|
|
219
|
+
- name: "Test independence"
|
|
220
|
+
description: "Tests should not import other tests"
|
|
221
|
+
layer: "**/*.test.ts"
|
|
222
|
+
must_not_import_from: ["**/*.test.ts", "**/*.spec.ts"]
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Rule types
|
|
226
|
+
|
|
227
|
+
| Constraint | Description |
|
|
228
|
+
| --- | --- |
|
|
229
|
+
| `must_not_import_from` | Forbidden import patterns |
|
|
230
|
+
| `may_import_from` | Whitelist of allowed imports |
|
|
231
|
+
| `must_import_from` | Required import patterns |
|
|
232
|
+
|
|
233
|
+
### Command options
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
diagram test [path] [options]
|
|
237
|
+
|
|
238
|
+
Options:
|
|
239
|
+
-c, --config <file> Config file (default: ".architecture.yml")
|
|
240
|
+
-f, --format <format> Output: console, json, junit
|
|
241
|
+
-o, --output <file> Write output to file
|
|
242
|
+
--dry-run Preview file matching
|
|
243
|
+
--verbose Show detailed output
|
|
244
|
+
--init Generate starter config
|
|
245
|
+
--force Overwrite existing config when used with --init
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Exit codes
|
|
249
|
+
|
|
250
|
+
| Code | Meaning |
|
|
251
|
+
| --- | --- |
|
|
252
|
+
| 0 | All rules passed |
|
|
253
|
+
| 1 | One or more rules failed |
|
|
254
|
+
| 2 | Configuration error |
|
|
255
|
+
|
|
256
|
+
### CI Integration
|
|
257
|
+
|
|
258
|
+
```yaml
|
|
259
|
+
# .github/workflows/architecture.yml
|
|
260
|
+
name: Architecture
|
|
261
|
+
on: [push, pull_request]
|
|
262
|
+
jobs:
|
|
263
|
+
test:
|
|
264
|
+
runs-on: ubuntu-latest
|
|
265
|
+
steps:
|
|
266
|
+
- uses: actions/checkout@v4
|
|
267
|
+
- uses: actions/setup-node@v4
|
|
268
|
+
- run: npm ci
|
|
269
|
+
- run: npm test
|
|
270
|
+
- run: npm run test:deep
|
|
271
|
+
- run: node src/diagram.js test . --format junit --output architecture-results.xml
|
|
272
|
+
- uses: dorny/test-reporter@v1
|
|
273
|
+
if: success() || failure()
|
|
274
|
+
with:
|
|
275
|
+
name: Architecture Tests
|
|
276
|
+
path: architecture-results.xml
|
|
277
|
+
reporter: java-junit
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Documentation
|
|
281
|
+
|
|
282
|
+
- Contributor guide: [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
283
|
+
- Security policy: [SECURITY.md](SECURITY.md)
|
|
284
|
+
- Support policy: [SUPPORT.md](SUPPORT.md)
|
|
285
|
+
- Code of conduct: [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)
|
|
286
|
+
- Maintainer docs index: [docs/README.md](docs/README.md)
|
|
287
|
+
- Release history: [CHANGELOG.md](CHANGELOG.md)
|
|
288
|
+
|
|
289
|
+
## Development
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
npm install
|
|
293
|
+
npm test
|
|
294
|
+
npm run test:deep
|
|
295
|
+
node src/diagram.js --help
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## License
|
|
299
|
+
|
|
300
|
+
MIT - see [LICENSE](LICENSE).
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@brainwav/diagram",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Generate architecture diagrams from codebases",
|
|
5
|
+
"main": "src/diagram.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"diagram": "src/diagram.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "node src/diagram.js analyze .",
|
|
11
|
+
"test:deep": "node scripts/deep-regression.js",
|
|
12
|
+
"prepublishOnly": "npm test",
|
|
13
|
+
"release:prepare": "bash scripts/release-npm.sh",
|
|
14
|
+
"release:prepare:initial": "bash scripts/release-npm.sh --initial",
|
|
15
|
+
"release:publish": "bash scripts/release-npm.sh --publish",
|
|
16
|
+
"release:publish:initial": "bash scripts/release-npm.sh --publish --initial"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"diagrams",
|
|
20
|
+
"mermaid",
|
|
21
|
+
"architecture",
|
|
22
|
+
"code-analysis",
|
|
23
|
+
"cli"
|
|
24
|
+
],
|
|
25
|
+
"author": "",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"chalk": "^4.1.2",
|
|
29
|
+
"cli-table3": "^0.6.5",
|
|
30
|
+
"commander": "^12.0.0",
|
|
31
|
+
"glob": "^10.0.0",
|
|
32
|
+
"picomatch": "^4.0.3",
|
|
33
|
+
"yaml": "^2.8.2",
|
|
34
|
+
"zod": "^4.3.6"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/jscraik/diagram-cli.git"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/jscraik/diagram-cli/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/jscraik/diagram-cli#readme",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"registry": "https://registry.npmjs.org/"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"src/diagram.js",
|
|
50
|
+
"src/video.js",
|
|
51
|
+
"README.md",
|
|
52
|
+
"LICENSE"
|
|
53
|
+
],
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=18"
|
|
56
|
+
}
|
|
57
|
+
}
|