create-idocs 0.0.0-stage → 0.3.1

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.
Files changed (34) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -2
  3. package/dist/chunk-YVMC6WCS.js +43 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +49 -0
  6. package/dist/scaffold.d.ts +8 -0
  7. package/dist/scaffold.js +8 -0
  8. package/package.json +32 -3
  9. package/template/.claude/skills/idocs/SKILL.md +108 -0
  10. package/template/.claude/skills/idocs/assets/examples/shop.diagram.yaml +164 -0
  11. package/template/.claude/skills/idocs/references/format.md +123 -0
  12. package/template/.claude/skills/idocs/references/layout.md +39 -0
  13. package/template/.claude/skills/idocs/references/scenarios.md +104 -0
  14. package/template/.claude/skills/idocs/references/setup.md +95 -0
  15. package/template/.claude/skills/idocs/references/troubleshooting.md +49 -0
  16. package/template/.github/workflows/deploy.yml +60 -0
  17. package/template/CLAUDE.md +27 -0
  18. package/template/README.md +30 -0
  19. package/template/_gitignore +6 -0
  20. package/template/_pnpm-workspace.yaml +4 -0
  21. package/template/astro.config.mjs +32 -0
  22. package/template/diagrams/diagram.schema.json +647 -0
  23. package/template/diagrams/shop/diagram.yaml +105 -0
  24. package/template/diagrams/shop/nodes/gateway.md +1 -0
  25. package/template/diagrams/shop/nodes/orders.md +9 -0
  26. package/template/package.json +29 -0
  27. package/template/public/favicon.svg +1 -0
  28. package/template/src/content/docs/architecture.mdx +13 -0
  29. package/template/src/content/docs/editing.mdx +62 -0
  30. package/template/src/content/docs/index.mdx +18 -0
  31. package/template/src/content.config.ts +7 -0
  32. package/template/src/env.d.ts +2 -0
  33. package/template/src/styles/custom.css +16 -0
  34. package/template/tsconfig.json +6 -0
