update
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
## 1. Executive Summary
|
||||
|
||||
This document defines the **blueprint** for NATSBridge - the cross-platform bi-directional data bridge that enables seamless communication between **Julia**, **JavaScript**, **Python**, and **MicroPython** applications using NATS as the message bus.
|
||||
This document defines the **blueprint** for NATSBridge - the cross-platform bi-directional data bridge that enables seamless communication between **Julia**, **JavaScript**, **Python**, **Dart**, and **MicroPython** applications using NATS as the message bus.
|
||||
|
||||
This architecture document serves as the single source of truth for:
|
||||
- **System Structure**: How components fit together and interact
|
||||
@@ -56,17 +56,20 @@ flowchart TD
|
||||
Julia_App[Julia Application]
|
||||
JS_App[JavaScript Application<br/>Node.js/Browser]
|
||||
Python_App[Python Application<br/>Desktop]
|
||||
Dart_App[Dart Application<br/>Desktop/Flutter/Web]
|
||||
MicroPython_App[MicroPython Device]
|
||||
end
|
||||
|
||||
Julia_App -->|NATS| NATS_Server
|
||||
JS_App -->|NATS| NATS_Server
|
||||
Python_App -->|NATS| NATS_Server
|
||||
Dart_App -->|NATS| NATS_Server
|
||||
MicroPython_App -->|NATS| NATS_Server
|
||||
|
||||
Julia_App -->|HTTP| File_Server
|
||||
JS_App -->|HTTP| File_Server
|
||||
Python_App -->|HTTP| File_Server
|
||||
Dart_App -->|HTTP| File_Server
|
||||
MicroPython_App -->|HTTP| File_Server
|
||||
|
||||
style NATS_Server fill:#fff3e0,stroke:#f57c00
|
||||
@@ -74,6 +77,7 @@ flowchart TD
|
||||
style Julia_App fill:#e8f5e9,stroke:#4caf50
|
||||
style JS_App fill:#e3f2fd,stroke:#2196f3
|
||||
style Python_App fill:#e3f2fd,stroke:#2196f3
|
||||
style Dart_App fill:#fff0f6,stroke:#e91e63
|
||||
style MicroPython_App fill:#fce4ec,stroke:#e91e63
|
||||
```
|
||||
|
||||
@@ -85,6 +89,7 @@ flowchart TD
|
||||
Julia_Module[Julia NATSBridge Module]
|
||||
JS_Module[JavaScript NATSBridge Module]
|
||||
Python_Module[Python NATSBridge Module]
|
||||
Dart_Module[Dart NATSBridge Module]
|
||||
MicroPython_Module[MicroPython NATSBridge Module]
|
||||
end
|
||||
|
||||
@@ -101,6 +106,7 @@ flowchart TD
|
||||
Julia_Module --> NATS_Client
|
||||
JS_Module --> NATS_Client
|
||||
Python_Module --> NATS_Client
|
||||
Dart_Module --> NATS_Client
|
||||
MicroPython_Module --> NATS_Client
|
||||
|
||||
NATS_Client --> NATS_Broker
|
||||
@@ -108,6 +114,7 @@ flowchart TD
|
||||
Julia_Module --> File_Client
|
||||
JS_Module --> File_Client
|
||||
Python_Module --> File_Client
|
||||
Dart_Module --> File_Client
|
||||
MicroPython_Module --> File_Client
|
||||
|
||||
File_Client --> File_Server
|
||||
@@ -115,6 +122,7 @@ flowchart TD
|
||||
style Julia_Module fill:#e8f5e9,stroke:#4caf50
|
||||
style JS_Module fill:#e3f2fd,stroke:#2196f3
|
||||
style Python_Module fill:#e3f2fd,stroke:#2196f3
|
||||
style Dart_Module fill:#fff0f6,stroke:#e91e63
|
||||
style MicroPython_Module fill:#fce4ec,stroke:#e91e63
|
||||
style NATS_Broker fill:#fff3e0,stroke:#f57c00
|
||||
style File_Server fill:#f3e5f5,stroke:#9c27b4
|
||||
@@ -180,8 +188,8 @@ flowchart TD
|
||||
| **_build_envelope** | Build message envelope from payloads | All |
|
||||
| **_build_payload** | Build payload object from serialized data | All |
|
||||
| **publish_message** | Publish message to NATS subject | All |
|
||||
| **fileserver_upload_handler** | Upload large payloads to HTTP server | Desktop |
|
||||
| **fileserver_download_handler** | Download payloads from HTTP server | Desktop |
|
||||
| **fileserver_upload_handler** | Upload large payloads to HTTP server | Desktop (Julia/JS/Python/Dart) |
|
||||
| **fileserver_download_handler** | Download payloads from HTTP server | Desktop (Julia/JS/Python/Dart) |
|
||||
|
||||
### Data Flow
|
||||
|
||||
@@ -296,8 +304,8 @@ end
|
||||
|------|-------------|---------------|----------|-----------|
|
||||
| `text` | Plain text string | UTF-8 bytes | Base64 | All |
|
||||
| `dictionary` | JSON object | JSON string | Base64/JSON | All |
|
||||
| `arrowtable` | Apache Arrow IPC | Arrow IPC stream | Base64/arrow-ipc | Desktop (Julia/Python/Node.js) |
|
||||
| `jsontable` | JSON array of objects | JSON string | Base64/json | All (including Browser) |
|
||||
| `arrowtable` | Apache Arrow IPC | Arrow IPC stream | Base64/arrow-ipc | Desktop (Julia/Python/Node.js/Dart) |
|
||||
| `jsontable` | JSON array of objects | JSON string | Base64/json | All (including Browser/Dart Web) |
|
||||
| `image` | Binary image data | Raw bytes | Base64 | All |
|
||||
| `audio` | Binary audio data | Raw bytes | Base64 | All |
|
||||
| `video` | Binary video data | Raw bytes | Base64 | All |
|
||||
@@ -339,7 +347,10 @@ flowchart TD
|
||||
|
||||
| Platform | Size Threshold | Notes |
|
||||
|----------|----------------|-------|
|
||||
| Desktop (Julia/JS/Python) | 500,000 bytes (0.5MB) | Default threshold |
|
||||
| Desktop (Julia/JS/Python/Dart) | 500,000 bytes (0.5MB) | Default threshold |
|
||||
| Dart Desktop | 500,000 bytes (0.5MB) | Default threshold |
|
||||
| Dart Flutter | 500,000 bytes (0.5MB) | Default threshold |
|
||||
| Dart Web | 500,000 bytes (0.5MB) | Default threshold |
|
||||
| MicroPython | 100,000 bytes (100KB) | Lower threshold for memory constraints |
|
||||
|
||||
### Transport Selection Flow
|
||||
@@ -510,6 +521,50 @@ class NATSBridge:
|
||||
self.fileserver_url = fileserver_url or self.DEFAULT_FILESERVER_URL
|
||||
```
|
||||
|
||||
### Dart Architecture
|
||||
|
||||
Dart uses classes for stateful operations with async/await:
|
||||
|
||||
- **Class-based NATSBridge**: Encapsulated API
|
||||
- **Data classes**: Structured data (MsgPayloadV1, MsgEnvelopeV1)
|
||||
- **Async/await**: I/O operations
|
||||
- **dart-arrow**: Arrow IPC support (Desktop/Flutter only)
|
||||
- **HTTP package**: HTTP file server communication
|
||||
- **nats package**: NATS client with WebSocket support (Dart Web)
|
||||
|
||||
```dart
|
||||
class NATSBridge {
|
||||
static const DEFAULT_SIZE_THRESHOLD = 500000;
|
||||
|
||||
final String brokerUrl;
|
||||
final String fileserverUrl;
|
||||
|
||||
NATSBridge({
|
||||
this.brokerUrl = 'nats://localhost:4222',
|
||||
this.fileserverUrl = 'http://localhost:8080',
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
#### Dart Desktop (Dart SDK)
|
||||
|
||||
- **TCP NATS connections**: Uses `nats://` or `tls://` URLs
|
||||
- **Apache Arrow IPC**: Full support via `dart-arrow`
|
||||
- **Uint8List for binary data**: Native Dart binary handling
|
||||
|
||||
#### Dart Flutter (Dart SDK)
|
||||
|
||||
- **TCP NATS connections**: Uses `nats://` or `tls://` URLs
|
||||
- **Apache Arrow IPC**: Full support via `dart-arrow`
|
||||
- **Uint8List for binary data**: Native Dart binary handling
|
||||
|
||||
#### Dart Web (Dart SDK)
|
||||
|
||||
- **WebSocket NATS connections**: Uses `ws://` or `wss://` URLs via `nats` package
|
||||
- **No Apache Arrow**: Uses `jsontable` for tabular data only
|
||||
- **Uint8List for binary data**: Browser-compatible binary handling
|
||||
- **Fetch API**: HTTP file server communication via `http` package
|
||||
|
||||
### Browser Architecture
|
||||
|
||||
Browser JavaScript has specific constraints due to security and compatibility:
|
||||
@@ -676,7 +731,7 @@ MAX_PAYLOAD_SIZE = 50_000 # 50KB hard limit
|
||||
|-----------|---------|-------|
|
||||
| NATS Server | 1 instance | Single node for development |
|
||||
| File Server | 1 instance | HTTP server for large payloads |
|
||||
| Client Memory | 50MB | Desktop platforms |
|
||||
| Client Memory | 50MB | Desktop platforms (Julia/JS/Python/Dart) |
|
||||
| Client Memory | 256KB | MicroPython devices |
|
||||
|
||||
### Environment Variables
|
||||
@@ -771,7 +826,7 @@ flowchart TD
|
||||
|
||||
| Version | Supported Platforms |
|
||||
|---------|---------------------|
|
||||
| v1.0.x | Julia 1.7+, Node.js 16+, Python 3.8+, MicroPython 1.19+ |
|
||||
| v1.0.x | Julia 1.7+, Node.js 16+, Python 3.8+, Dart 2.17+, MicroPython 1.19+ |
|
||||
|
||||
---
|
||||
|
||||
@@ -809,6 +864,7 @@ flowchart TD
|
||||
| [`src/natsbridge_ssr.js`](../src/natsbridge_ssr.js) | Node.js | Arrow IPC, async/await | specification.md:2-19 (all sections) | FR-001 through FR-014, NFR-101 through NFR-405 |
|
||||
| [`src/natsbridge_csr.js`](../src/natsbridge_csr.js) | Browser | JSON table only, WebSocket NATS | specification.md:2-19 (all sections) | FR-001 through FR-014, NFR-101 through NFR-405 |
|
||||
| [`src/natsbridge.py`](../src/natsbridge.py) | Python | Arrow IPC, async/await | specification.md:2-19 (all sections) | FR-001 through FR-014, NFR-101 through NFR-405 |
|
||||
| [`src/natsbridge.dart`](../src/natsbridge.dart) | Dart | Full feature set, Arrow IPC, async/await | specification.md:2-19 (all sections) | FR-001 through FR-014, NFR-101 through NFR-405 |
|
||||
| [`src/natsbridge_mpy.py`](../src/natsbridge_mpy.py) | MicroPython | Limited to direct transport | specification.md:2-19 (all sections) | FR-005, FR-006, FR-012 |
|
||||
|
||||
### 16.3 External Dependencies
|
||||
@@ -827,6 +883,10 @@ flowchart TD
|
||||
| Python | nats-py | Latest | NATS client | specification.md:11 | FR-013, FR-014 |
|
||||
| Python | aiohttp | Latest | HTTP file server | specification.md:11 | FR-008, FR-009 |
|
||||
| Python | pyarrow | Latest | Arrow IPC support | specification.md:11 | FR-002, FR-012 |
|
||||
| Dart | nats | Latest | NATS client | specification.md:11 | FR-013, FR-014 |
|
||||
| Dart | http | Latest | HTTP file server | specification.md:11 | FR-008, FR-009 |
|
||||
| Dart | uuid | Latest | UUID generation | specification.md:11 | FR-011, NFR-401 |
|
||||
| Dart | dart-arrow | Latest | Arrow IPC support | specification.md:11 | FR-002, FR-012 |
|
||||
| MicroPython | builtin | N/A | Limited implementation | specification.md:11 | FR-005, FR-006, FR-012 |
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user