Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions publar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/target
Cargo.lock
node_modules/
package-lock.json
.claude
.DS_STORE
113 changes: 113 additions & 0 deletions publar/ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Publar Architecture

This document describes the technical architecture and implementation details of Publar.

## High-Level Overview

```
┌───────────────────┐
│ Publar UI │
│ (Dioxus) │
└─────────┬─────────┘
┌───────────────────┐
│ Testnet Manager │
│ (pubky-testnet) │
└─────────┬─────────┘
┌───────────┼───────────┐
▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐
│Homeserver│Homeserver│Homeserver│
│ :50000 │ :50001 │ :50002 │
└────▲────┘ └────▲────┘ └────▲────┘
│ │ │
┌───┴──┐ ┌───┴──┐ ┌───┴──┐
│Client│ │Client│ │Client│
└──────┘ └──────┘ └──────┘
```

## Components

### Frontend (Dioxus 0.6)

- **Topbar**: Controls for adding nodes, running scenarios, and resetting
- **Network Visualization**: Interactive SVG graph with force-directed layout (Fruchterman-Reingold algorithm)
- Homeservers: White circles with port labels
- Clients: Lime green (#c7ff00) circles with truncated public keys
- Connections: Lime green lines showing client-homeserver relationships
- **Context Sidebar**: Resizable panel with node details, actions, and event log

### Backend (pubky-testnet + pubky)

- **Testnet Manager**: Manages multiple homeserver processes via pubky-testnet
- **Session Management**: Maintains client sessions with homeservers
- **Scenario Engine**: Executes timed operations (create, connect, write, read)

### State Management

- Dioxus signals for reactive UI updates
- Shared Arc<Mutex<>> for cross-task state access

## Data Flow

```
User Action → Dioxus Event Handler → Testnet Manager → Homeserver HTTP API
Update Signals
UI Re-renders
Log Event Entry
```

## Key Algorithms

### Force-Directed Layout

- **Repulsion**: All nodes push away from each other (prevents overlap)
- **Spring Forces**: Connected nodes maintain ideal distance (~150px)
- **Damping**: Velocity decay creates smooth stabilization
- Runs continuously every 50ms for dynamic repositioning

### Scenario Execution

- Operations grouped by timestamp
- Sequential execution with precise timing
- Async/await for non-blocking UI

## File Structure

```
publar/
├── src/
│ ├── main.rs # App entry, state, event handlers
│ ├── components/
│ │ ├── topbar.rs # Top control bar
│ │ ├── network_visualization.rs # SVG graph with force layout
│ │ └── context_sidebar.rs # Right panel (details + log)
│ ├── testnet.rs # Wrapper around pubky-testnet
│ ├── scenario.rs # Scenario definitions and operations
│ ├── force_layout.rs # Fruchterman-Reingold algorithm
│ └── api.rs # REST API (future)
├── examples/
│ └── testnet_write_read.rs # External connection example
├── assets/
│ ├── input.css # Tailwind source
│ └── tailwind.css # Generated CSS
├── build.rs # Compiles Tailwind on build
├── tailwind.config.js # Tailwind configuration
├── package.json # npm dependencies
├── Cargo.toml # Rust dependencies
├── Dioxus.toml # Dioxus bundling configuration
└── SCENARIOS.md # JSON scenario documentation
```

## Key Technologies

- **[Dioxus 0.6](https://dioxuslabs.com/)**: Cross-platform UI framework (desktop, web, mobile)
- **[Tailwind CSS v3](https://tailwindcss.com/)**: Utility-first styling
- **[Tokio](https://tokio.rs/)**: Async runtime
- **[pubky-testnet 0.6.0-rc.6](https://github.com/pubky/pubky)**: Manages local homeserver processes
- **[pubky 0.6.0-rc.6](https://github.com/pubky/pubky)**: Client library for Pubky protocol
36 changes: 36 additions & 0 deletions publar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "publar"
version = "0.1.0"
edition = "2021"
authors = ["Kevin Karsopawiro <kevin@synonym.to>"]
description = "A desktop application for visualizing, testing, and debugging Pubky network topologies"
license = "MIT"
repository = "https://github.com/pubky/publar"

[dependencies]
dioxus = { version = "0.6", features = ["desktop"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0"
tracing = "0.1"
tracing-subscriber = "0.3"
pubky-testnet = "0.6.0-rc.6"
pubky = "0.6.0-rc.6"
axum = "0.7"
tower-http = { version = "0.5", features = ["cors"] }
chrono = "0.4"
reqwest = "0.11"
rfd = { version = "0.14", default-features = false, features = ["xdg-portal", "tokio"] }

[profile]

[profile.wasm-dev]
inherits = "dev"
opt-level = 1

[profile.server-dev]
inherits = "dev"

[profile.android-dev]
inherits = "dev"
12 changes: 12 additions & 0 deletions publar/Dioxus.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[application]
name = "publar"
default_platform = "desktop"

[bundle]
identifier = "com.synonym.publar"
publisher = "Synonym"
icon = []

[application.desktop]
window_width = 800
window_height = 600
21 changes: 21 additions & 0 deletions publar/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Synonym

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading