flowbook 0.1.1 → 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.
@@ -0,0 +1,499 @@
1
+ ---
2
+ name: flowbook
3
+ description: "Flowbook generator — analyzes codebase logic and generates Mermaid flowchart documentation (.flow.md). Auto-discovers functions, API routes, state machines, auth flows, data pipelines, and business logic, then produces browsable flowchart documentation. Triggers: 'flowbook', 'flow diagram', 'flowchart', 'generate flows', 'document flows', 'logic diagram'."
4
+ license: MIT
5
+ compatibility:
6
+ - Claude Code
7
+ - OpenAI Codex
8
+ - VS Code / GitHub Copilot
9
+ - Google Antigravity
10
+ - Gemini CLI
11
+ - Cursor
12
+ - Windsurf (Codeium)
13
+ - AmpCode
14
+ - OpenCode / oh-my-opencode
15
+ metadata:
16
+ author: Epsilondelta
17
+ version: "1.0.0"
18
+ tags: flowbook, flowchart, mermaid, documentation, architecture, diagram, visualization
19
+ ---
20
+
21
+ # flowbook — Flowchart Documentation Generator
22
+
23
+ Analyze codebase logic → setup flowbook → generate `.flow.md` files → verify → build.
24
+
25
+ **Execute ALL phases in order. Do NOT skip phases. Generate flows for ALL significant logic — not just a few.**
26
+
27
+ ---
28
+
29
+ ## Phase 1: Project Analysis
30
+
31
+ ### 1.1 Check Flowbook Existence
32
+
33
+ Check if flowbook is already set up:
34
+
35
+ - `package.json` has `"flowbook"` script → Already initialized, skip Phase 2
36
+ - Otherwise → Proceed to Phase 2
37
+
38
+ ### 1.2 Detect Package Manager
39
+
40
+ | Lockfile | PM |
41
+ |----------|----|
42
+ | `bun.lock` or `bun.lockb` | bun |
43
+ | `pnpm-lock.yaml` | pnpm |
44
+ | `yarn.lock` | yarn |
45
+ | `package-lock.json` | npm |
46
+
47
+ ### 1.3 Detect Framework & Language
48
+
49
+ Read `package.json` dependencies:
50
+
51
+ | Dependency | Framework |
52
+ |------------|-----------|
53
+ | `next` | Next.js |
54
+ | `nuxt` | Nuxt |
55
+ | `@sveltejs/kit` | SvelteKit |
56
+ | `svelte` (no kit) | Svelte |
57
+ | `vue` (no nuxt) | Vue |
58
+ | `@angular/core` | Angular |
59
+ | `express` / `fastify` / `hono` / `koa` | Node.js Backend |
60
+ | `@nestjs/core` | NestJS |
61
+ | `react` (no next) | React |
62
+ | `django` / `flask` / `fastapi` | Python Backend |
63
+ | `spring` | Java/Kotlin Backend |
64
+ | `gin` / `echo` / `fiber` | Go Backend |
65
+
66
+ Language detection:
67
+ - `tsconfig.json` → TypeScript
68
+ - `*.go` files → Go
69
+ - `*.py` files → Python
70
+ - `*.java` / `*.kt` files → Java/Kotlin
71
+ - Otherwise → JavaScript
72
+
73
+ ### 1.4 Detect Source Structure
74
+
75
+ Scan for actual source directories:
76
+
77
+ **Frontend:**
78
+ - `src/components/`, `src/pages/`, `src/views/`, `src/routes/`
79
+ - `src/app/`, `app/`, `pages/`, `components/`
80
+ - `src/store/`, `src/hooks/`, `src/composables/`, `src/lib/`
81
+
82
+ **Backend:**
83
+ - `src/routes/`, `src/api/`, `src/controllers/`, `src/services/`
84
+ - `src/middleware/`, `src/handlers/`, `src/resolvers/`
85
+ - `routes/`, `api/`, `controllers/`, `services/`
86
+
87
+ **Shared:**
88
+ - `src/utils/`, `src/helpers/`, `src/lib/`
89
+ - `src/models/`, `src/schemas/`, `src/types/`
90
+
91
+ Only include directories that actually exist.
92
+
93
+ ---
94
+
95
+ ## Phase 2: Flowbook Setup
96
+
97
+ ### 2.1 Initialize Flowbook
98
+
99
+ ```bash
100
+ npx flowbook@latest init
101
+ ```
102
+
103
+ This will:
104
+ - Install `flowbook` as a devDependency
105
+ - Add `"flowbook"` and `"build-flowbook"` scripts to `package.json`
106
+ - Create `flows/example.flow.md` as a starter template
107
+ - Add `flowbook-static` to `.gitignore`
108
+
109
+ ### 2.2 Verify Setup
110
+
111
+ Check that:
112
+ - `package.json` contains `"flowbook": "flowbook dev"` script
113
+ - `flowbook` is in `devDependencies`
114
+ - `flows/` directory exists
115
+
116
+ ### 2.3 Remove Example Flow
117
+
118
+ After verification, delete the example to replace with real flows:
119
+
120
+ ```bash
121
+ rm flows/example.flow.md
122
+ ```
123
+
124
+ ---
125
+
126
+ ## Phase 3: Codebase Analysis & Flow Discovery
127
+
128
+ This is the **most critical phase**. Deeply analyze the codebase to identify all significant logic flows.
129
+
130
+ ### 3.1 Flow Categories to Discover
131
+
132
+ Scan the codebase for these flow types. For EACH one found, plan a `.flow.md` file:
133
+
134
+ #### A. API / Route Flows
135
+ - HTTP request → middleware chain → handler → response
136
+ - REST endpoints (GET, POST, PUT, DELETE)
137
+ - GraphQL resolvers (Query, Mutation)
138
+ - WebSocket message flows
139
+ - RPC handlers
140
+
141
+ #### B. Authentication & Authorization
142
+ - Login / signup / logout flows
143
+ - Token refresh / session management
144
+ - OAuth flows (redirect → callback → token exchange)
145
+ - Role-based access control (RBAC) decision trees
146
+ - Password reset / email verification
147
+
148
+ #### C. Data Flows
149
+ - CRUD operations (Create → Validate → Save → Respond)
150
+ - Data pipeline / ETL (Extract → Transform → Load)
151
+ - Form submission → validation → API call → state update
152
+ - File upload → process → store → respond
153
+ - Cache strategies (read-through, write-through, invalidation)
154
+
155
+ #### D. State Management
156
+ - Global state flow (Redux, Zustand, Pinia, Vuex)
157
+ - Action → Reducer → State → UI update cycle
158
+ - Side effects (Sagas, Thunks, Effects)
159
+ - Optimistic updates → rollback on failure
160
+
161
+ #### E. Business Logic
162
+ - Order processing / checkout flow
163
+ - Payment flow (initiate → process → confirm / refund)
164
+ - Notification system (trigger → queue → send → track)
165
+ - Scheduling / cron job flows
166
+ - Approval workflows (submit → review → approve/reject)
167
+
168
+ #### F. Error Handling
169
+ - Global error boundary flow
170
+ - Retry strategies (exponential backoff)
171
+ - Fallback / circuit breaker patterns
172
+ - Error logging / monitoring pipeline
173
+
174
+ #### G. DevOps & Infrastructure
175
+ - CI/CD pipeline stages
176
+ - Deployment flow
177
+ - Health check / monitoring flow
178
+ - Database migration flow
179
+
180
+ #### H. Lifecycle & Initialization
181
+ - App bootstrap / initialization sequence
182
+ - Component lifecycle flows
183
+ - Server startup → middleware registration → route binding → listen
184
+ - Database connection → migration → seeding → ready
185
+
186
+ ### 3.2 How to Analyze
187
+
188
+ For each source file:
189
+
190
+ 1. **Read the file** — understand its purpose
191
+ 2. **Trace the flow** — follow function calls, conditionals, async operations
192
+ 3. **Identify decision points** — if/else, switch, try/catch, early returns
193
+ 4. **Map dependencies** — what other modules/services does it call?
194
+ 5. **Note error paths** — what happens when things fail?
195
+
196
+ ### 3.3 Flow Classification
197
+
198
+ For each discovered flow, determine:
199
+
200
+ | Field | How to Determine |
201
+ |-------|-----------------|
202
+ | `title` | Clear, descriptive name (e.g., "User Login Flow") |
203
+ | `category` | Group by domain: Authentication, API, Data, State, Business, DevOps, etc. |
204
+ | `tags` | Relevant keywords for filtering |
205
+ | `order` | Lower = more important. Core flows first. |
206
+ | `description` | One-line summary of what the flow does |
207
+
208
+ ### 3.4 Skip Rules
209
+
210
+ Do NOT create flows for:
211
+ - Trivial utility functions (formatDate, slugify, etc.)
212
+ - Simple getters/setters with no logic
213
+ - Type definitions / interfaces only
214
+ - Test files
215
+ - Config files (unless they represent a complex pipeline)
216
+ - Files that already have corresponding `.flow.md`
217
+
218
+ ---
219
+
220
+ ## Phase 4: Flow File Generation
221
+
222
+ ### 4.1 File Placement
223
+
224
+ Place ALL flow files in the `flows/` directory at project root:
225
+
226
+ ```
227
+ flows/
228
+ ├── auth-login.flow.md
229
+ ├── auth-oauth.flow.md
230
+ ├── api-user-crud.flow.md
231
+ ├── data-order-processing.flow.md
232
+ ├── state-cart-management.flow.md
233
+ └── devops-ci-pipeline.flow.md
234
+ ```
235
+
236
+ **Naming convention**: `{category}-{name}.flow.md` (kebab-case)
237
+
238
+ ### 4.2 Flow File Template
239
+
240
+ Every `.flow.md` file MUST follow this structure:
241
+
242
+ ````markdown
243
+ ---
244
+ title: {Descriptive Title}
245
+ category: {Category Name}
246
+ tags: [{tag1}, {tag2}, {tag3}]
247
+ order: {number}
248
+ description: {One-line description}
249
+ ---
250
+
251
+ ```mermaid
252
+ flowchart TD
253
+ A[Start] --> B{Decision}
254
+ B -->|Yes| C[Action]
255
+ B -->|No| D[Other Action]
256
+ C --> E[End]
257
+ D --> E
258
+ ```
259
+ ````
260
+
261
+ ### 4.3 Mermaid Diagram Guidelines
262
+
263
+ #### Node Types
264
+
265
+ ```mermaid
266
+ flowchart TD
267
+ A[Regular Step] %% Rectangle: action/process
268
+ B{Decision Point} %% Diamond: if/else, switch
269
+ C([Start / End]) %% Stadium: entry/exit points
270
+ D[(Database)] %% Cylinder: DB operations
271
+ E[[Sub-routine]] %% Subroutine: function call
272
+ F>Event / Signal] %% Flag: async event, webhook
273
+ G{{Validation}} %% Hexagon: validation step
274
+ H[/Input/] %% Parallelogram: user input
275
+ I[\Output\] %% Reverse parallelogram: response
276
+ ```
277
+
278
+ #### Edge Labels
279
+
280
+ ```mermaid
281
+ flowchart TD
282
+ A{Authenticated?} -->|Yes| B[Dashboard]
283
+ A -->|No| C[Login Page]
284
+ D[API Call] -->|200 OK| E[Process Data]
285
+ D -->|4xx/5xx| F[Handle Error]
286
+ G[Submit] -->|Valid| H[Save]
287
+ G -->|Invalid| I[Show Errors]
288
+ ```
289
+
290
+ #### Styling
291
+
292
+ Apply consistent colors to node types:
293
+
294
+ ```mermaid
295
+ flowchart TD
296
+ A([Start]) --> B[Process]
297
+ B --> C{Decision}
298
+ C -->|Yes| D[(Save to DB)]
299
+ C -->|No| E[Handle Error]
300
+ D --> F([End])
301
+ E --> F
302
+
303
+ style A fill:#6366f1,color:#fff
304
+ style F fill:#6366f1,color:#fff
305
+ style C fill:#f59e0b,color:#000
306
+ style D fill:#10b981,color:#fff
307
+ style E fill:#ef4444,color:#fff
308
+ ```
309
+
310
+ **Color convention:**
311
+ - `#6366f1` (indigo) — Start/End points
312
+ - `#10b981` (green) — Success paths, DB operations
313
+ - `#f59e0b` (amber) — Decision points
314
+ - `#ef4444` (red) — Error paths, failures
315
+ - `#8b5cf6` (purple) — External service calls
316
+ - `#3b82f6` (blue) — Processing steps
317
+ - Default (no style) — Regular steps
318
+
319
+ #### Subgraphs for Complex Flows
320
+
321
+ Use subgraphs to group related steps:
322
+
323
+ ```mermaid
324
+ flowchart TD
325
+ A([Request]) --> B
326
+
327
+ subgraph Middleware
328
+ B[Auth Check] --> C[Rate Limit] --> D[Parse Body]
329
+ end
330
+
331
+ D --> E
332
+
333
+ subgraph Handler
334
+ E[Validate Input] --> F{Valid?}
335
+ F -->|Yes| G[Process]
336
+ F -->|No| H[Return 400]
337
+ end
338
+
339
+ G --> I[(Save)]
340
+ I --> J[\200 OK/]
341
+ H --> K[\400 Error/]
342
+ ```
343
+
344
+ ### 4.4 Complexity Guidelines
345
+
346
+ - **Simple flows** (3-8 nodes): Single linear or branching flow
347
+ - **Medium flows** (8-15 nodes): Multiple branches, some subgraphs
348
+ - **Complex flows** (15-25 nodes): Multiple subgraphs, parallel paths
349
+ - **Do NOT exceed 25 nodes** per diagram — split into multiple flows instead
350
+
351
+ If a flow is too complex:
352
+ 1. Create a high-level overview flow
353
+ 2. Create detailed sub-flows for each section
354
+ 3. Reference sub-flows in the overview's description
355
+
356
+ ### 4.5 Real-World Example
357
+
358
+ For a Next.js API route `app/api/auth/login/route.ts`:
359
+
360
+ ````markdown
361
+ ---
362
+ title: User Login
363
+ category: Authentication
364
+ tags: [auth, login, jwt, api]
365
+ order: 1
366
+ description: POST /api/auth/login — validates credentials and returns JWT tokens
367
+ ---
368
+
369
+ ```mermaid
370
+ flowchart TD
371
+ A([POST /api/auth/login]) --> B[/Parse Request Body/]
372
+ B --> C{{Validate Email & Password}}
373
+ C -->|Invalid| D[\400 Bad Request/]
374
+ C -->|Valid| E[(Find User by Email)]
375
+ E -->|Not Found| F[\401 Unauthorized/]
376
+ E -->|Found| G{{Compare Password Hash}}
377
+ G -->|Mismatch| F
378
+ G -->|Match| H[Generate JWT Access Token]
379
+ H --> I[Generate Refresh Token]
380
+ I --> J[(Save Refresh Token)]
381
+ J --> K[\200 OK + Tokens/]
382
+
383
+ style A fill:#6366f1,color:#fff
384
+ style C fill:#f59e0b,color:#000
385
+ style G fill:#f59e0b,color:#000
386
+ style E fill:#10b981,color:#fff
387
+ style J fill:#10b981,color:#fff
388
+ style D fill:#ef4444,color:#fff
389
+ style F fill:#ef4444,color:#fff
390
+ style K fill:#10b981,color:#fff
391
+ ```
392
+ ````
393
+
394
+ ---
395
+
396
+ ## Phase 5: Verification
397
+
398
+ ### 5.1 Syntax Check
399
+
400
+ For each generated `.flow.md` file:
401
+
402
+ 1. Verify YAML frontmatter is valid (title, category present)
403
+ 2. Verify mermaid code block is properly fenced (``` mermaid ```)
404
+ 3. Verify mermaid syntax has no obvious errors (matched brackets, valid node IDs)
405
+
406
+ ### 5.2 Build Verification
407
+
408
+ ```bash
409
+ npx flowbook build 2>&1
410
+ ```
411
+
412
+ If build fails:
413
+ - Read error output
414
+ - Fix the issue (likely malformed mermaid syntax)
415
+ - Retry until build succeeds
416
+
417
+ ### 5.3 Visual Verification
418
+
419
+ Start dev server and verify rendering:
420
+
421
+ ```bash
422
+ npx flowbook dev &
423
+ FB_PID=$!
424
+ sleep 3
425
+ ```
426
+
427
+ If the `playwright` skill is available, load it and:
428
+
429
+ 1. Navigate to `http://localhost:6200`
430
+ 2. Wait for Flowbook UI to load
431
+ 3. Check sidebar — all flow categories should appear
432
+ 4. Click through each flow — verify diagrams render (no error messages)
433
+ 5. Screenshot any failures
434
+
435
+ ```bash
436
+ kill $FB_PID 2>/dev/null
437
+ ```
438
+
439
+ ### 5.4 Fix-and-Retry Loop
440
+
441
+ If mermaid diagrams fail to render:
442
+ 1. Common issue: special characters in labels — wrap in quotes: `A["Label with (parens)"]`
443
+ 2. Common issue: reserved keywords — prefix with text: `A[End Point]` not `A[End]` alone as node content after using `End` as ID
444
+ 3. Re-run build verification
445
+ 4. Repeat until all diagrams render
446
+
447
+ ---
448
+
449
+ ## Phase 6: Summary Report
450
+
451
+ Print a summary:
452
+
453
+ ```
454
+ === Flowbook Report ===
455
+ Framework: {detected framework}
456
+ Language: {detected language}
457
+
458
+ Flows generated: {N}
459
+ Categories:
460
+ - Authentication: {N} flows
461
+ - API: {N} flows
462
+ - Data: {N} flows
463
+ - State: {N} flows
464
+ - Business Logic: {N} flows
465
+ - DevOps: {N} flows
466
+
467
+ Files created:
468
+ - flows/{filename}.flow.md — {title}
469
+ - flows/{filename}.flow.md — {title}
470
+ ...
471
+
472
+ Build: ✅ / ❌
473
+ ```
474
+
475
+ ---
476
+
477
+ ## Troubleshooting
478
+
479
+ ### Flowbook init fails
480
+ - **No package.json**: Run `npm init -y` first
481
+ - **Permission error**: Check write permissions on project directory
482
+
483
+ ### Mermaid syntax errors
484
+ - **Brackets**: Every `[`, `{`, `(` must be closed
485
+ - **Special characters in labels**: Wrap in double quotes: `A["User's Input"]`
486
+ - **Arrow syntax**: Use `-->` for solid, `-.->` for dotted, `==>` for thick
487
+ - **Node ID reuse**: Each node ID must be unique per diagram. Reuse ID to reference same node.
488
+ - **Subgraph naming**: Subgraph labels cannot contain special characters
489
+
490
+ ### Diagrams too complex
491
+ - Split into overview + detail flows
492
+ - Use subgraphs to group related logic
493
+ - Keep each diagram under 25 nodes
494
+ - Link related flows via description references
495
+
496
+ ### Build fails
497
+ - Check mermaid version compatibility (flowbook uses Mermaid 11+)
498
+ - Validate YAML frontmatter (no tabs, proper indentation)
499
+ - Ensure code blocks use triple backticks with `mermaid` language tag