Developer Guide¶
Audience
This guide is for JavaScript/TypeScript developers who want to:
- Understand PyNodeWidget's frontend architecture
- Contribute to the JavaScript codebase
- Create custom field types, handles, or components
- Extend the library with plugins
For Python users: See the User Guide instead.
Prerequisites
Familiarity with:
- React 18+ - Component model, hooks, state management
- TypeScript - Type system, interfaces, generics
- ReactFlow - Node graph library fundamentals
- Valibot - Schema validation library
Overview¶
PyNodeWidget renders interactive node graphs using a three-layer grid system. Python sends JSON schemas, JavaScript renders using React components, and user interactions sync back via AnyWidget.
Core Architecture¶
graph LR
A[Python JSON] -->|AnyWidget| B[NodeGrid]
B --> C[GridRenderer]
C --> D[ComponentFactory]
D --> E[React Components]
E -->|User Input| F[Python]
style B fill:#e1f5ff
style D fill:#fff4e1
Key Concepts:
- NodeGrid: Defines rows, columns, and cells
- GridCell: Contains layout and components
- ComponentType: Discriminated union of all component types
- NodeTemplate: Immutable blueprint (shared)
- NodeInstance: Mutable runtime data (per-node)
Documentation Structure¶
Architecture¶
Start here to understand the system.
- Data flow (Python ↔ JavaScript)
- Three-layer grid system
- Core data structures
- Value synchronization
- Extension points
Time: 15 minutes
Extension Guide¶
Copy-paste recipes for common tasks.
- Adding custom field types
- Adding custom handle types
- Creating services
- Building custom hooks
- Testing extensions
Time: 5-10 minutes per recipe
JavaScript Development¶
Setup and build commands.
- Environment setup
- Development workflow
- Testing
- Build system
- Common tasks
Time: 5 minutes
Hooks Reference¶
Available React hooks.
- useSetNodeValues
- useSetNodesDict
- useAutoLayout
- useContextMenu
- useExport
Time: 2 minutes
Quick Start¶
1. Understand the Architecture¶
Read Architecture to understand: - How the three-layer grid works - Core data structures (the Essential 5) - Value synchronization patterns
2. Set Up Development Environment¶
See JavaScript Development for details.
3. Try an Extension¶
Follow a recipe in the Extension Guide: - Add a color picker field - Create a multi-handle component - Build a validation service
4. Explore the Codebase¶
Key Files:
- src/components/ComponentFactory.tsx - Core rendering
- src/components/GridRenderer.tsx - Three-layer system
- src/utils/NodeComponentBuilder.tsx - Schema → Component
- src/types/schema.ts - TypeScript types
When to Use This Guide¶
| If you want to... | Start here... |
|---|---|
| Understand how it works | Architecture |
| Add a custom field | Extension Guide → Custom Field Types |
| Add a custom handle | Extension Guide → Custom Handle Types |
| Set up development | JavaScript Development |
| Use a hook | Hooks Reference |
| Debug Python ↔ JS sync | Architecture → Value Synchronization |
| Contribute code | JavaScript Development + Extension Guide |
Development vs. User Documentation¶
Choose the Right Guide
- New to PyNodeWidget? Start with the User Guide (Python-only)
- Building nodes in Python? See Creating Custom Nodes
- Need to extend the JavaScript side? You're in the right place!
Getting Help¶
- GitHub Issues: Report bugs or request features
- Architecture questions: Read Architecture first
- How-to questions: Check Extension Guide recipes
- Code examples: See
js/dev/DevApp.tsxandexamples/
Contributing¶
We welcome contributions! Before starting:
- Read Architecture to understand the system
- Set up your environment: JavaScript Development
- Follow patterns in Extension Guide
- Add tests (see Testing section in JavaScript Development)
- Submit a PR
Code Style: - TypeScript with strict mode - Valibot for schemas - Tailwind CSS for styling - Vitest for testing
The User Guide is pure Python—no JavaScript knowledge required. The Developer Guide dives into React, TypeScript, bundlers, and the internal APIs.
Quick Reference¶
Key Technologies¶
- React 18: Frontend framework
- ReactFlow 12: Node graph visualization
- TypeScript 5: Type-safe JavaScript
- Zustand 4: Lightweight state management
- Bun 1.1+: Fast JavaScript runtime and bundler
- Vite 5: Development server and build tool
- AnyWidget 0.9+: Jupyter widget bridge
Project Structure¶
js/
├── src/ # Main source code
│ ├── NodeComponentBuilder.tsx # Node component generator
│ ├── NodePanel.tsx # Node editor panel
│ ├── components/ # React components
│ │ ├── fields/ # Field type components
│ │ ├── handles/ # Handle components
│ │ └── layouts/ # Layout components
│ ├── hooks/ # React hooks
│ ├── stores/ # Zustand state stores
│ ├── services/ # Business logic
│ ├── types/ # TypeScript types
│ └── utils/ # Helper functions
├── dev/ # Development app
├── tests/ # Vitest unit tests
└── package.json # Dependencies and scripts
Build Targets¶
PyNodeWidget builds three separate JavaScript bundles:
- AnyWidget Bundle (
static/json_schema_node_widget.js) - For Jupyter notebooks - Standalone Node Editor (
static/json_schema_node.js) - For web apps - Development Server (
dev/app.html) - For local testing
Contributing¶
Found a bug or want to add a feature? See the Contributing Guide for:
- Setting up the development environment
- Running tests (pytest for Python, vitest for JavaScript)
- Code style guidelines (ruff for Python, prettier/eslint for JavaScript)
- Pull request process
Next Steps¶
- Read the Architecture Overview to understand the system design
- Set up your dev environment with the JavaScript Development guide
- Explore the codebase in
js/src/with the TypeScript types reference - Run the dev server (
bun run dev) to see live updates
Work in Progress
The API reference sections (Field Registry, Layout System, etc.) are being written. Check back soon or contribute to the documentation!