streamweave 0.10.1

Composable, async, stream-first computation in pure Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# Minimal Syntax Graph Macro Implementation

## Overview

This document describes the implementation of a minimal syntax declarative macro (`graph!`) that supports:
- **Fan-out patterns**: One source to multiple targets
- **Fan-in patterns**: Multiple sources to one target
- **Graph input connections**: External inputs to graph nodes
- **Graph output connections**: Graph nodes to external outputs

## Syntax Design

### Important Notes

- **Node Configuration**: Node configuration (like filter predicates, map transforms, range parameters) is supplied at **runtime via input ports**, not during node creation. Nodes are created with just `Node::new("name")` - no builder methods like `.config()`, `.start()`, `.end()`, etc.
- **Reserved Name**: Nodes cannot be named `graph` - this name is reserved for the graph I/O namespace.

### Basic Syntax

```rust
let graph = graph! {
    // Node definitions (name: NodeInstance)
    // Configuration is supplied at runtime via input ports, not during node creation
    range: RangeNode::new("range"),
    filter: FilterNode::new("filter"),
    square: MapNode::new("square"),
    sum: SumNode::new("sum"),
    
    // All connections must specify explicit port names
    range.out => filter.in,
    filter.out => square.in,
    square.out => sum.in,
    
    // Graph inputs (external -> internal) - use graph. prefix
    // Configuration values are supplied at runtime via graph inputs
    graph.start: 1i32 => range.start,
    graph.end: 11i32 => range.end,
    graph.filter_config => filter.configuration,
    graph.map_config => square.configuration,
    
    // Graph outputs (internal -> external) - use graph. prefix
    sum.out => graph.result
};
```

**Important**: 
- All connections must explicitly specify port names. There are no default ports or sequential connection shortcuts.
- Node configuration is supplied at runtime via input ports (e.g., `graph.filter_config => filter.configuration`), not during node creation.

### Fan-Out Pattern

```rust
let graph = graph! {
    source: SourceNode::new("source"),
    filter1: FilterNode::new("filter1"),
    filter2: FilterNode::new("filter2"),
    filter3: FilterNode::new("filter3"),
    process1: ProcessNode::new("process1"),
    process2: ProcessNode::new("process2"),
    process3: ProcessNode::new("process3"),
    
    // Fan-out: one source port to multiple target ports (all ports must be explicit on both sides)
    source.out => filter1.in,
    source.out => filter2.in,
    source.out => filter3.in,
    
    // Each target continues with explicit ports on both sides
    filter1.out => process1.in,
    filter2.out => process2.in,
    filter3.out => process3.in,
    
    // Configuration supplied at runtime via graph inputs
    graph.filter1_config => filter1.configuration,
    graph.filter2_config => filter2.configuration,
    graph.filter3_config => filter3.configuration
};
```

**Alternative Fan-Out with Different Source Ports:**

```rust
let graph = graph! {
    router: RouterNode::new("router"),
    filter1: FilterNode::new("filter1"),
    filter2: FilterNode::new("filter2"),
    filter3: FilterNode::new("filter3"),
    
    // Fan-out: different source ports to different targets (all ports explicit)
    router.out1 => filter1.in,
    router.out2 => filter2.in,
    router.out3 => filter3.in
};
```

### Fan-In Pattern

```rust
let graph = graph! {
    source1: SourceNode::new("source1"),
    source2: SourceNode::new("source2"),
    source3: SourceNode::new("source3"),
    merge: MergeNode::new("merge"),
    process: ProcessNode::new("process"),
    
    // Fan-in: multiple source ports to one target port (all ports must be explicit on both sides)
    source1.out => merge.in_0,
    source2.out => merge.in_1,
    source3.out => merge.in_2,
    
    // Continue chain after merge with explicit ports on both sides
    merge.out => process.in
};
```

**Alternative Fan-In with Different Source Ports:**

```rust
let graph = graph! {
    source1: SourceNode::new("source1"),
    source2: SourceNode::new("source2"),
    source3: SourceNode::new("source3"),
    merge: MergeNode::new("merge"),
    
    // Fan-in: different source ports to different target ports (all ports explicit)
    source1.out => merge.in_0,
    source2.error => merge.in_1,  // Different source port name
    source3.out => merge.in_2
};
```