@@ -0,0 +1,104 @@
1
+ # Scenarios
2
+
3
+ A scenario is a story that plays over a diagram: an ordered list of steps. Each step flies a packet along your edges, or makes one node do something. A diagram can have any number of scenarios; readers pick one above the diagram.
4
+
5
+ ## Shape
6
+
7
+ ```yaml
8
+ scenarios:
9
+ place-order:
10
+ title: Place an order
11
+ summary: | # the story in one or two sentences (markdown)
12
+ The order is saved first, charged second and confirmed last.
13
+ phases: # optional chapters; or use a flat `steps:` list
14
+ - title: Save
15
+ caption: before any money moves
16
+ steps:
17
+ - browser -> orders:
18
+ label: POST /orders
19
+ note: The request carries an idempotency key. # explanation shown in the step list
20
+ - orders -> db: { label: INSERT order, kind: lookup }
21
+ - title: Charge
22
+ steps:
23
+ - orders -> stripe: create payment intent
24
+ - at stripe: { label: authorise card, note: The one step we do not control. }
25
+ - stripe -> orders: succeeded
26
+ ```
27
+
28
+ Only `title` and at least one step are required. Other scenario fields: `view` (which view to play on; default the first), `mode` (`flow`, `sequence` or `story`: how it opens), `lanes` (story columns, below).
29
+
30
+ ## Steps
31
+
32
+ | You write | What happens |
33
+ |---|---|
34
+ | `a -> b: label` | A packet flies from `a` to `b`. |
35
+ | `at a: label` | `a` pulses and shows the caption: "this component does something". |
36
+ | `par:` with a nested list | The steps inside start together. |
37
+
38
+ Every step can be written compactly (`a -> b: label`) or as a map (`a -> b: { label: ..., kind: ..., note: ... }`). Options:
39
+
40
+ | Option | Meaning |
41
+ |---|---|
42
+ | `label` | What travels, shown on the packet. Keep it short. |
43
+ | `kind` | `request` (default), `response`, `error`, `lookup`, `event`. Changes the packet's colour and style. |
44
+ | `note` | Markdown explanation shown in the step list. |
45
+ | `status` | `planned` draws the step dashed with a tag. |
46
+ | `via` | Force the route through these nodes: `via: [gateway]`. |
47
+ | `hold` | Extra pause in seconds. |
48
+ | `title`, `detail` | The heading and short body of the step's box in the story view. |
49
+
50
+ **Routing.** Steps follow the edges you declared. If `a` and `b` are not directly connected, the packet takes the shortest route through the nodes between them, hop by hop (`browser -> db` flies through the API). If there is no route, `idocs check` says so: declare an edge (it can be `hidden: true`) or add `via`.
51
+
52
+ **Responses.** A packet that flies against an edge's direction is a response automatically (green), so `db -> api` over an `api -> db` edge needs no `kind`. Write `kind: error` for failures.
53
+
54
+ **Lookups.** `kind: lookup` marks a quick question to a data store or cache. Follow it with the answer: `cache -> api: hit`.
55
+
56
+ ## Story view
57
+
58
+ The same scenario can be read as a story: swimlanes with one column per actor, steps running down the page in order, and the phases as bands. Readers switch with the Flow / Sequence / Story buttons; `mode: story` makes it the default.
59
+
60
+ How steps become boxes:
61
+
62
+ | Step | In the story |
63
+ |---|---|
64
+ | `at a: ...` | A box in `a`'s lane. |
65
+ | `a -> b: ...` | A box in `b`'s lane, joined by an arrow to the box before it. If the story is not already at `a`, a small box shows where it starts. |
66
+ | `a -> b: { kind: lookup }` | A dashed box in `b`'s lane, level with the step that asked, joined by a double-headed dotted arrow. The answer step that follows is folded into the same box. |
67
+
68
+ Boxes are numbered 1, 2, 3 along the story; lookups are not numbered. Click a box to play that step.
69
+
70
+ ```yaml
71
+ scenarios:
72
+ read-request:
73
+ title: One read request, end to end
74
+ mode: story
75
+ lanes: # columns, left to right
76
+ - { title: Browser, nodes: [browser] }
77
+ - { title: Stores, sub: Redis · Postgres, nodes: [redis, postgres] } # one lane, several nodes
78
+ phases:
79
+ - title: Who are you?
80
+ steps:
81
+ - gateway -> backend:
82
+ title: Check the session # box heading; defaults to the label
83
+ detail: | # one to three short lines; defaults to "from → to"
84
+ cookie → session
85
+ token read from Redis
86
+ - backend -> redis: { label: session lookup, kind: lookup }
87
+ - redis -> backend: found
88
+ - at backend: { title: Which device?, detail: id → URL + org }
89
+ ```
90
+
91
+ - Without `lanes` you get one lane per node, in order of first appearance. With `lanes`, list them in the order you want; nodes you leave out get their own lane at the end, and `idocs check` warns about them.
92
+ - Write `title` as a short question or verb phrase ("Who are you?", "Cross the tunnel") and `detail` as what is concrete: a route, a header, a store. They are for the story only; the packet label stays short.
93
+ - Use `at` steps for "this component does something" moments, and lookups for questions to a data store.
94
+ - Keep a story to about 8 lanes and 15 boxes. Past that, split it into two scenarios.
95
+
96
+ ## Writing good scenarios
97
+
98
+ - **One question per scenario.** "Pay with a card" and "Card declined" are two scenarios.
99
+ - **Failures get their own scenario.** That is where readers learn the most.
100
+ - **Label what travels** (`POST /payments`, `payment.succeeded`) and put the reasoning in `note`.
101
+ - **Two to five phases**, with plain names. They become the chapter headings in the step list.
102
+ - **Do not narrate the obvious.** A note should answer "why" or "what could go wrong here".
103
+ - **Start at the actor.** The first step is usually `browser -> gateway`, or an `at` step describing the trigger.
104
+ - If a scenario needs a relationship you do not want drawn, add the edge with `hidden: true`.
@@ -0,0 +1,95 @@
1
+ # Setting up idocs
2
+
3
+ idocs renders diagrams inside an **Astro** site (usually with **Starlight** for the docs chrome). Use the project's package manager; examples use pnpm.
4
+
5
+ ## What is on npm
6
+
7
+ | Package | Role |
8
+ |---|---|
9
+ | `create-idocs` | `npm create idocs@latest`: scaffolds a new site. |
10
+ | `@the-package-labs/idocs` | The CLI: `idocs check`, `list`, `schema`, `icons search`, `new`. |
11
+ | `@the-package-labs/idocs-astro` | The Astro integration and the `<Diagram>` component. |
12
+ | `@the-package-labs/idocs-react` | The interactive diagram component (a dependency of the integration). |
13
+ | `@the-package-labs/idocs-core` | Schema, compiler and layout (a dependency of the others). |
14
+
15
+ The source is `https://github.com/The-Package-Labs/idocs`. If an install fails with "not found", check `npm view @the-package-labs/idocs-core version`: it should print a version. A company registry mirror may simply not have the `@packagelab` scope yet.
16
+
17
+ ## Start a new site
18
+
19
+ ```sh
20
+ npm create idocs@latest my-docs
21
+ cd my-docs
22
+ pnpm install
23
+ pnpm dev # http://localhost:4321
24
+ ```
25
+
26
+ This creates an Astro + Starlight project with an example diagram (`diagrams/shop`), three pages, a GitHub Pages workflow, and this skill. The folder must be empty or not exist. Edit `diagrams/shop/diagram.yaml` and the page reloads.
27
+
28
+ ## Add idocs to an existing Astro + Starlight site
29
+
30
+ 1. **Install.**
31
+ ```sh
32
+ pnpm add @the-package-labs/idocs-astro @the-package-labs/idocs-react @astrojs/react react react-dom
33
+ pnpm add -D @the-package-labs/idocs
34
+ ```
35
+ On pnpm 10 or later, allow the build scripts it asks about by adding to `pnpm-workspace.yaml`:
36
+ ```yaml
37
+ allowBuilds:
38
+ esbuild: true
39
+ sharp: true
40
+ ```
41
+ 2. **Register the integrations** in `astro.config.mjs`:
42
+ ```js
43
+ import react from '@astrojs/react'
44
+ import starlight from '@astrojs/starlight'
45
+ import idocs from '@the-package-labs/idocs-astro'
46
+ import { defineConfig } from 'astro/config'
47
+
48
+ export default defineConfig({
49
+ integrations: [
50
+ idocs(), // compiles diagrams/ at build time; the build fails on a broken diagram
51
+ react(),
52
+ starlight({
53
+ title: 'My docs',
54
+ // Widens the content column for diagrams and keeps prose at a readable width.
55
+ customCss: ['@the-package-labs/idocs-astro/starlight.css'],
56
+ }),
57
+ ],
58
+ })
59
+ ```
60
+ `idocs({ dir: 'my-diagrams' })` changes the folder (default `diagrams`).
61
+ 3. **Types.** In `src/env.d.ts` add `/// <reference types="@the-package-labs/idocs-astro/virtual" />`.
62
+ 4. **A first diagram.**
63
+ ```sh
64
+ pnpm idocs new shop
65
+ pnpm idocs schema # editor autocomplete for diagram.yaml
66
+ pnpm idocs check
67
+ ```
68
+ 5. **A page** (`src/content/docs/shop.mdx`):
69
+ ```mdx
70
+ ---
71
+ title: Shop
72
+ tableOfContents: false
73
+ ---
74
+ import Diagram from '@the-package-labs/idocs-astro/Diagram.astro'
75
+
76
+ <Diagram name="shop" />
77
+ ```
78
+ 6. Add `"check": "idocs check"` to `package.json` scripts, and run it in CI.
79
+
80
+ For an Astro site without Starlight, the same steps apply except for `customCss`; give the diagram a wide container.
81
+
82
+ ## Publish to GitHub Pages
83
+
84
+ The template ships `.github/workflows/deploy.yml`. For an existing site, add a workflow that installs, runs `pnpm check`, builds with `SITE_URL=https://<owner>.github.io` and `BASE_PATH=/<repo>`, and deploys `dist/` with `actions/deploy-pages`. In `astro.config.mjs` use `site: process.env.SITE_URL, base: process.env.BASE_PATH`.
85
+
86
+ The repository's **Settings → Pages → Source** must be set to **GitHub Actions** once. Until it is, the deploy step fails with a 404; the template's workflow detects that and skips the step with a notice.
87
+
88
+ ## Install this skill in another project
89
+
90
+ ```sh
91
+ npx skills add The-Package-Labs/idocs --skill idocs # this project
92
+ npx skills add The-Package-Labs/idocs --skill idocs -g # every project
93
+ ```
94
+
95
+ Projects created with `create-idocs` already contain it in `.claude/skills/idocs`.
@@ -0,0 +1,49 @@
1
+ # Troubleshooting
2
+
3
+ Run `idocs check --json` first. Each message has a file, line, column and often a hint.
4
+
5
+ ## Diagram errors
6
+
7
+ | Message | Fix |
8
+ |---|---|
9
+ | `Edge from "x" is not a node` / `Edge to "x" ...` | A typo or an undeclared node. The hint names the nearest id. |
10
+ | `"x" is not a node` (in a scenario) | Same, inside a step, `via`, `lanes` or a view's `include`. |
11
+ | `No path from "a" to "b" in view "v"` | The step needs a route. Declare an edge between them (it can be `hidden: true`), or add `via: [...]` through nodes that are connected. |
12
+ | `Node "x" is not in view "v"` | The scenario's view does not include `x`. Add it to `include`, or set the scenario's `view:`. |
13
+ | `Unknown key "titel"` | A typo. The hint suggests the right key; the message lists allowed keys. |
14
+ | `Not a recognised step` | Steps are `a -> b: label`, `at node: label`, or `par:` with a list. Check spacing and the arrow. |
15
+ | `A step with at needs a label or a title` | `at x:` needs text: `at x: what happens`. |
16
+ | `"x" is not a direct member of group "g"` | Entries in a group's `rows:` must be nodes or groups whose `in:` is that group. |
17
+ | `Groups are nested in a cycle` | A group's `in:` chain loops back on itself. |
18
+ | `Edge id "e" is used twice` | Give edges distinct ids or drop the ids. |
19
+ | `Unknown edge kind "x"` | Use a built-in kind or define it under `edgeKinds:`. |
20
+ | warning `Unknown icon "x"` | `idocs icons search x`, then use the suggested name. |
21
+ | warning `Doc file "x" was not found` | A `doc:` path that does not exist. Paths are relative to the diagram folder. |
22
+ | warning `... appears in the story but is in no lane` | A `lanes:` list that leaves out a node the scenario uses. Add it to a lane or ignore: it gets its own lane at the end. |
23
+ | warning `Node "x" cites "src/y.ts", which does not exist` | A `refs:` path that moved. Update the diagram or the reference. |
24
+
25
+ ## YAML pitfalls
26
+
27
+ - **Flow maps and commas.** In `{ label: a, b, kind: x }` the comma ends the value. Quote it: `{ label: "a, b", kind: x }`. Same for a colon followed by a space.
28
+ - **Values starting with `{`, `[`, `*`, `&`, `!`, `%`, `@` or a backtick** need quotes.
29
+ - **Ports and times** like `:8080` need quotes: `sub: ":8080"`.
30
+ - **Indentation** is spaces only, two per level. Steps under `phases:` sit under that phase's `steps:`.
31
+ - **Multi-line text** uses `|` and indentation:
32
+ ```yaml
33
+ detail: |
34
+ first line
35
+ second line
36
+ ```
37
+ - **`Invalid input: expected string, received undefined`** at a path: a required field is missing there.
38
+
39
+ ## The site
40
+
41
+ | Symptom | Check |
42
+ |---|---|
43
+ | `<Diagram name="x"> does not match a diagram` | The folder name differs. The error lists the available names. |
44
+ | Build fails with `Diagram errors:` | Run `idocs check`; the build fails on any diagram error by design. |
45
+ | The diagram shows "Loading diagram..." and never appears | A browser console error. Is `react()` from `@astrojs/react` in `astro.config.mjs`? |
46
+ | Edits to a diagram do not show in dev | Save the file again; if the compiler itself changed (an idocs upgrade), restart the dev server. |
47
+ | The page is narrow with a tiny diagram | The Starlight content column. Add `@the-package-labs/idocs-astro/starlight.css` to Starlight's `customCss`. |
48
+ | Fonts differ from the screenshots | The templates use IBM Plex via `@fontsource/ibm-plex-sans` and `-mono`; add them or set `--idocs-sans` and `--idocs-mono`. |
49
+ | Diagram looks blurry when zoomed | Use the current `@the-package-labs/idocs-react`; older builds kept the zoom layer on the GPU. |
@@ -0,0 +1,60 @@
1
+ name: Deploy to GitHub Pages
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ workflow_dispatch:
6
+
7
+ permissions:
8
+ contents: read
9
+ pages: write
10
+ id-token: write
11
+
12
+ concurrency:
13
+ group: pages
14
+ cancel-in-progress: true
15
+
16
+ jobs:
17
+ build:
18
+ runs-on: ubuntu-latest
19
+ outputs:
20
+ pages: ${{ steps.pages.outputs.enabled }}
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - uses: pnpm/action-setup@v4
24
+ - uses: actions/setup-node@v4
25
+ with:
26
+ node-version: 22
27
+ cache: pnpm
28
+ - run: pnpm install --frozen-lockfile
29
+ - run: pnpm check --strict
30
+ - run: pnpm build
31
+ env:
32
+ # Project pages live under /<repo>/. Remove BASE_PATH if you use a custom domain.
33
+ SITE_URL: https://${{ github.repository_owner }}.github.io
34
+ BASE_PATH: /${{ github.event.repository.name }}
35
+ - id: pages
36
+ name: Is GitHub Pages enabled?
37
+ env:
38
+ GH_TOKEN: ${{ github.token }}
39
+ run: |
40
+ if gh api "repos/${{ github.repository }}/pages" --silent 2>/dev/null; then
41
+ echo "enabled=true" >> "$GITHUB_OUTPUT"
42
+ else
43
+ echo "enabled=false" >> "$GITHUB_OUTPUT"
44
+ echo "::notice title=GitHub Pages is not enabled::Open Settings > Pages, set the source to 'GitHub Actions', then re-run this workflow. The site was built, but not deployed."
45
+ fi
46
+ - uses: actions/upload-pages-artifact@v3
47
+ if: steps.pages.outputs.enabled == 'true'
48
+ with:
49
+ path: dist
50
+
51
+ deploy:
52
+ needs: build
53
+ if: needs.build.outputs.pages == 'true'
54
+ runs-on: ubuntu-latest
55
+ environment:
56
+ name: github-pages
57
+ url: ${{ steps.deployment.outputs.page_url }}
58
+ steps:
59
+ - id: deployment
60
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,27 @@
1
+ # My docs
2
+
3
+ Documentation site built with [idocs](https://github.com/The-Package-Labs/idocs): Astro + Starlight pages with architecture diagrams that readers can click and play.
4
+
5
+ ## Commands
6
+
7
+ ```sh
8
+ pnpm install
9
+ pnpm dev # http://localhost:4321
10
+ pnpm check [--json] # validate every diagram (errors say file:line:col and suggest fixes)
11
+ pnpm build # static site in dist/
12
+ pnpm idocs new <name> # new diagram folder
13
+ pnpm idocs list --json # what diagrams, views and scenarios exist
14
+ pnpm idocs icons search <q> # find an icon name
15
+ ```
16
+
17
+ ## Where things are
18
+
19
+ - `diagrams/<name>/diagram.yaml`: one diagram (nodes, groups, edges, views, scenarios)
20
+ - `diagrams/<name>/nodes/<id>.md`: what a reader sees when they click that box
21
+ - `diagrams/<name>/scenarios/<id>.yaml`: a long scenario in its own file
22
+ - `src/content/docs/*.mdx`: the pages; embed a diagram with `<Diagram name="<name>" />`
23
+ - `src/styles/custom.css`: theme tokens (`--idocs-*`)
24
+
25
+ ## Working on diagrams
26
+
27
+ Use the `idocs` skill (`.claude/skills/idocs`). Read the code you are documenting, write the YAML, then **always** run `pnpm check` and look at the rendered page before you finish. Never invent services, ports or flows.
@@ -0,0 +1,30 @@
1
+ # My docs
2
+
3
+ Interactive architecture docs, built with [idocs](https://github.com/The-Package-Labs/idocs).
4
+
5
+ ```sh
6
+ pnpm install
7
+ pnpm dev # http://localhost:4321
8
+ ```
9
+
10
+ Diagrams live in `diagrams/`, pages in `src/content/docs/`. Start with `diagrams/shop/diagram.yaml`, change a label, and save: the page reloads.
11
+
12
+ | | |
13
+ |---|---|
14
+ | `pnpm check` | validate diagrams |
15
+ | `pnpm idocs new <name>` | add a diagram |
16
+ | `pnpm build` | build the static site into `dist/` |
17
+
18
+ ## Publish
19
+
20
+ Push to GitHub, open **Settings → Pages**, and choose **GitHub Actions** as the source. The workflow in `.github/workflows/deploy.yml` builds and publishes on every push to `main`.
21
+
22
+ ## Draw with an AI agent
23
+
24
+ The `idocs` skill in `.claude/skills/` teaches Claude Code the diagram format. For other agents or other projects: `npx skills add The-Package-Labs/idocs --skill idocs`.
25
+
26
+ ## Update idocs
27
+
28
+ ```sh
29
+ pnpm up "@the-package-labs/idocs-*" --latest
30
+ ```
@@ -0,0 +1,6 @@
1
+ node_modules
2
+ dist
3
+ .astro
4
+ .DS_Store
5
+ *.log
6
+ .env
@@ -0,0 +1,4 @@
1
+ # pnpm 10+ asks you to approve dependency build scripts. These two are safe and needed.
2
+ allowBuilds:
3
+ esbuild: true
4
+ sharp: true
@@ -0,0 +1,32 @@
1
+ import react from '@astrojs/react'
2
+ import starlight from '@astrojs/starlight'
3
+ import idocs from '@the-package-labs/idocs-astro'
4
+ import { defineConfig } from 'astro/config'
5
+
6
+ // Publishing to GitHub Pages: the deploy workflow sets SITE_URL and BASE_PATH for you.
7
+ export default defineConfig({
8
+ site: process.env.SITE_URL,
9
+ base: process.env.BASE_PATH,
10
+ integrations: [
11
+ idocs(),
12
+ react(),
13
+ starlight({
14
+ title: 'My docs',
15
+ description: 'How our system works, with diagrams you can play.',
16
+ customCss: [
17
+ '@fontsource/ibm-plex-sans/400.css',
18
+ '@fontsource/ibm-plex-sans/500.css',
19
+ '@fontsource/ibm-plex-sans/600.css',
20
+ '@fontsource/ibm-plex-mono/400.css',
21
+ '@fontsource/ibm-plex-mono/500.css',
22
+ '@the-package-labs/idocs-astro/starlight.css',
23
+ './src/styles/custom.css',
24
+ ],
25
+ sidebar: [
26
+ { label: 'Overview', slug: 'index' },
27
+ { label: 'How the shop works', slug: 'architecture' },
28
+ { label: 'Editing diagrams', slug: 'editing' },
29
+ ],
30
+ }),
31
+ ],
32
+ })