3.1 KiB
3.1 KiB
Codebase simplification and design patterns
This doc summarizes recent improvements and suggested next steps for readability, extension, and consistency.
Done
1. Single place for template/reachability (DRY)
- Added
lib/graph/templateRefs.ts:isReachable,resolveExtendsRef,getTemplateRefs. - Refactored
config/renderingLogic.tsanduseRenderingNodeState.tsto use these helpers instead of duplicating the same logic. - Pattern: Extract shared pure helpers into a small lib module; keep call sites thin and consistent.
2. Naming and comments
- Renamed
outputMenuRegistry.tsx→outputMenuHandlers.tsx(no registry, only helpers). - Updated
rendering.tsandsourceRenderingLogic.ts: output menu is described as coming from the node descriptor (getOutputMenuContent), not a separate registry. - Documented
NodeMenubar: extra content can come from props or from the descriptor (getNodeMenuExtraContent). - Documented
nodeTypes.ts: clarifies React Flow types vs node type id (nodeRegistry).
3. Central pipeline entry
- rendering.ts documents the 3-step pipeline, how to add a source/output type, and points to
templateRefs.tsfor shared helpers.
4. Rendering signatures (pure module)
- Added
lib/graph/renderingSignatures.ts:buildConnectedNodeIds,buildSourceSignatures(connectedNodeIds + all five signatures + sourceSignature). - Refactored
useRenderingNodeStateto callbuildSourceSignaturesin a single useMemo; hook is shorter and signature logic is testable in isolation.
5. Canvas split
- CanvasContextMenuContent (
app/canvas/CanvasContextMenuContent.tsx): context menu content (Create Node grouped by classification, Paste). CanvasPage passesonCreateNodeandonPaste. - useCanvasConnectionPath (
app/canvas/useCanvasConnectionPath.ts): all connection-path state and callbacks (updating/trigger/paused/error node ids, path node ids, start/end update, add/remove paused/error). CanvasPage calls the hook withedgesand passes the result into FlowContext.
Design patterns in use
| Pattern | Where |
|---|---|
| Registry | nodeRegistry, sourceRenderingLogic |
| Builder | nodeTypeBuilder (descriptor per node type) |
| Pipeline | Resolve → Render → Display (rendering.ts) |
| Strategy | Source logic per node type; output menu per descriptor |
| Shared helpers | templateRefs, outputMenuHandlers, renderingUtils |
Suggested next steps
-
CanvasPage: Further split optional: e.g.
useCanvasGraph()for graph state + persistence + connection rules, so the page is mostly composition and layout. -
Config types: If you add more output types (e.g. Mermaid), consider a small registry API (
registerConfigType,getConfigType) instead of a single largeCONFIG_TYPESarray. -
Consistent node shape in lib:
templateRefsandrenderingSignaturesuseEdgeLike/NodeLike; standardize where appropriate to reduce casts.