### Explicit Port Connections

```rust
let graph = graph! {
    add: AddNode::new("add"),
    
    // Graph inputs with explicit ports - use graph. prefix
    graph.input1 => add.in1,
    graph.input2 => add.in2,
    
    // Graph outputs with explicit ports - use graph. prefix
    add.out => graph.output
};
```

### Combined Patterns

```rust
let graph = graph! {
    source: SourceNode::new("source"),
    filter1: FilterNode::new("filter1"),
    filter2: FilterNode::new("filter2"),
    merge: MergeNode::new("merge"),
    process: ProcessNode::new("process"),
    
    // Fan-out: explicit ports on both source and target sides for each connection
    source.out => filter1.in,
    source.out => filter2.in,
    
    // Fan-in: explicit ports on both source and target sides for each connection
    filter1.out => merge.in_0,
    filter2.out => merge.in_1,
    
    // Continue chain: explicit ports on both sides
    merge.out => process.in,
    
    // Graph I/O: explicit ports with graph. prefix
    graph.external_input => source.in,
    process.out => graph.external_output
};
```

## Macro Implementation Strategy

### Phase 1: Macro Structure

The macro will parse the input and build a `GraphBuilder` structure that can be converted to a `Graph`.

```rust
#[macro_export]
macro_rules! graph {
    // Main entry point - parse the entire graph definition
    ($($tt:tt)*) => {
        $crate::graph::macros::graph_impl! {
            nodes: {},
            edges: [],
            inputs: {},
            outputs: {},
            $($tt)*
        }
    };
}
```

### Phase 2: Parsing Rules

The macro needs to distinguish between:
1. **Node definitions**: `name: NodeInstance` (where `name` cannot be `graph`)
2. **Node-to-node connections**: `source_node.source_port => target_node.target_port` (all ports must be explicit on both sides)
3. **Fan-out**: Multiple connections from one or more source ports to multiple target ports (each connection must explicitly name both source and target ports)
4. **Fan-in**: Multiple connections from multiple source ports to one or more target ports (each connection must explicitly name both source and target ports)
5. **Graph inputs**: `graph.input_name: value => node.port` or `graph.input_name => node.port` (ports must be explicit)
6. **Graph outputs**: `node.port => graph.output_name` (ports must be explicit)

**Critical Rule**: In fan-out and fan-in patterns, **every connection must explicitly name both the source port and the target port**. There are no default port names or shortcuts.

### Phase 3: Builder Generation

The macro generates code that:
1. Creates node instances
2. Adds nodes to the graph
3. Creates edges for connections
4. Exposes input/output ports
5. Connects external channels

## Detailed Implementation

### Core Macro Structure

