# sqlitegraph-core/src/algo/ — Graph Algorithms
Collection of graph algorithms built on top of sqlitegraph's graph primitives.
These are the "query templates" that transform graph structure into actionable results.
## Architecture
- `mod.rs` — Module exports.
- `backend/` — Algorithm backend abstractions (4 files).
- Files (flat): BFS, DFS, shortest path, k-hop, PageRank, community detection, centrality, etc.
## Key Algorithms
- **Traversal**: BFS, DFS, k-hop neighborhood, bidirectional shortest path.
- **Community**: Louvain modularity optimization, label propagation.
- **Centrality**: Betweenness, closeness, degree, eigenvector centrality.
- **Ranking**: PageRank, personalized PageRank (with seed nodes).
- **Matching**: Subgraph isomorphism, pattern matching.
## Key Conventions
- All algorithms take a `GraphBackend` trait reference — backend-agnostic.
- Results are returned as typed structs, not raw rows. No `HashMap<String, Value>`.
- Large algorithms support streaming/iterators — don't materialize the full result set in memory.
- Community detection is iterative — provide convergence threshold and max iterations.
- Algorithms use the graph's connection pool for concurrent reads where possible.
## When Editing Here
- Performance-critical paths MUST use prepared statements (via the graph's `StatementWrapper`).
- New algorithms: create a new file, add `pub mod` to `mod.rs`, implement on `GraphBackend` trait.
- Louvain is the most complex — changes affect community detection used everywhere.
- Test with graphs of varying size: 10 nodes (correctness), 10K nodes (performance), 1M nodes (stress).