2.7 KiB
2.7 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.
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 (~950 lines): Split into smaller units, e.g.:
useCanvasGraph()or similar for graph state and connection rules.- A dedicated component for the context menu (add node, paste, etc.).
- Keeps CanvasPage as composition + layout.
-
useRenderingNodeState: Consider extracting:
- Signature building (config/edges/variables/functions/data) into a pure function or small module, e.g.
buildSourceSignatures(nodes, edges, id, incomingIds, getConfigContent). - Makes the hook easier to read and the logic testable in isolation.
- Signature building (config/edges/variables/functions/data) into a pure function or small module, e.g.
-
Config types: If you add more output types (e.g. Mermaid), consider a small registry API (
registerConfigType,getConfigType) instead of a single largeCONFIG_TYPESarray, so extensions can register without editing the core list. -
Consistent node shape in lib:
templateRefsusesEdgeLike/NodeLike; other graph code uses inline{ source, target }ornodes as .... You could standardize on the same minimal types where appropriate to reduce casts.