```rust
// src/graph/macros.rs

use crate::graph::Graph;
use crate::edge::Edge;

/// Internal macro for parsing graph definitions
#[macro_export]
macro_rules! graph_impl {
    // Base case: all tokens consumed
    (
        nodes: {$($nodes:tt)*},
        edges: [$($edges:tt)*],
        inputs: {$($inputs:tt)*},
        outputs: {$($outputs:tt)*},
    ) => {
        $crate::graph::macros::build_graph! {
            nodes: {$($nodes)*},
            edges: [$($edges)*],
            inputs: {$($inputs)*},
            outputs: {$($outputs)*}
        }
    };
    
    // Parse node definition: name: NodeInstance
    (
        nodes: {$($nodes:tt)*},
        edges: [$($edges:tt)*],
        inputs: {$($inputs:tt)*},
        outputs: {$($outputs:tt)*},
        $name:ident : $node:expr,
        $($rest:tt)*
    ) => {
        $crate::graph::macros::graph_impl! {
            nodes: {
                $($nodes)*
                $name: $node,
            },
            edges: [$($edges)*],
            inputs: {$($inputs)*},
            outputs: {$($outputs)*},
            $($rest)*
        }
    };
    
    // Parse node-to-node connection: source_node.source_port => target_node.target_port
    // All ports must be explicitly named - no defaults
    (
        nodes: {$($nodes:tt)*},
        edges: [$($edges:tt)*],
        inputs: {$($inputs:tt)*},
        outputs: {$($outputs:tt)*},
        $source_node:ident . $source_port:ident => $target_node:ident . $target_port:ident,
        $($rest:tt)*
    ) => {
        $crate::graph::macros::graph_impl! {
            nodes: {$($nodes)*},
            edges: [
                $($edges)*
                (stringify!($source_node), stringify!($source_port), stringify!($target_node), stringify!($target_port)),
            ],
            inputs: {$($inputs)*},
            outputs: {$($outputs)*},
            $($rest)*
        }
    };
    
    // Parse graph input with value: graph.input_name: value => node.port
    (
        nodes: {$($nodes:tt)*},
        edges: [$($edges:tt)*],
        inputs: {$($inputs:tt)*},
        outputs: {$($outputs:tt)*},
        graph . $input_name:ident : $value:expr => $node:ident . $port:ident,
        $($rest:tt)*
    ) => {
        $crate::graph::macros::graph_impl! {
            nodes: {$($nodes)*},
            edges: [$($edges)*],
            inputs: {
                $($inputs)*
                $input_name: ($value, stringify!($node), stringify!($port)),
            },
            outputs: {$($outputs)*},
            $($rest)*
        }
    };
    
    // Parse graph input connection: graph.input_name => node.port
    (
        nodes: {$($nodes:tt)*},
        edges: [$($edges:tt)*],
        inputs: {$($inputs:tt)*},
        outputs: {$($outputs:tt)*},
        graph . $input_name:ident => $node:ident . $port:ident,
        $($rest:tt)*
    ) => {
        $crate::graph::macros::graph_impl! {
            nodes: {$($nodes)*},
            edges: [$($edges)*],
            inputs: {
                $($inputs)*
                $input_name: (None, stringify!($node), stringify!($port)),
            },
            outputs: {$($outputs)*},
            $($rest)*
        }
    };
    
    // Parse graph output: node.port => graph.output_name
    (
        nodes: {$($nodes:tt)*},
        edges: [$($edges:tt)*],
        inputs: {$($inputs:tt)*},
        outputs: {$($outputs:tt)*},
        $node:ident . $port:ident => graph . $output_name:ident,
        $($rest:tt)*
    ) => {
        $crate::graph::macros::graph_impl! {
            nodes: {$($nodes)*},
            edges: [$($edges)*],
            inputs: {$($inputs)*},
            outputs: {
                $($outputs)*
                $output_name: (stringify!($node), stringify!($port)),
            },
            $($rest)*
        }
    };
}
```

### Graph Builder Macro

```rust
/// Builds the actual Graph from parsed components
#[macro_export]
macro_rules! build_graph {
    (
        nodes: {
            $($name:ident : $node:expr),+ $(,)?
        },
        edges: [
            $(
                ($source:expr, $source_port:expr, $target:expr, $target_port:expr),
            )+
        ],
        inputs: {
            $(
                $input_name:ident : ($value:expr, $node:expr, $port:expr),
            )*
        },
        outputs: {
            $(
                $output_name:ident : ($node:expr, $port:expr),
            )*
        }
    ) => {{
        let mut graph = $crate::graph::Graph::new("graph".to_string());
        
        // Add all nodes
        $(
            let node_instance = $node;
            graph.add_node(
                stringify!($name).to_string(),
                Box::new(node_instance)
            ).expect("Failed to add node");
        )+
        
        // Add all edges
        $(
            graph.add_edge($crate::edge::Edge {
                source_node: $source.to_string(),
                source_port: $source_port.to_string(),
                target_node: $target.to_string(),
                target_port: $target_port.to_string(),
            }).expect("Failed to add edge");
        )+
        
        // Expose and connect input ports
        $(
            {
                let external_name = stringify!($input_name);
                let internal_node = $node;
                let internal_port = $port;
                
                graph.expose_input_port(
                    internal_node,
                    internal_port,
                    external_name
                ).expect("Failed to expose input port");
                
                // If value is provided, create channel and send value
                if let Some(val) = $value {
                    let (tx, rx) = tokio::sync::mpsc::channel(1);
                    graph.connect_input_channel(external_name, rx)
                        .expect("Failed to connect input channel");
                    
                    // Spawn task to send initial value
                    let val_arc = std::sync::Arc::new(val) as std::sync::Arc<dyn std::any::Any + Send + Sync>;
                    tokio::spawn(async move {
                        let _ = tx.send(val_arc).await;
                    });
                }
            }
        )*
        
        // Expose and connect output ports
        $(
            {
                let external_name = stringify!($output_name);
                let internal_node = $node;
                let internal_port = $port;
                
                graph.expose_output_port(
                    internal_node,
                    internal_port,
                    external_name
                ).expect("Failed to expose output port");
            }
        )*
        
        graph
    }};
}
```

