Psynapse Backend
The Psynapse backend is a FastAPI server that handles node graph execution. This decouples the compute from the UI, allowing for more scalable and testable node execution.
Architecture
Components
- FastAPI Server (
psynapse/backend/server.py) - Provides REST API endpoints for node operations
-
Handles graph execution requests
-
Node Schemas (
psynapse/backend/node_schemas.py) - Defines the schema for available nodes
-
Specifies parameters and return types for each node
-
Graph Executor (
psynapse/backend/executor.py) - Executes node graphs
- Manages node dependencies and caching
- Returns results for ViewNodes
Frontend Integration
- Graph Serializer (
psynapse/core/serializer.py) - Converts the UI node graph to a JSON format
-
Serializes nodes and edges for backend consumption
-
Backend Client (
psynapse/editor/backend_client.py) - HTTP client for communicating with the backend
- Provides sync wrappers for async operations
API Endpoints
GET /nodes
Returns the schema of all available nodes.
Response:
{
"nodes": [
{
"name": "add",
"params": [
{"name": "a", "type": "float"},
{"name": "b", "type": "float"}
],
"returns": [
{"name": "result", "type": "float"}
]
}
]
}
POST /execute
Executes a node graph and returns results.
Request:
{
"nodes": [
{
"id": "node_0",
"type": "add",
"input_sockets": [
{"id": "node_0_input_0", "name": "a", "value": 5.0},
{"id": "node_0_input_1", "name": "b", "value": 3.0}
],
"output_sockets": [
{"id": "node_0_output_0", "name": "result"}
]
},
{
"id": "node_1",
"type": "view",
"input_sockets": [
{"id": "node_1_input_0", "name": "value", "value": null}
],
"output_sockets": []
}
],
"edges": [
{
"start_socket": "node_0_output_0",
"end_socket": "node_1_input_0"
}
]
}
Response:
GET /health
Health check endpoint.
Response:
Running the Backend
Method 1: Using the helper script
Method 2: Using uvicorn directly
Method 3: Using uvicorn with custom host/port
Usage Workflow
-
Start the backend server
-
Launch the Psynapse editor
-
Build your node graph
- Drag nodes from the library panel
-
Connect nodes by dragging from output to input sockets
-
Execute the graph
- Click the "▶ Run Graph" button
- The frontend will serialize the graph and send it to the backend
- Results will be displayed in ViewNodes
Development
Adding New Node Types
To add a new node type:
-
Add the node schema in
psynapse/backend/node_schemas.py: -
Implement the execution logic in
psynapse/backend/executor.py: -
Create the frontend node class in
psynapse/nodes/: -
Register the node in the serializer mapping (
psynapse/core/serializer.py):
Testing
Test the backend endpoints using curl or any HTTP client: