docs(adr-048): WASM graph transforms architecture (PROPOSED)#19
Merged
Conversation
Formalizes the two-crate split (cognicode-graph-algos +
cognicode-graph-wasm) with a 1-method GraphBuilder trait + pure
algorithm functions, tsify-generated TypeScript types, and a JSON
protocol reusing frontend DTOs.
Spike PASSED: /tmp/opencode/spike-petgraph-wasm/ validated that
petgraph 0.6.5 + serde + serde_json + thiserror compile to
wasm32-unknown-unknown in 5.07s (dev + release). Result captured
in .sddk-spike-wasm-compat.json.
Spike key findings (engram obs-2856):
- petgraph + all transitive deps are pure-Rust WASM-compatible
- PageRank body in graph_analytics.rs:78-177 operates on
Vec<Vec<usize>> + Vec<f64> after a one-time petgraph setup —
NO petgraph API calls in the hot loop
- god_nodes (graph_analytics.rs:248-272) consumes HashMap<usize, f64>
directly — zero petgraph coupling
- 1-method GraphBuilder trait is sufficient (replaces original
4-method GraphLike design)
Required trait imports for petgraph code:
use petgraph::visit::{EdgeRef, NodeIndexable};
Architecture decision:
- cognicode-graph-algos: pure, both targets, deps = [petgraph*,
serde, serde_json, thiserror]
- petgraph-adapter: optional feature (default = []) so WASM bundle
stays clean
- cognicode-graph-wasm: bindgen shim, wasm32 only
- Algorithm bodies are free functions — same .rs compiles to both
- tsify auto-generates .d.ts from #[derive(Tsify)] structs
Tag: v0.13.0-pre (new feature: WASM graph transforms, M reserved
for after all 5 PRs land)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cognicode-graph-algos+cognicode-graph-wasm) withGraphBuilder(1 method) + pure algorithm functionsContext
ADR-047 (v0.12.16) permitted WASM-for-shared-compute but left the architecture unspecified. This ADR specifies the crate structure and validates the approach with empirical evidence (spike).
Decision
cognicode-graph-algosGraphBuilder(1 method) + pure functions + JSON adjacency buildercognicode-graph-wasmpetgraph-adapterfeature gate:default = [], optional. Native builds enable it; WASM builds keep petgraph out of the dep tree.page_rank(in_neighbors, out_degree, n, alpha, max_iter)+god_nodes(scores, percentile). Same.rscompiles to both targets — single source guaranteed by construction.tsify:#[derive(Tsify)]auto-generates.d.ts. No drift.Spike Evidence
.sddk-spike-wasm-compat.jsondocuments:cargo check --target wasm32-unknown-unknownPASS (5.07s dev + release)cargo testPASS (PageRank mass conservation verified)graph_analytics.rs:78-177operates onVec<Vec<usize>>— NO petgraph API calls in the hot loop:248-272) consumesHashMap<usize, f64>directlyAffected Areas
crates/cognicode-graph-algos/crates/cognicode-graph-wasm/Cargo.toml(workspace): add 2 new memberscrates/cognicode-core/src/application/services/graph_analytics.rs: delegate to cognicode-graph-algos.github/workflows/ci.yml: add wasm-build-and-test job + bundle size gateValidation (post-merge, PRs #2-#5)
cargo test -p cognicode-graph-algospasses (native)wasm-pack test --node crates/cognicode-graph-wasmpasses (wasm32)cognicode-corecompiles with re-export (no native caller breakage).wasmgzipped < 500KB (512000 bytes).d.tsmatches Rust struct shapesTag plan: v0.13.0 MINOR (after all 5 PRs land in this cycle)