## Simplified Implementation Approach

Given the complexity of macro parsing, here's a more practical approach using a builder pattern:

### Step 1: Create GraphBuilder Helper

```rust
// src/graph/builder.rs

pub struct GraphBuilder {
    name: String,
    nodes: Vec<(String, Box<dyn Node>)>,
    edges: Vec<Edge>,
    input_bindings: Vec<(String, String, String, Option<Arc<dyn Any + Send + Sync>>)>, // (external, node, port, value)
    output_bindings: Vec<(String, String, String)>, // (external, node, port)
}

impl GraphBuilder {
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            nodes: Vec::new(),
            edges: Vec::new(),
            input_bindings: Vec::new(),
            output_bindings: Vec::new(),
        }
    }
    
    pub fn add_node(mut self, name: impl Into<String>, node: Box<dyn Node>) -> Self {
        let name_str = name.into();
        if name_str == "graph" {
            panic!("Node name 'graph' is reserved for graph I/O namespace. Use 'graph.input_name' for graph inputs and 'graph.output_name' for graph outputs.");
        }
        self.nodes.push((name_str, node));
        self
    }
    
    pub fn connect(mut self, source: &str, source_port: &str, target: &str, target_port: &str) -> Self {
        self.edges.push(Edge {
            source_node: source.to_string(),
            source_port: source_port.to_string(),
            target_node: target.to_string(),
            target_port: target_port.to_string(),
        });
        self
    }
    
    // Note: Sequential connections and fan-out/fan-in helpers removed
    // All connections must be explicit with named ports
    
    pub fn input<T: Send + Sync + 'static>(
        mut self,
        external_name: impl Into<String>,
        node: &str,
        port: &str,
        value: Option<T>,
    ) -> Self {
        let value_arc = value.map(|v| Arc::new(v) as Arc<dyn Any + Send + Sync>);
        self.input_bindings.push((
            external_name.into(),
            node.to_string(),
            port.to_string(),
            value_arc,
        ));
        self
    }
    
    pub fn output(mut self, external_name: impl Into<String>, node: &str, port: &str) -> Self {
        self.output_bindings.push((
            external_name.into(),
            node.to_string(),
            port.to_string(),
        ));
        self
    }
    
    pub fn build(mut self) -> Result<Graph, GraphExecutionError> {
        let mut graph = Graph::new(self.name);
        
        // Add nodes
        for (name, node) in self.nodes {
            graph.add_node(name.clone(), node)?;
        }
        
        // Add edges
        for edge in self.edges {
            graph.add_edge(edge)?;
        }
        
        // Setup input bindings
        for (external, node, port, value) in self.input_bindings {
            graph.expose_input_port(&node, &port, &external)?;
            
            if let Some(val) = value {
                let (tx, rx) = tokio::sync::mpsc::channel(1);
                graph.connect_input_channel(&external, rx)?;
                tokio::spawn(async move {
                    let _ = tx.send(val).await;
                });
            }
        }
        
        // Setup output bindings
        for (external, node, port) in self.output_bindings {
            graph.expose_output_port(&node, &port, &external)?;
        }
        
        Ok(graph)
    }
}
```

### Step 2: Simplified Macro

