|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +Guidance for Claude Code (and other AI assistants) working in this repository. |
| 4 | + |
| 5 | +## Project overview |
| 6 | + |
| 7 | +**Kratos FlowGraph** is a browser-based, node-graph editor for configuring |
| 8 | +[KratosMultiphysics](https://github.com/KratosMultiphysics/Kratos) simulations. Users wire nodes |
| 9 | +(analysis stages, solvers, materials, processes, model parts, outputs) on a canvas, and FlowGraph |
| 10 | +generates the Kratos `ProjectParameters.json` (and material files). |
| 11 | + |
| 12 | +It is **not** a bundled SPA. It is: |
| 13 | + |
| 14 | +- a small **Express + EJS** server (`app.js`) that serves a single canvas page and optionally |
| 15 | + launches Kratos, plus |
| 16 | +- a large library of plain-ESM **[litegraph.js](https://github.com/jagenjo/litegraph.js)** node |
| 17 | + modules served statically from `public/js/nodes/`. |
| 18 | + |
| 19 | +There is **no build step** for the application itself. The published NPM package is |
| 20 | +`kratos-flowgraph`, exposed as a runnable CLI. |
| 21 | + |
| 22 | +## Run / develop |
| 23 | + |
| 24 | +```sh |
| 25 | +npm install |
| 26 | +npm start # node app.js — serves the editor on http://localhost:8182 |
| 27 | +npm run devstart # nodemon app.js — auto-reload during development |
| 28 | +``` |
| 29 | + |
| 30 | +- Port and Kratos paths come from `config/default.json` (via the `config` package). Switch config |
| 31 | + files with `NODE_ENV` (e.g. `NODE_ENV=debug` → `config/debug.json`). |
| 32 | +- The CLI entry point is `bin/kratos-flowgraph.js`; it `chdir`s to the package root (so |
| 33 | + CWD-relative lookups in `src/module_importer.js` and `config` work) and then imports `app.js`. |
| 34 | +- The editor UI needs **no Kratos install**; `kratos_root` / `working_dir` / `python_binary` are |
| 35 | + only used by the optional `/run_simulation` route. |
| 36 | + |
| 37 | +## Architecture map |
| 38 | + |
| 39 | +| Path | Role | |
| 40 | +| --- | --- | |
| 41 | +| `app.js` | Express server: serves `public/`, renders `views/index.ejs`, routes `/upload_json`, `/run_simulation`. | |
| 42 | +| `bin/kratos-flowgraph.js` | CLI launcher (chdir to package root, then run app). | |
| 43 | +| `src/module_importer.js` | Auto-discovers node/widget files under `public/js/nodes` & `public/js/widgets`. | |
| 44 | +| `views/index.ejs` | The entire UI: toolbar, `<canvas class="graphcanvas">`, JSON side panel. | |
| 45 | +| `public/js/code.js` | Bootstraps the litegraph editor; wires the toolbar; exposes `window.graph`/`window.graphcanvas`. | |
| 46 | +| `public/js/side.js` | Side panel toggle (`openNav`), `addViewerNode`, experimental LLM hook. | |
| 47 | +| `public/js/litegraph/litegraph.core.js` | Vendored litegraph engine. | |
| 48 | +| `public/js/extensions/*.js` | Core customisations: `extended_menu` (categorized add-node menu), `draw_node`/`draw_widget`, `compute_size`, `remove_node`/`remove_widget`, `custom_node_panel`, `selection_import`, `load_project_parameters` (import ProjectParameters → graph). | |
| 49 | +| `public/js/nodes/**` | The node library, organized by Kratos domain (see the docs Node Reference). | |
| 50 | +| `public/js/model_manager.js`, `problem_manager.js` | Track model parts / global problem state across connections. | |
| 51 | +| `config/default.json` | Runtime config (host, port, kratos_root, working_dir, python_binary). | |
| 52 | +| `doc/` | VitePress documentation (see below). | |
| 53 | +| `scripts/screenshots/capture.spec.js` | Playwright screenshot capture for the docs. | |
| 54 | + |
| 55 | +## Adding a node |
| 56 | + |
| 57 | +Drop a `.js` file under `public/js/nodes/<category>/` that defines a class and calls |
| 58 | +`LiteGraph.registerNodeType("Category/Sub/Name", Class)`. It is **auto-discovered** — no manifest to |
| 59 | +edit. The registered type path drives the context-menu category. Reuse existing slot types so the |
| 60 | +node connects to the rest of the library. See `doc/development/adding-a-node.md` for a template. |
| 61 | + |
| 62 | +## Documentation & screenshots |
| 63 | + |
| 64 | +The docs live in `doc/` (VitePress) with screenshots under `doc/public/screenshots/`. |
| 65 | + |
| 66 | +```sh |
| 67 | +npm run docs:dev # local docs dev server |
| 68 | +npm run docs:build # build static docs into doc/.vitepress/dist |
| 69 | +npm run docs:screenshots # Playwright: boot the app, capture UI screenshots (needs `npx playwright install chromium` once) |
| 70 | +``` |
| 71 | + |
| 72 | +## Publishing |
| 73 | + |
| 74 | +- **NPM**: bump `version` in `package.json`, push, then create a **GitHub Release**. The |
| 75 | + `.github/workflows/publish.yml` workflow publishes `kratos-flowgraph` using the `NPM_TOKEN` secret. |
| 76 | + Verify the tarball with `npm pack --dry-run`. |
| 77 | +- **Docs**: pushing to `master` triggers `.github/workflows/docs.yml`, which builds and deploys the |
| 78 | + VitePress site to GitHub Pages (requires Pages source = "GitHub Actions", one-time). |
| 79 | + |
| 80 | +## ⚠️ Mandatory documentation sync clause |
| 81 | + |
| 82 | +> **Whenever a new feature, node, or user-facing change is added, you MUST update `CLAUDE.md`, |
| 83 | +> `README.md`, and the `doc/` VitePress documentation in the same change. If the change alters the |
| 84 | +> UI, regenerate the Playwright screenshots with `npm run docs:screenshots`. A feature is NOT |
| 85 | +> complete until these are updated.** |
| 86 | +
|
| 87 | +Concretely, when you change behaviour: |
| 88 | + |
| 89 | +1. Update `CLAUDE.md` if the architecture, commands or workflow changed. |
| 90 | +2. Update `README.md` if the quick-start, features or install steps changed. |
| 91 | +3. Update the relevant page(s) under `doc/` (guide, node reference, or development). |
| 92 | +4. Re-run `npm run docs:screenshots` if the UI changed, and commit the updated images. |
| 93 | + |
| 94 | +## Conventions & notes |
| 95 | + |
| 96 | +- Node names, slot types and emitted JSON should match the Kratos schema for the concept modelled. |
| 97 | +- Runtime dependencies (`express`, `cors`, `ejs`, `config`) live under `dependencies` — do **not** |
| 98 | + move them back to `devDependencies`, or the published CLI will not run. |
| 99 | +- `package-lock.json` is gitignored; there is no committed lockfile. |
| 100 | +- Prefer extending existing base classes (`Material`, `AnalysisStage`, `Process`, …) for new nodes. |
0 commit comments