@timo9378/flow2code 0.1.2 → 0.1.3
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/CHANGELOG.md +56 -56
- package/LICENSE +21 -21
- package/README.md +230 -223
- package/dist/cli.js +61 -2
- package/dist/server.d.ts +27 -27
- package/dist/server.js +876 -4
- package/out/404.html +1 -1
- package/out/__next.__PAGE__.txt +4 -4
- package/out/__next._full.txt +13 -13
- package/out/__next._head.txt +4 -4
- package/out/__next._index.txt +6 -6
- package/out/__next._tree.txt +2 -2
- package/out/_next/static/chunks/{41ec06cb3e44c96a.js → 5f1a9fec0e69c483.js} +2 -2
- package/out/_next/static/chunks/6b84376656bd9887.js +1 -0
- package/out/_next/static/chunks/993eabba22c07d39.js +54 -0
- package/out/_next/static/chunks/a6dad97d9634a72d.js.map +1 -1
- package/out/_next/static/chunks/ab8888d4b78b94be.js +5 -0
- package/out/_next/static/chunks/acf223168ac429f7.js +1 -0
- package/out/_next/static/chunks/{8486af13ea541d4d.js → b112c2f519e4b429.js} +1 -1
- package/out/_next/static/chunks/{4b43c69e91d19eee.js → b163b5d7cccbcf42.js} +1 -1
- package/out/_next/static/chunks/b6e8711267bccbbd.js +1 -0
- package/out/_next/static/chunks/c8a26302d935bf6e.css +1 -0
- package/out/_next/static/chunks/fbca595129527827.js +1 -0
- package/out/_next/static/chunks/{turbopack-b95472a0b02a2729.js → turbopack-576234c945ffdc44.js} +1 -1
- package/out/_not-found/__next._full.txt +11 -11
- package/out/_not-found/__next._head.txt +4 -4
- package/out/_not-found/__next._index.txt +6 -6
- package/out/_not-found/{__next._not-found.__PAGE__.txt → __next._not-found/__PAGE__.txt} +2 -2
- package/out/_not-found/__next._not-found.txt +3 -3
- package/out/_not-found/__next._tree.txt +2 -2
- package/out/_not-found.html +1 -1
- package/out/_not-found.txt +11 -11
- package/out/index.html +2 -2
- package/out/index.txt +13 -13
- package/package.json +123 -121
- package/scripts/postinstall.cjs +23 -0
- package/out/_next/static/chunks/324e22de375c241a.css +0 -1
- package/out/_next/static/chunks/3638bc7cb3d72bbe.js +0 -379
- package/out/_next/static/chunks/46e882944a7f3aed.js +0 -1
- package/out/_next/static/chunks/59b058cf94cc555e.js +0 -1
- package/out/_next/static/chunks/6e36daee8960e188.js +0 -5
- package/out/_next/static/chunks/80a5431d4e78c469.js +0 -1
- package/out/_next/static/chunks/8a38426c5ed81587.js +0 -1
- package/out/_next/static/chunks/edbd80df6004e249.js +0 -52
- /package/out/_next/static/{dSD-EjLFfv3PUm7xo33fg → gs3QpnA696kN6tOSlwt6o}/_buildManifest.js +0 -0
- /package/out/_next/static/{dSD-EjLFfv3PUm7xo33fg → gs3QpnA696kN6tOSlwt6o}/_clientMiddlewareManifest.json +0 -0
- /package/out/_next/static/{dSD-EjLFfv3PUm7xo33fg → gs3QpnA696kN6tOSlwt6o}/_ssgManifest.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
|
-
|
|
8
|
-
## [0.1.0] — 2026-02-27
|
|
9
|
-
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
#### Core
|
|
13
|
-
- **Visual AST Compiler** — Flow-based IR → production-ready TypeScript
|
|
14
|
-
- **Headless compiler** — `import { compile } from "@timo9378/flow2code/compiler"` can be used standalone
|
|
15
|
-
- **CLI** — `flow2code compile`, `flow2code watch`, `flow2code migrate` commands
|
|
16
|
-
- **Standalone dev server** — Zero-dependency HTTP server (`flow2code serve`)
|
|
17
|
-
- **Plugin system** — `NodePlugin` interface + `PluginRegistry` factory pattern
|
|
18
|
-
- **15 built-in node types** — HTTP Webhook, Cron Job, Fetch API, SQL Query, Redis Cache, Custom Code, If/Else, For Loop, Try/Catch, Return Response, Declare Variable, Transform, Call Subflow, Manual Trigger
|
|
19
|
-
|
|
20
|
-
#### Platforms
|
|
21
|
-
- **Next.js** platform adapter (App Router)
|
|
22
|
-
- **Express** platform adapter
|
|
23
|
-
- **Cloudflare Workers** platform adapter
|
|
24
|
-
- Extensible `PlatformAdapter` interface, supports third-party platform registration
|
|
25
|
-
|
|
26
|
-
#### AI Features
|
|
27
|
-
- AI Flow Generator (OpenAI-compatible endpoints)
|
|
28
|
-
- Streaming support (SSE) + retry mechanism + token budget management
|
|
29
|
-
- Custom AI endpoint management (copilot-api / Gemini / Ollama)
|
|
30
|
-
- AI Code Review (automatic audit of generated IR)
|
|
31
|
-
- **IR Security Validator** — Scans AI-generated code for malicious patterns (eval, child_process, fs, etc.)
|
|
32
|
-
|
|
33
|
-
#### DX Improvements
|
|
34
|
-
- **Runtime Error Tracer** — Reverse-lookup from Error.stack via Source Map to canvas node
|
|
35
|
-
- **Git-Native Split Storage** — YAML directory format, supports git diff
|
|
36
|
-
- **Edit-Time Type Inference** — Real-time inference of upstream node flowState types
|
|
37
|
-
- **Dynamic Node Registry** — Extensible node definition system
|
|
38
|
-
- **Expression Autocomplete** — Expression input auto-completion (flowState fields + methods)
|
|
39
|
-
- **Decompiler** — TypeScript → FlowIR reverse parser (ts-morph AST analysis)
|
|
40
|
-
|
|
41
|
-
#### Quality
|
|
42
|
-
- TypeScript strict mode
|
|
43
|
-
- ESLint v10 flat config (0 errors)
|
|
44
|
-
- 354 tests / 31 test files (vitest)
|
|
45
|
-
- GitHub Actions CI (Node.js 20/22 matrix)
|
|
46
|
-
- `.husky/pre-push` CI guard
|
|
47
|
-
- Content-Security-Policy headers
|
|
48
|
-
- TypeDoc API reference generation
|
|
49
|
-
- Zustand undo/redo isolated slice
|
|
50
|
-
|
|
51
|
-
### Security
|
|
52
|
-
- IR Security Validator (`validateIRSecurity()`) three-tier threat detection
|
|
53
|
-
- Custom Code dangerous API compile-time warnings
|
|
54
|
-
- CSP / X-Content-Type-Options / X-Frame-Options / X-XSS-Protection headers
|
|
55
|
-
- 2MB body size limit
|
|
56
|
-
- IR structural validation (cycle detection, orphan node detection)
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] — 2026-02-27
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
#### Core
|
|
13
|
+
- **Visual AST Compiler** — Flow-based IR → production-ready TypeScript
|
|
14
|
+
- **Headless compiler** — `import { compile } from "@timo9378/flow2code/compiler"` can be used standalone
|
|
15
|
+
- **CLI** — `flow2code compile`, `flow2code watch`, `flow2code migrate` commands
|
|
16
|
+
- **Standalone dev server** — Zero-dependency HTTP server (`flow2code serve`)
|
|
17
|
+
- **Plugin system** — `NodePlugin` interface + `PluginRegistry` factory pattern
|
|
18
|
+
- **15 built-in node types** — HTTP Webhook, Cron Job, Fetch API, SQL Query, Redis Cache, Custom Code, If/Else, For Loop, Try/Catch, Return Response, Declare Variable, Transform, Call Subflow, Manual Trigger
|
|
19
|
+
|
|
20
|
+
#### Platforms
|
|
21
|
+
- **Next.js** platform adapter (App Router)
|
|
22
|
+
- **Express** platform adapter
|
|
23
|
+
- **Cloudflare Workers** platform adapter
|
|
24
|
+
- Extensible `PlatformAdapter` interface, supports third-party platform registration
|
|
25
|
+
|
|
26
|
+
#### AI Features
|
|
27
|
+
- AI Flow Generator (OpenAI-compatible endpoints)
|
|
28
|
+
- Streaming support (SSE) + retry mechanism + token budget management
|
|
29
|
+
- Custom AI endpoint management (copilot-api / Gemini / Ollama)
|
|
30
|
+
- AI Code Review (automatic audit of generated IR)
|
|
31
|
+
- **IR Security Validator** — Scans AI-generated code for malicious patterns (eval, child_process, fs, etc.)
|
|
32
|
+
|
|
33
|
+
#### DX Improvements
|
|
34
|
+
- **Runtime Error Tracer** — Reverse-lookup from Error.stack via Source Map to canvas node
|
|
35
|
+
- **Git-Native Split Storage** — YAML directory format, supports git diff
|
|
36
|
+
- **Edit-Time Type Inference** — Real-time inference of upstream node flowState types
|
|
37
|
+
- **Dynamic Node Registry** — Extensible node definition system
|
|
38
|
+
- **Expression Autocomplete** — Expression input auto-completion (flowState fields + methods)
|
|
39
|
+
- **Decompiler** — TypeScript → FlowIR reverse parser (ts-morph AST analysis)
|
|
40
|
+
|
|
41
|
+
#### Quality
|
|
42
|
+
- TypeScript strict mode
|
|
43
|
+
- ESLint v10 flat config (0 errors)
|
|
44
|
+
- 354 tests / 31 test files (vitest)
|
|
45
|
+
- GitHub Actions CI (Node.js 20/22 matrix)
|
|
46
|
+
- `.husky/pre-push` CI guard
|
|
47
|
+
- Content-Security-Policy headers
|
|
48
|
+
- TypeDoc API reference generation
|
|
49
|
+
- Zustand undo/redo isolated slice
|
|
50
|
+
|
|
51
|
+
### Security
|
|
52
|
+
- IR Security Validator (`validateIRSecurity()`) three-tier threat detection
|
|
53
|
+
- Custom Code dangerous API compile-time warnings
|
|
54
|
+
- CSP / X-Content-Type-Options / X-Frame-Options / X-XSS-Protection headers
|
|
55
|
+
- 2MB body size limit
|
|
56
|
+
- IR structural validation (cycle detection, orphan node detection)
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025-2026 flow2code contributors
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 flow2code contributors
|
|
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
CHANGED
|
@@ -1,223 +1,230 @@
|
|
|
1
|
-
# Flow2Code
|
|
2
|
-
|
|
3
|
-
**The Visual AST Compiler & Code Audit Tool for Backend APIs.**
|
|
4
|
-
|
|
5
|
-
> AI generates the code, Flow2Code decompiles it into a visual flow for you to audit, or compiles your visual flow into production-ready TypeScript.
|
|
6
|
-
|
|
7
|
-
[](https://github.com/timo9378/flow2code/actions/workflows/ci.yml)
|
|
8
|
-
[](LICENSE)
|
|
9
|
-
[](https://www.npmjs.com/package/@timo9378/flow2code)
|
|
10
|
-
[](https://www.npmjs.com/package/@timo9378/flow2code)
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
┌──────────────────────────────────┐
|
|
14
|
-
│ flow2code │
|
|
15
|
-
│ │
|
|
16
|
-
TS Code ──┤► decompile() → FlowIR → Canvas │ ← AI Code Audit
|
|
17
|
-
│ │
|
|
18
|
-
Canvas ──┤► FlowIR → compile() → TS Code │ ← Visual Compiler
|
|
19
|
-
└──────────────────────────────────┘
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Why Flow2Code?
|
|
23
|
-
|
|
24
|
-
| Traditional Low-Code | Flow2Code |
|
|
25
|
-
|---|---|
|
|
26
|
-
| Vendor-locked Runtime | **Zero-dependency** — outputs native TypeScript, deploy anywhere |
|
|
27
|
-
| Black-box nodes | **AST Compilation** — ts-morph generates syntactically correct code |
|
|
28
|
-
| Single platform | **Multi-platform** — Next.js, Express, Cloudflare Workers |
|
|
29
|
-
| Can't version control | **Git-friendly** — IR is JSON/YAML, diffable in PRs |
|
|
30
|
-
| Developers don't trust it | **Visual Audit** — bidirectional canvas ↔ code mapping |
|
|
31
|
-
|
|
32
|
-
## Core Features
|
|
33
|
-
|
|
34
|
-
- **AST Compilation, not interpretation** — Uses ts-morph to generate syntactically correct TypeScript. No string concatenation.
|
|
35
|
-
- **Zero-dependency output** — Generated code has no runtime dependency. Deploy directly to Vercel / AWS Lambda / Cloudflare.
|
|
36
|
-
- **Multi-platform output** — Same flow compiles to Next.js, Express, or Cloudflare Workers.
|
|
37
|
-
- **Per-instance Plugin System** — Node logic is extensible via plugins. Compile sessions are isolated.
|
|
38
|
-
- **flowState + Type Inference** — Cross-node data passing with TypeScript type safety.
|
|
39
|
-
- **Auto concurrency detection** — Topological sort identifies independent nodes, auto-generates `Promise.allSettled`.
|
|
40
|
-
- **Environment variable protection** — Secrets auto-converted to `process.env.XXX`.
|
|
41
|
-
- **Expression Parser** — Recursive Descent Parser for `$input` / `$trigger` / `$node.xxx` template syntax.
|
|
42
|
-
- **Decompiler** — TypeScript → FlowIR reverse parser for code auditing.
|
|
43
|
-
- **Semantic Diff** — Structural comparison of two IR versions.
|
|
44
|
-
|
|
45
|
-
## Tech Stack
|
|
46
|
-
|
|
47
|
-
| Layer | Technology |
|
|
48
|
-
|-------|-----------|
|
|
49
|
-
| Visual Canvas | Next.js 16 + React 19 + React Flow (@xyflow/react v12) |
|
|
50
|
-
| State Management | Zustand 5 |
|
|
51
|
-
| IR Specification | Custom JSON Schema + TypeScript Types |
|
|
52
|
-
| AST Engine | ts-morph 27 (TypeScript Compiler API Wrapper) |
|
|
53
|
-
| Platform Adapters | NextjsPlatform / ExpressPlatform / CloudflarePlatform |
|
|
54
|
-
| Plugin System | `createPluginRegistry()` factory (per-instance) |
|
|
55
|
-
| CLI | Commander.js + Chokidar |
|
|
56
|
-
| Testing | Vitest 4 — 354 tests across 31 test files |
|
|
57
|
-
| CI | GitHub Actions (Node 20/22 matrix) |
|
|
58
|
-
|
|
59
|
-
## Quick Start
|
|
60
|
-
|
|
61
|
-
### Install
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
npm
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
#
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
#
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
│
|
|
161
|
-
│
|
|
162
|
-
│
|
|
163
|
-
│
|
|
164
|
-
│ │
|
|
165
|
-
│ │
|
|
166
|
-
│ │ │ ├──
|
|
167
|
-
│ │ │ ├──
|
|
168
|
-
│ │ │
|
|
169
|
-
│ │
|
|
170
|
-
│ │ │
|
|
171
|
-
│ │ │
|
|
172
|
-
│ │ │
|
|
173
|
-
│ │ │
|
|
174
|
-
│ │ │
|
|
175
|
-
│ │ │
|
|
176
|
-
│ │ │
|
|
177
|
-
│ │ ├──
|
|
178
|
-
│ │ └──
|
|
179
|
-
│
|
|
180
|
-
│
|
|
181
|
-
├──
|
|
182
|
-
├── .
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
|
197
|
-
|
|
198
|
-
|
|
|
199
|
-
|
|
|
200
|
-
|
|
|
201
|
-
|
|
|
202
|
-
|
|
|
203
|
-
|
|
|
204
|
-
|
|
|
205
|
-
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
|
210
|
-
|
|
211
|
-
|
|
|
212
|
-
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
1
|
+
# Flow2Code
|
|
2
|
+
|
|
3
|
+
**The Visual AST Compiler & Code Audit Tool for Backend APIs.**
|
|
4
|
+
|
|
5
|
+
> AI generates the code, Flow2Code decompiles it into a visual flow for you to audit, or compiles your visual flow into production-ready TypeScript.
|
|
6
|
+
|
|
7
|
+
[](https://github.com/timo9378/flow2code/actions/workflows/ci.yml)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://www.npmjs.com/package/@timo9378/flow2code)
|
|
10
|
+
[](https://www.npmjs.com/package/@timo9378/flow2code)
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
┌──────────────────────────────────┐
|
|
14
|
+
│ flow2code │
|
|
15
|
+
│ │
|
|
16
|
+
TS Code ──┤► decompile() → FlowIR → Canvas │ ← AI Code Audit
|
|
17
|
+
│ │
|
|
18
|
+
Canvas ──┤► FlowIR → compile() → TS Code │ ← Visual Compiler
|
|
19
|
+
└──────────────────────────────────┘
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Why Flow2Code?
|
|
23
|
+
|
|
24
|
+
| Traditional Low-Code | Flow2Code |
|
|
25
|
+
|---|---|
|
|
26
|
+
| Vendor-locked Runtime | **Zero-dependency** — outputs native TypeScript, deploy anywhere |
|
|
27
|
+
| Black-box nodes | **AST Compilation** — ts-morph generates syntactically correct code |
|
|
28
|
+
| Single platform | **Multi-platform** — Next.js, Express, Cloudflare Workers |
|
|
29
|
+
| Can't version control | **Git-friendly** — IR is JSON/YAML, diffable in PRs |
|
|
30
|
+
| Developers don't trust it | **Visual Audit** — bidirectional canvas ↔ code mapping |
|
|
31
|
+
|
|
32
|
+
## Core Features
|
|
33
|
+
|
|
34
|
+
- **AST Compilation, not interpretation** — Uses ts-morph to generate syntactically correct TypeScript. No string concatenation.
|
|
35
|
+
- **Zero-dependency output** — Generated code has no runtime dependency. Deploy directly to Vercel / AWS Lambda / Cloudflare.
|
|
36
|
+
- **Multi-platform output** — Same flow compiles to Next.js, Express, or Cloudflare Workers.
|
|
37
|
+
- **Per-instance Plugin System** — Node logic is extensible via plugins. Compile sessions are isolated.
|
|
38
|
+
- **flowState + Type Inference** — Cross-node data passing with TypeScript type safety.
|
|
39
|
+
- **Auto concurrency detection** — Topological sort identifies independent nodes, auto-generates `Promise.allSettled`.
|
|
40
|
+
- **Environment variable protection** — Secrets auto-converted to `process.env.XXX`.
|
|
41
|
+
- **Expression Parser** — Recursive Descent Parser for `$input` / `$trigger` / `$node.xxx` template syntax.
|
|
42
|
+
- **Decompiler** — TypeScript → FlowIR reverse parser for code auditing.
|
|
43
|
+
- **Semantic Diff** — Structural comparison of two IR versions.
|
|
44
|
+
|
|
45
|
+
## Tech Stack
|
|
46
|
+
|
|
47
|
+
| Layer | Technology |
|
|
48
|
+
|-------|-----------|
|
|
49
|
+
| Visual Canvas | Next.js 16 + React 19 + React Flow (@xyflow/react v12) |
|
|
50
|
+
| State Management | Zustand 5 |
|
|
51
|
+
| IR Specification | Custom JSON Schema + TypeScript Types |
|
|
52
|
+
| AST Engine | ts-morph 27 (TypeScript Compiler API Wrapper) |
|
|
53
|
+
| Platform Adapters | NextjsPlatform / ExpressPlatform / CloudflarePlatform |
|
|
54
|
+
| Plugin System | `createPluginRegistry()` factory (per-instance) |
|
|
55
|
+
| CLI | Commander.js + Chokidar |
|
|
56
|
+
| Testing | Vitest 4 — 354 tests across 31 test files |
|
|
57
|
+
| CI | GitHub Actions (Node 20/22 matrix) |
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
### Install
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# npm
|
|
65
|
+
npm install @timo9378/flow2code
|
|
66
|
+
|
|
67
|
+
# pnpm
|
|
68
|
+
pnpm add @timo9378/flow2code
|
|
69
|
+
|
|
70
|
+
# yarn
|
|
71
|
+
yarn add @timo9378/flow2code
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### CLI Usage
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Initialize flow2code in your project
|
|
78
|
+
npx @timo9378/flow2code init
|
|
79
|
+
|
|
80
|
+
# Compile a .flow.json to TypeScript
|
|
81
|
+
npx @timo9378/flow2code compile .flow2code/flows/hello.flow.json --dry-run
|
|
82
|
+
|
|
83
|
+
# Compile with output
|
|
84
|
+
npx @timo9378/flow2code compile .flow2code/flows/hello.flow.json -o src/app/api/hello/route.ts
|
|
85
|
+
|
|
86
|
+
# Audit (decompile) any TypeScript file into a visual FlowIR
|
|
87
|
+
npx @timo9378/flow2code audit src/app/api/users/route.ts
|
|
88
|
+
|
|
89
|
+
# Start the visual editor
|
|
90
|
+
npx @timo9378/flow2code dev
|
|
91
|
+
|
|
92
|
+
# Watch mode (auto-compile on file change)
|
|
93
|
+
npx @timo9378/flow2code watch .flow2code/flows/
|
|
94
|
+
|
|
95
|
+
# Source Map trace — find which canvas node generated a line
|
|
96
|
+
npx @timo9378/flow2code trace src/app/api/hello/route.ts 15
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Library Usage
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { compile, validate, decompile } from "@timo9378/flow2code";
|
|
103
|
+
|
|
104
|
+
// Compile: FlowIR → TypeScript
|
|
105
|
+
const result = compile(ir, { platform: "nextjs" });
|
|
106
|
+
|
|
107
|
+
// Validate: Check IR structure
|
|
108
|
+
const check = validate(ir);
|
|
109
|
+
|
|
110
|
+
// Decompile: TypeScript → FlowIR (code audit)
|
|
111
|
+
const audit = decompile(code);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Development
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Clone and install
|
|
118
|
+
git clone https://github.com/timo9378/flow2code.git
|
|
119
|
+
cd flow2code && pnpm install
|
|
120
|
+
|
|
121
|
+
# Start dev server (visual canvas)
|
|
122
|
+
pnpm dev
|
|
123
|
+
|
|
124
|
+
# Run tests
|
|
125
|
+
pnpm test:run
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Headless Usage (No UI Required)
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { compile } from "@timo9378/flow2code/compiler";
|
|
132
|
+
|
|
133
|
+
const ir = JSON.parse(fs.readFileSync("my-api.flow.json", "utf-8"));
|
|
134
|
+
const result = compile(ir, { platform: "express" });
|
|
135
|
+
|
|
136
|
+
if (result.success) {
|
|
137
|
+
fs.writeFileSync(result.filePath!, result.code!);
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Decompiler (TypeScript → Visual Flow)
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { decompile } from "@timo9378/flow2code/compiler";
|
|
145
|
+
|
|
146
|
+
const code = fs.readFileSync("route.ts", "utf-8");
|
|
147
|
+
const result = decompile(code);
|
|
148
|
+
|
|
149
|
+
if (result.success) {
|
|
150
|
+
console.log(JSON.stringify(result.ir, null, 2));
|
|
151
|
+
console.log(`Confidence: ${result.confidence}`);
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Project Structure
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
flow2code/
|
|
159
|
+
├── src/
|
|
160
|
+
│ ├── app/ # Next.js App Router (UI)
|
|
161
|
+
│ ├── components/ # Visual canvas components
|
|
162
|
+
│ ├── store/ # Zustand canvas state management
|
|
163
|
+
│ ├── lib/
|
|
164
|
+
│ │ ├── index.ts # Headless Compiler public API
|
|
165
|
+
│ │ ├── ir/
|
|
166
|
+
│ │ │ ├── types.ts # IR Schema + TypeScript types
|
|
167
|
+
│ │ │ ├── validator.ts # IR validator
|
|
168
|
+
│ │ │ └── topological-sort.ts # Topological sort + concurrency detection
|
|
169
|
+
│ │ ├── compiler/
|
|
170
|
+
│ │ │ ├── compiler.ts # AST compiler core
|
|
171
|
+
│ │ │ ├── decompiler.ts # TS → FlowIR reverse parser
|
|
172
|
+
│ │ │ ├── expression-parser.ts # Recursive Descent Parser
|
|
173
|
+
│ │ │ ├── type-inference.ts # Type inference engine
|
|
174
|
+
│ │ │ ├── symbol-table.ts # Human-readable variable naming
|
|
175
|
+
│ │ │ ├── plugins/ # Plugin system (extensible)
|
|
176
|
+
│ │ │ │ ├── index.ts # Plugin registry factory + exports
|
|
177
|
+
│ │ │ │ ├── types.ts # PluginRegistry interface
|
|
178
|
+
│ │ │ │ └── builtin.ts # 15 built-in plugins
|
|
179
|
+
│ │ │ └── platforms/ # Platform adapters
|
|
180
|
+
│ │ │ ├── types.ts # PlatformAdapter interface
|
|
181
|
+
│ │ │ ├── nextjs.ts # Next.js App Router
|
|
182
|
+
│ │ │ ├── express.ts # Express.js
|
|
183
|
+
│ │ │ └── cloudflare.ts # Cloudflare Workers
|
|
184
|
+
│ │ ├── diff/ # Semantic Diff
|
|
185
|
+
│ │ └── storage/ # .flow.json split/merge
|
|
186
|
+
│ ├── cli/ # CLI (compile/watch/init)
|
|
187
|
+
│ └── server/ # Standalone HTTP Server
|
|
188
|
+
├── tests/ # 354 tests (Vitest)
|
|
189
|
+
├── .github/workflows/ci.yml # GitHub Actions CI
|
|
190
|
+
├── CONTRIBUTING.md
|
|
191
|
+
└── vitest.config.ts
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Node Types
|
|
195
|
+
|
|
196
|
+
| Category | Node | Compiled Output |
|
|
197
|
+
|----------|------|-----------------|
|
|
198
|
+
| ⚡ Trigger | HTTP Webhook | `export async function POST(req)` |
|
|
199
|
+
| ⚡ Trigger | Cron Job | Scheduled function |
|
|
200
|
+
| ⚡ Trigger | Manual | Exported async function |
|
|
201
|
+
| 🔧 Action | Fetch API | `await fetch(...)` + try/catch |
|
|
202
|
+
| 🔧 Action | SQL Query | Drizzle / Prisma / Raw SQL |
|
|
203
|
+
| 🔧 Action | Redis Cache | Redis get/set/del |
|
|
204
|
+
| 🔧 Action | Custom Code | Inline TypeScript |
|
|
205
|
+
| 🔧 Action | Call Subflow | `await importedFunction(...)` |
|
|
206
|
+
| 🔀 Logic | If/Else | `if (...) { } else { }` |
|
|
207
|
+
| 🔀 Logic | For Loop | `for (const item of ...)` |
|
|
208
|
+
| 🔀 Logic | Try/Catch | `try { } catch (e) { }` |
|
|
209
|
+
| 🔀 Logic | Promise.all | `await Promise.allSettled([...])` |
|
|
210
|
+
| 📦 Variable | Declare | `const x = ...` |
|
|
211
|
+
| 📦 Variable | Transform | Expression transform |
|
|
212
|
+
| 📤 Output | Return Response | Platform-specific Response |
|
|
213
|
+
|
|
214
|
+
## Platform Support
|
|
215
|
+
|
|
216
|
+
| Platform | Trigger Init | Response | CLI Flag |
|
|
217
|
+
|----------|-------------|----------|----------|
|
|
218
|
+
| **Next.js** (default) | `req.nextUrl.searchParams` / `req.json()` | `NextResponse.json()` | `--platform nextjs` |
|
|
219
|
+
| **Express** | `req.query` / `req.body` | `res.status().json()` | `--platform express` |
|
|
220
|
+
| **Cloudflare Workers** | `new URL(request.url)` / `request.json()` | `new Response()` | `--platform cloudflare` |
|
|
221
|
+
|
|
222
|
+
## Contributing
|
|
223
|
+
|
|
224
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
225
|
+
|
|
226
|
+
For detailed usage examples and workflows, see [USAGE.md](USAGE.md).
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
MIT
|