```rust
#[macro_export]
macro_rules! graph {
    (
        $(
            $name:ident : $node:expr
        ),+ $(,)?
        $(
            ; $($connections:tt)*
        )?
    ) => {{
        // Validate that no node is named "graph"
        $(
            $crate::graph::macros::validate_node_name!(stringify!($name));
        )+
        
        let mut builder = $crate::graph::builder::GraphBuilder::new("graph");
        
        // Add nodes
        $(
            builder = builder.add_node(stringify!($name), Box::new($node));
        )+
        
        // Parse connections
        $(
            $crate::graph::macros::parse_connections!(builder, $($connections)*)
        )?
        
        builder.build().expect("Failed to build graph")
    }};
}

/// Validates that a node name is not "graph"
#[macro_export]
macro_rules! validate_node_name {
    ("graph") => {
        compile_error!("Node name 'graph' is reserved for graph I/O namespace. Use 'graph.input_name' for graph inputs and 'graph.output_name' for graph outputs.");
    };
    ($name:expr) => {};
}

#[macro_export]
macro_rules! parse_connections {
    // Parse node-to-node connection: source_node.source_port => target_node.target_port
    // All ports must be explicitly named
    ($builder:ident, $source_node:ident . $source_port:ident => $target_node:ident . $target_port:ident $(, $rest:tt)*) => {
        $builder = $builder.connect(stringify!($source_node), stringify!($source_port), stringify!($target_node), stringify!($target_port));
        $crate::graph::macros::parse_connections!($builder, $($rest)*);
    };
    
    // Parse graph input with value: graph.input_name: value => node.port
    ($builder:ident, graph . $input_name:ident : $value:expr => $node:ident . $port:ident $(, $rest:tt)*) => {
        $builder = $builder.input(stringify!($input_name), stringify!($node), stringify!($port), Some($value));
        $crate::graph::macros::parse_connections!($builder, $($rest)*);
    };
    
    // Parse graph input connection: graph.input_name => node.port
    ($builder:ident, graph . $input_name:ident => $node:ident . $port:ident $(, $rest:tt)*) => {
        $builder = $builder.input(stringify!($input_name), stringify!($node), stringify!($port), None::<()>);
        $crate::graph::macros::parse_connections!($builder, $($rest)*);
    };
    
    // Parse graph output: node.port => graph.output_name
    ($builder:ident, $node:ident . $port:ident => graph . $output_name:ident $(, $rest:tt)*) => {
        $builder = $builder.output(stringify!($output_name), stringify!($node), stringify!($port));
        $crate::graph::macros::parse_connections!($builder, $($rest)*);
    };
    
    ($builder:ident, $(,)?) => {
        $builder
    };
}
```

## Usage Examples

### Example 1: Simple Linear Pipeline

```rust
let graph = graph! {
    range: RangeNode::new("range"),
    filter: FilterNode::new("filter"),
    square: MapNode::new("square"),
    sum: SumNode::new("sum"),
    
    ; range.out => filter.in,
      filter.out => square.in,
      square.out => sum.in,
      graph.start: 1i32 => range.start,
      graph.end: 11i32 => range.end,
      graph.filter_config => filter.configuration,
      graph.map_config => square.configuration,
      sum.out => graph.result
};
```

### Example 2: Fan-Out Pattern

```rust
let graph = graph! {
    source: SourceNode::new("source"),
    filter1: FilterNode::new("filter1"),
    filter2: FilterNode::new("filter2"),
    filter3: FilterNode::new("filter3"),
    
    // Fan-out: each connection must specify explicit ports on BOTH source and target sides
    source.out => filter1.in,
    source.out => filter2.in,
    source.out => filter3.in,
    
    // Configuration supplied at runtime via graph inputs
    graph.filter1_config => filter1.configuration,
    graph.filter2_config => filter2.configuration,
    graph.filter3_config => filter3.configuration
};
```

**Example 2b: Fan-Out with Different Source Ports**

```rust
let graph = graph! {
    router: RouterNode::new("router"),
    filter1: FilterNode::new("filter1"),
    filter2: FilterNode::new("filter2"),
    filter3: FilterNode::new("filter3"),
    
    // Fan-out: different source ports, all explicitly named
    router.out1 => filter1.in,
    router.out2 => filter2.in,
    router.out3 => filter3.in
};
```

