flowgraph-ai 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 404FoundingFather
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,210 @@
1
+ # FlowGraph
2
+
3
+ Machine-verifiable maintenance contracts for codebases. Capture what breaks when code changes.
4
+
5
+ ## What is FlowGraph?
6
+
7
+ FlowGraph is a lightweight contract system that answers one question: **"If I change X, what else breaks?"**
8
+
9
+ It captures the invisible maintenance relationships in your codebase — the ones where changing a database table silently breaks a repository method, or adding an enum value requires updating three switch statements in different files. These are the bugs that compilers don't catch and code review misses.
10
+
11
+ FlowGraph is designed for AI coding agents and human developers alike. It's not documentation, not a dependency graph, and not a type system. It's a maintenance contract.
12
+
13
+ ### What goes in a FlowGraph:
14
+
15
+ - **co_change edges** — "if you change X, you must also update Y" (highest value)
16
+ - **validates edges** — runtime schema validation boundaries (Zod, Joi, etc.)
17
+ - **Invariants** — cross-cutting rules that span multiple files
18
+ - **Complex flows** — multi-file execution paths with non-trivial branching
19
+
20
+ ### What does NOT go in a FlowGraph:
21
+
22
+ - Function call trees (read the code)
23
+ - Request/response shapes (that's documentation)
24
+ - Anything the type checker already enforces
25
+ - Simple linear flows with no branching
26
+
27
+ ## Quick Start
28
+
29
+ ```bash
30
+ # Verify your flowgraph against source code
31
+ npx flowgraph-ai verify
32
+
33
+ # See what breaks if you change a specific node
34
+ npx flowgraph-ai verify --impact table:users
35
+
36
+ # Render as Mermaid diagrams (outputs markdown)
37
+ npx flowgraph-ai render
38
+
39
+ # Create a starter flowgraph for your project
40
+ npx flowgraph-ai init
41
+ ```
42
+
43
+ ## Example
44
+
45
+ Here's a minimal flowgraph for a todo API ([full example](./example/)):
46
+
47
+ ```json
48
+ {
49
+ "$flowgraph": "2.1",
50
+ "meta": { "name": "todo-api", "root": "src/" },
51
+ "nodes": {
52
+ "type:TaskStatus": {
53
+ "kind": "type",
54
+ "loc": "types.ts:5",
55
+ "values": ["pending", "in_progress", "done", "cancelled"]
56
+ },
57
+ "table:tasks": {
58
+ "kind": "table",
59
+ "loc": "../schema.sql:1"
60
+ },
61
+ "method:TaskRepository.create": {
62
+ "kind": "method",
63
+ "loc": "repository.ts:11"
64
+ }
65
+ },
66
+ "edges": [
67
+ {
68
+ "from": "table:tasks",
69
+ "to": "method:TaskRepository.create",
70
+ "rel": "co_change",
71
+ "note": "column changes require INSERT query update"
72
+ }
73
+ ],
74
+ "flows": {},
75
+ "invariants": []
76
+ }
77
+ ```
78
+
79
+ This single `co_change` edge says: if you add a column to the `tasks` table, you must also update `TaskRepository.create` — because it has a raw INSERT query that lists columns explicitly. The verifier confirms both sides of this contract exist in your source code.
80
+
81
+ ## CLI Commands
82
+
83
+ ### `flowgraph verify [file]`
84
+
85
+ Runs four verification phases against your source code:
86
+
87
+ 1. **Structural** — every node's `loc` points to a real file and the expected artifact exists (type definition, method signature, CREATE TABLE, route handler, etc.)
88
+ 2. **Relational** — edges are valid (validates edges check for schema.parse() calls, co_change edges check both nodes exist)
89
+ 3. **Sequential** — flow steps reference existing nodes and branch targets are reachable
90
+ 4. **Invariant** — scoped nodes and files exist (custom invariant logic requires a project-specific checker)
91
+
92
+ Output: `PASS`, `FAIL`, or `WARN` for each check.
93
+
94
+ If no file is specified, auto-discovers `*.flowgraph.json` in the current directory.
95
+
96
+ ### `flowgraph verify --impact <node:id>`
97
+
98
+ Shows everything affected by changing a node:
99
+ - Outgoing/incoming edges (with `co_change` edges highlighted)
100
+ - Flows containing the node
101
+ - Invariants scoping the node
102
+
103
+ ### `flowgraph-ai render [file]`
104
+
105
+ Generates a markdown file with Mermaid diagrams:
106
+ - **Dependency graph** — nodes grouped by kind, edges styled by type (dashed for co_change, solid for others)
107
+ - **Flow diagrams** — one per flow, with decision diamonds for branching and terminal nodes for DONE/FAIL
108
+ - **Invariants table** — all invariants with their enforcement notes
109
+
110
+ Output is written next to the input file (e.g., `my-project.flowgraph.json` -> `my-project.flowgraph.md`). View it on GitHub (native Mermaid support), in VS Code with a Mermaid extension, or paste diagrams into [mermaid.live](https://mermaid.live).
111
+
112
+ ### `flowgraph-ai init`
113
+
114
+ Creates a starter `<project-name>.flowgraph.json` in the current directory.
115
+
116
+ ## Specification
117
+
118
+ See [flowgraph-spec-v2.1.md](./flowgraph-spec-v2.1.md) for the full FlowGraph specification, including:
119
+ - All node kinds and their fields
120
+ - Edge types and when to use each
121
+ - Flow syntax and branching
122
+ - Invariant structure
123
+ - Extensibility with custom node kinds
124
+
125
+ ## Integrating with Claude Code
126
+
127
+ FlowGraph is designed to be read by AI coding agents. To hook it up to [Claude Code](https://docs.anthropic.com/en/docs/claude-code):
128
+
129
+ 1. **Copy the spec into your project** so the agent can read it locally:
130
+ ```bash
131
+ # from your project root
132
+ cp node_modules/flowgraph-ai/flowgraph-spec-v2.1.md flowgraph/
133
+ # or if you haven't installed it:
134
+ curl -sL https://raw.githubusercontent.com/404FoundingFather/flowgraph/main/flowgraph-spec-v2.1.md -o flowgraph/flowgraph-spec-v2.1.md
135
+ ```
136
+
137
+ 2. **Add a FlowGraph section** to your `.claude/CLAUDE.md` — here's a ready-to-paste template (replace the paths to match your project):
138
+
139
+ ````markdown
140
+ ## FlowGraph
141
+
142
+ This project uses [FlowGraph](https://github.com/404FoundingFather/flowgraph) for machine-verifiable maintenance contracts.
143
+
144
+ - **`flowgraph/your-project.flowgraph.json`** — The contract: nodes, co_change edges, invariants, and flows. Read this first for structural understanding of how components connect.
145
+ - **`flowgraph/flowgraph-spec-v2.1.md`** — The FlowGraph specification (how to read and write flowgraph files). Reference this when creating or updating flowgraph entries.
146
+
147
+ ### The three elements:
148
+
149
+ 1. **co_change edges** (primary) — "if you change X, you must also update Y." Every table and key type should have co_change edges to the methods/endpoints that would break if the schema changed.
150
+ 2. **Invariants** — Cross-cutting rules that must hold regardless of what changes. Each has an `enforce` field explaining where/how it's enforced.
151
+ 3. **Complex flows** — Multi-file execution paths with non-trivial branching (3+ cases). Only flows where the branching logic spans multiple files and isn't obvious from reading one call site.
152
+
153
+ ### Before modifying code:
154
+
155
+ - **Impact check** — Run `npx flowgraph-ai verify --impact <node:id>` to see co_change requirements, containing flows, and scoped invariants.
156
+
157
+ ### After modifying code:
158
+
159
+ 1. **Verify** — Run `npx flowgraph-ai verify` to check the flowgraph still matches source.
160
+ 2. **Update** — If verification fails:
161
+ - Changed a table schema? Update co_change target methods/endpoints.
162
+ - New table? Add `table:` node with loc, fk, indexes + co_change edges to its repository methods.
163
+ - New cross-cutting rule? Add an `invariants` entry with `enforce`.
164
+ - Changed a complex multi-file flow with branching? Update the relevant `flows` entry.
165
+ 3. **Re-verify** — Run `npx flowgraph-ai verify` again to confirm 0 FAIL.
166
+
167
+ ### What does NOT belong:
168
+
169
+ - **calls/reads/writes edges** — Visible by reading the call site. co_change captures what matters.
170
+ - **Method pre/post conditions** — Restates what the method name and types already say.
171
+ - **Endpoint request/response shapes** — Documentation, not contract.
172
+ - **Simple linear flows** — If a flow is just "endpoint -> service -> repo -> done" with no branching, don't add it.
173
+ - **Nodes not referenced** by any co_change edge, invariant, or complex flow.
174
+ ````
175
+
176
+ The template points the agent at two files: the flowgraph JSON (the contract itself) and the spec (how to read/write it). This gives it enough context to check impact before changing, verify after changing, update the flowgraph when verification fails, and know what does and doesn't belong.
177
+
178
+ ### Other AI agents
179
+
180
+ The same instructions work for any AI coding agent that reads project configuration. The key points to convey:
181
+
182
+ 1. Read the flowgraph JSON for structural understanding of the codebase
183
+ 2. Run `--impact` before modifying code to see what else needs to change
184
+ 3. Run `verify` after modifying code to confirm contracts still hold
185
+ 4. Keep the flowgraph lean — only high-value maintenance contracts
186
+
187
+ ## Getting Started from Scratch
188
+
189
+ 1. **Start small.** Run `npx flowgraph-ai init` and replace the example with 5-10 `co_change` edges from your project. Focus on database table -> repository method pairs and enum -> switch statement pairs.
190
+
191
+ 2. **Add invariants.** Write down 2-3 cross-cutting rules that a new contributor would violate without being told.
192
+
193
+ 3. **Add validates edges** where runtime validation (Zod, Joi, etc.) marks a trust boundary.
194
+
195
+ 4. **Only add flows** for complex multi-file paths with 3+ branching cases. Most projects have 2-5 of these.
196
+
197
+ See the [Getting Started section of the spec](./flowgraph-spec-v2.1.md#getting-started) for detailed guidance.
198
+
199
+ ## Philosophy
200
+
201
+ FlowGraph follows a "less is more" approach:
202
+
203
+ - Every element must prevent a real bug when code changes
204
+ - If it would drift silently without causing bugs, it doesn't belong
205
+ - Nodes exist because they're referenced by edges, flows, or invariants — not to document the codebase
206
+ - The maintenance cost of each element must be justified by the bugs it prevents
207
+
208
+ ## License
209
+
210
+ MIT