mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
- synapse-ffi: graph_data() returns the whole page-level graph (links, tags, property refs, block refs/embeds per page, unlinked mentions, decayed synapses) as parallel arrays with degree, backlinks, Louvain clusters and primary tags; cached by op seq, synapse state and hour. - synapse-ffi: ForceLayout, a Barnes-Hut force layout stepped from Dart on a Rust worker thread (pin/unpin for dragging, reheat). - app: Graph view with a mode selector (Network, Local, Synapses, Clusters, Namespaces, Timeline), filters (title, tag, date range, min links, orphans, journals, mentions), pan/zoom, node drag, hover highlighting, activation pulse, cluster hulls, radial namespace/tag tree, and a local graph panel on every page. Edges render as one vertex mesh, nodes in colour/size batches, culled to the viewport. - Tests: Rust extraction/mentions/cache/clusters/layout; widget tests for mode switching, filters and layout restarts; a real-app integration smoke test with frame timings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
5.8 KiB
Markdown
102 lines
5.8 KiB
Markdown
# App (Flutter) and FFI
|
||
|
||
## Layout
|
||
- `crates/synapse-ffi`: the only API the app sees. `src/api/` is scanned by
|
||
`flutter_rust_bridge` (v2.13): `graph.rs` (opaque `SynapseGraph` handle, reads), `outline.rs`
|
||
(block editing), `search.rs` (title/block lookup until `synapse-search` is wired), `dto.rs`.
|
||
Extension points for search/AI/history/CalDAV/sync are documented in `src/api/mod.rs`.
|
||
- `app/`: Flutter client. `lib/src/rust/` is generated; `rust_builder/` is the cargokit glue
|
||
that builds `synapse-ffi` as part of `flutter build`/`run` (paths point at
|
||
`../crates/synapse-ffi`).
|
||
- `app/lib/src/`: `backend/` (`GraphBackend` interface + FFI implementation), `state/`
|
||
(app state, write queue, outline controller and algorithms), `editor/` (block row, editor,
|
||
Markdown renderer, autocomplete), `views/` (journals, page, timeline, all pages, quick
|
||
switcher, shell), `theme/`.
|
||
|
||
## Toolchain
|
||
- Flutter stable (3.47+) on `PATH`, Rust stable via rustup, `cargo install
|
||
flutter_rust_bridge_codegen --version 2.13.0 --locked`.
|
||
- rustup's `~/.cargo/bin` must come **before** `/usr/bin` in `PATH`. Fedora's packaged `cargo`
|
||
(rust 1.99) cannot reuse artifacts built by rustup's toolchain (1.97) and cargokit picks up
|
||
whichever `cargo` is first: `export PATH="$HOME/.cargo/bin:$PATH"` (check with
|
||
`cargo --version`), or remove the distro `cargo`/`rust` packages.
|
||
- Linux desktop: `clang cmake ninja-build gtk3-devel` (Fedora) / `clang cmake ninja-build
|
||
libgtk-3-dev` (Debian/Ubuntu).
|
||
- Android: Android SDK + NDK (cargokit installs the Rust targets with rustup).
|
||
- Windows: Visual Studio 2022 with "Desktop development with C++", Rust MSVC toolchain.
|
||
|
||
## Build and run
|
||
```bash
|
||
cd app
|
||
flutter run -d linux # debug, builds the Rust crate via cargokit
|
||
flutter build linux --release # build/linux/x64/release/bundle/
|
||
flutter run -d <android-device> # or: flutter build apk --release
|
||
flutter build windows --release # on Windows
|
||
```
|
||
The graph lives in the platform app-support dir (`~/.local/share/es.zenvairo.synapse/graph`
|
||
on Linux). Override it with `SYNAPSE_GRAPH=/path/to/graph`.
|
||
|
||
## After changing the FFI API
|
||
```bash
|
||
cd app && flutter_rust_bridge_codegen generate
|
||
```
|
||
Commit the regenerated `crates/synapse-ffi/src/frb_generated.rs` and `app/lib/src/rust/`.
|
||
`frb_generated.rs` is excluded from rustfmt.
|
||
|
||
## Checks
|
||
- `cargo test -p synapse-ffi` (outline semantics against the real core).
|
||
- `cd app && dart analyze && flutter test` (editor key handling runs against an in-memory
|
||
backend that reuses the Dart outline algorithms).
|
||
- `flutter analyze` crashes when the project path contains non-ASCII characters (its LSP
|
||
channel miscounts bytes); `dart analyze` runs the same analysis.
|
||
|
||
## Editor
|
||
- Blocks render Markdown when idle and become raw-Markdown text fields when focused.
|
||
- Keys: Enter split (at start: new block above), Shift+Enter newline, Tab/Shift+Tab
|
||
indent/outdent (Logseq's direct outdenting), Backspace at start merges into the previous
|
||
block, Delete at end pulls the next one in, ↑/↓/←/→ cross block edges, Alt+Shift+↑/↓ move
|
||
among siblings, Ctrl+↑/↓ collapse/expand, Ctrl+Enter cycles TODO/DONE, Esc leaves editing.
|
||
- `[[`, `((` auto-pair; `[[`, `#` and `((` open autocomplete (↑/↓, Enter/Tab, Esc).
|
||
- Drag a bullet onto a row: upper half = before, lower half = after, lower half to the right
|
||
= first child.
|
||
- Edits apply locally at once and go to the core through one serial write queue (text saves
|
||
are debounced 350 ms); after structural edits the outline is re-read and the core's
|
||
structure wins if they ever disagree.
|
||
- App shortcuts: Ctrl+K quick switcher, Ctrl+Shift+J journals, Ctrl+Shift+T timeline,
|
||
Ctrl+\ sidebar, Alt+←/→ back/forward.
|
||
|
||
## Graph view
|
||
One view (sidebar "Graph", Ctrl+Shift+G) with a mode selector:
|
||
- **Network**: force-directed graph of pages (journals optional). Edges: links, tags,
|
||
property refs, block refs/embeds (aggregated per page) and dashed mentions (unlinked
|
||
references: a page title appearing as whole words in another page's text). Node size by
|
||
degree + backlinks, colour by cluster or primary tag. Filters: title, tag, created date
|
||
range, min links, orphans, journals, mentions. Drag nodes, hover highlights neighbours,
|
||
wheel/pinch zoom, tap opens the page.
|
||
- **Local**: neighbourhood of a page at depth 1–3 (also a side panel on every page).
|
||
- **Synapses**: `related()` spreading activation from a focus page; brightness/size =
|
||
activation, edge thickness = Hebbian synapse weight, a pulse travels outward by hops.
|
||
- **Clusters**: Louvain communities with soft hulls.
|
||
- **Namespaces**: radial tree of `a/b/c` titles and of tags with their pages.
|
||
- **Timeline**: the journal timeline.
|
||
|
||
Data and layout live in Rust: `SynapseGraph::graph_data()` returns the whole page-level
|
||
graph as parallel arrays (cached until the op seq or the synapse table changes);
|
||
`ForceLayout` (Barnes-Hut, O(n log n)) is stepped from Dart in small batches on a Rust
|
||
worker thread. The painter batches draws (one call per edge kind and node colour/size),
|
||
culls to the viewport and limits labels with an occupancy grid.
|
||
|
||
```bash
|
||
# Stats and timings for a graph (release build)
|
||
cargo run --release -p synapse-ffi --example graph_stats -- /path/to/graph
|
||
# Real-app smoke test of every graph mode with frame timings (opens a window; use a copy
|
||
# of the graph, opening it may write today's journal). Profile mode for real numbers:
|
||
cd app && flutter drive --profile -d linux --driver=test_driver/integration_test.dart \
|
||
--target=integration_test/graph_smoke_test.dart \
|
||
--dart-define=GRAPH=/path/to/copy [--dart-define=SHOTS=/dir/for/pngs]
|
||
```
|
||
Measured (profile, Linux, Impeller GL): 5 000 pages / 19 000 links settle in ~7 s and pan at
|
||
build p50 6 ms / raster p50 4 ms per frame; a 360-page graph settles in ~1 s at ~2 ms/frame.
|
||
Edges are drawn as one triangle mesh (`drawVertices`): stroking 10k+ lines made Impeller
|
||
tessellate every frame (raster ~40 ms).
|