### Example 3: Fan-In Pattern

```rust
let graph = graph! {
    source1: SourceNode::new("source1"),
    source2: SourceNode::new("source2"),
    source3: SourceNode::new("source3"),
    merge: MergeNode::new("merge"),
    
    // Fan-in: each connection must specify explicit ports on BOTH source and target sides
    source1.out => merge.in_0,
    source2.out => merge.in_1,
    source3.out => merge.in_2
};
```

**Example 3b: Fan-In with Different Source Ports**

```rust
let graph = graph! {
    source1: SourceNode::new("source1"),
    source2: SourceNode::new("source2"),
    source3: SourceNode::new("source3"),
    merge: MergeNode::new("merge"),
    
    // Fan-in: different source ports, all explicitly named on both sides
    source1.out => merge.in_0,
    source2.error => merge.in_1,  // Different source port name
    source3.out => merge.in_2
};
```

### Example 4: Combined Patterns

```rust
let graph = graph! {
    source: SourceNode::new("source"),
    filter1: FilterNode::new("filter1"),
    filter2: FilterNode::new("filter2"),
    merge: MergeNode::new("merge"),
    process: ProcessNode::new("process"),
    
    // Fan-out: explicit ports for each connection
    source.out => filter1.in,
    source.out => filter2.in,
    
    // Fan-in: explicit ports for each connection
    filter1.out => merge.in_0,
    filter2.out => merge.in_1,
    
    // Continue chain: explicit ports
    merge.out => process.in,
    
    // Graph I/O: explicit ports
    graph.external_input => source.in,
    process.out => graph.external_output
};
```

### Example 5: Invalid - Node Named "graph"

```rust
// This will cause a compile-time error:
let graph = graph! {
    graph: SourceNode::new("graph"),  // ERROR: "graph" is reserved
    // ...
};
```

**Error Message**: `Node name 'graph' is reserved for graph I/O namespace. Use 'graph.input_name' for graph inputs and 'graph.output_name' for graph outputs.`

## Implementation Steps

1. **Create GraphBuilder** (`src/graph/builder.rs`)
   - Implement builder pattern for graph construction
   - Support explicit port connections (no defaults or shortcuts)
   - Handle input/output bindings

2. **Create Macro** (`src/graph/macros.rs`)
   - Implement `graph!` macro
   - Parse node definitions
   - Parse connection patterns
   - Generate builder calls

3. **Add Tests** (`src/graph/macros_test.rs`)
   - Test simple linear pipelines
   - Test fan-out patterns
   - Test fan-in patterns
   - Test graph I/O
   - Test combined patterns

4. **Update Documentation**
   - Add macro usage examples
   - Document syntax patterns
   - Provide migration guide

## Benefits

- **Minimal Syntax**: Reduces boilerplate by 80-90%
- **Visual Clarity**: Connections are immediately visible
- **Type Safety**: Compile-time validation
- **Flexibility**: Supports all graph patterns
- **Explicit Ports**: All connections require explicit port names, preventing ambiguity
- **Clear Namespace**: `graph.` prefix clearly distinguishes graph I/O from node I/O
- **Compile-Time Safety**: Reserved `graph` node name prevents namespace conflicts

## Restrictions

- **Reserved Node Name**: Nodes cannot be named `graph` - this name is reserved for the graph I/O namespace (`graph.input_name` and `graph.output_name`)
- **Required Prefix**: Graph inputs and outputs must use the `graph.` prefix to distinguish them from node-to-node connections
- **Explicit Ports Required**: All connections must explicitly specify port names on **both the source and target sides** (e.g., `node1.out => node2.in`). This applies to:
  - Regular node-to-node connections
  - Fan-out patterns (each connection must name both source and target ports)
  - Fan-in patterns (each connection must name both source and target ports)
  - Graph I/O connections
  - There are no default ports or sequential connection shortcuts
- **Compile-Time Validation**: Attempting to use `graph` as a node name will result in a compile-time error with a helpful message