8000 Phase 3 Complete: Datalog with Recursive Rules by adityamukho · Pull Request #5 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
15b03ec
Pivot documentation from GQL to Datalog
adityamukho Jan 13, 2026
2d26304
Removed mention of GQL (no more relevant).
adityamukho Jan 13, 2026
90521a6
Removed mention of GQL (no more relevant).
adityamukho Jan 13, 2026
4736656
Implement EAV data model for Datalog (Phase 3.1)
adityamukho Jan 13, 2026
f550dbd
Use timestamp-based transaction IDs (millisecond precision)
adityamukho Jan 13, 2026
37bee28
Merge main into devel (Phase 3: Datalog Core)
adityamukho Jan 13, 2026
ad96e7d
Update demo commands to showcase Datalog syntax (Phase 3)
adityamukho Jan 13, 2026
065fc18
Remove GQL backward compatibility from REPL
adityamukho Jan 13, 2026
a98805f
Complete removal of GQL implementation in favor of Datalog
adityamukho Jan 13, 2026
c916bd5
Fix keyword entity matching in Datalog queries
adityamukho Jan 13, 2026
b3a1c22
Add CLI argument for file-based persistent storage
adityamukho Jan 13, 2026
7029700
Replace bincode with postcard for serialization
adityamukho Jan 13, 2026
6e0840c
Removed PI-like constants to keep linter from whining.
adityamukho Jan 13, 2026
174c39b
Ignore comments, accept multi-line inputs.
adityamukho Jan 13, 2026
34deda4
Update demo commands to showcase Datalog syntax (Phase 3)
adityamukho Jan 13, 2026
ccb2d87
Remove GQL backward compatibility from REPL
adityamukho Jan 13, 2026
a702185
Complete removal of GQL implementation in favor of Datalog
adityamukho Jan 13, 2026
0574af3
Fix keyword entity matching in Datalog queries
adityamukho Jan 13, 2026
98d7223
Add CLI argument for file-based persistent storage
adityamukho Jan 13, 2026
2a54b83
Replace bincode with postcard for serialization
adityamukho Jan 13, 2026
40ee467
Removed PI-like constants to keep linter from whining.
adityamukho Jan 13, 2026
99ad0c8
Ignore comments, accept multi-line inputs.
adityamukho Jan 13, 2026
bb55e6c
Merge remote-tracking branch 'origin/devel' into devel
adityamukho Jan 13, 2026
83858fd
Update description.
adityamukho Jan 13, 2026
ea7461e
Added comma to punctuate long list.
adityamukho Jan 13, 2026
54a8116
Documented design choice to load DB in-memory even with persistent st…
adityamukho Jan 13, 2026
11257e3
Update to reflect test current coverage status.
adityamukho Jan 13, 2026
623d6f6
Complete Phase 3: Datalog with recursive rules and comprehensive testing
adityamukho Jan 13, 2026
27fe557
Remove scan-pr job from OSV-Scanner workflow
adityamukho Jan 13, 2026
671d7ac
Revert "Remove scan-pr job from OSV-Scanner workflow"
adityamukho Jan 13, 2026
3266370
Update OSV-Scanner action to v2.3.1 to fix deprecated upload-artifact
adityamukho Jan 13, 2026
9f50ebb
Add actions:read permission for OSV-Scanner v2.3.1
adityamukho Jan 13, 2026
4920c82
Merge branch 'main' into devel
adityamukho Jan 13, 2026
9ec2926
Use or_default() instead of or_insert_with(Vec::new)
adityamukho Jan 13, 2026
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
134 changes: 85 additions & 49 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

Minigraf is a tiny, portable **bi-temporal graph database with Datalog queries** written in Rust. It's designed to be the "SQLite of graph databases" - embedded, single-file, reliable, with time travel capabilities.

**Current Status: Phase 2 Complete → Phase 3 Starting** - Pivoting from GQL to Datalog:
**Current Status: Phase 3 COMPLETE ✅ → Phase 4 Starting** - Datalog with Recursive Rules:
- ✅ Phase 1: Property graph PoC (in-memory)
- ✅ Phase 2: Persistent storage (`.graph` file format, embedded API)
- 🎯 Phase 3: Datalog core (EAV model, recursive rules) - **NEXT**
- 🎯 Phase 4: Bi-temporal support (transaction time + valid time)
- ✅ **Phase 3: Datalog core (EAV model, recursive rules) - COMPLETE!**
- 🎯 Phase 4: Bi-temporal support (transaction time + valid time) - **NEXT**
- 🎯 Phase 5: ACID + WAL (crash safety, transactions)
- 🎯 Phase 6: Performance (indexes, query optimization)
- 🎯 v1.0.0: 12-15 months
Expand Down Expand Up @@ -257,6 +257,13 @@ Page 1+: Data
- Future: EAV facts with temporal dimensions
```

**Serialization Format** (Phase 3+):
- Using **postcard** (v1.0+) for fact serialization
- Replaced bincode (unmaintained as of 2024/2025)
- postcard: Lightweight, embedded-focused, better size than bincode
- Future consideration: Evaluate **rkyv** in Phase 5/6 for zero-copy
deserialization when implementing WAL or memory-mapped access

### Query Language

**Current (Phase 1-2, GQL-inspired)** - Archived:
Expand Down Expand Up @@ -302,60 +309,83 @@ SHOW NODES

## Test Coverage

**Current Tests (Phase 1-2)**: 54 tests passing ✅
- Unit tests:
- `src/graph/types.rs`: Node/Edge creation, PropertyValue
- `src/graph/storage.rs`: CRUD, queries, edge relationships
- `src/query/parser.rs`: GQL syntax parsing
- `src/query/executor.rs`: Query execution, validation
- `src/storage/`: Backend operations, persistence
- `src/minigraf.rs`: Embedded API
- Integration tests:
- `tests/integration_test.rs`: Complete workflow
- `tests/concurrency_test.rs`: Thread safety
- `tests/edge_cases_test.rs`: Edge cases, dirty flags

**Future Tests (Phase 3+)**:
- Datalog parser (EDN syntax)
- Pattern matching and unification
- Recursive rule evaluation
- Transitive closure
- Bi-temporal queries (Phase 4)
- WAL and crash recovery (Phase 5)
- Index performance (Phase 6)
**Current Tests (Phase 3)**: 123 tests passing ✅
- **Unit tests** (94 tests):
- `src/graph/types.rs`: Fact types, Value types, EAV model
- `src/graph/storage.rs`: FactStorage, CRUD, history tracking
- `src/query/datalog/parser.rs`: EDN/Datalog syntax parsing, rules
- `src/query/datalog/types.rs`: Pattern, WhereClause, DatalogQuery
- `src/query/datalog/matcher.rs`: Pattern matching, variable unification
- `src/query/datalog/executor.rs`: Query execution, rule registration
- `src/query/datalog/rules.rs`: RuleRegistry, rule management
- `src/query/datalog/evaluator.rs`: Semi-naive evaluation, transitive closure
- `src/storage/`: Backend operations, persistence (postcard)

- **Integration tests** (26 tests):
- `tests/complex_queries_test.rs` (10 tests): Multi-pattern joins, self-joins, edge cases
- `tests/recursive_rules_test.rs` (9 tests): Transitive closure, cycles, long chains, family trees
- `tests/concurrency_test.rs` (7 tests): Thread safety, concurrent rule registration/queries

- **Doc tests** (3 tests): Inline documentation examples

**Comprehensive Coverage**:
- ✅ Datalog parser (EDN syntax) - 15 tests
- ✅ Pattern matching and unification - 16 tests
- ✅ **Recursive rule evaluation** - 15 tests (NEW!)
- ✅ **Transitive closure** - 9 tests (NEW!)
- ✅ **Concurrency** - 7 tests (NEW!)
- ✅ Complex queries (3+ patterns, self-joins) - 10 tests (NEW!)

**Demo Scripts**:
- `demo_recursive.txt`: Comprehensive recursive rules examples (transitive closure, cycles, family trees)

Run tests with: `cargo test`
See `TEST_COVERAGE.md` for detailed coverage report.

**Future Tests (Phase 4+)**:
- Bi-temporal queries (:as-of, :valid-at) - Phase 4
- WAL and crash recovery - Phase 5
- Index performance - Phase 6

## Development Notes

### Phase 2 (Current) - Foundation Complete ✅
### Phase 2 (Complete) - Foundation ✅

- **Storage backend abstraction** - Solid foundation for Phase 3+
- **Single `.graph` file** - Philosophy-aligned persistent storage
- **Embedded API** - `Minigraf::open()` works like SQLite
- **UUID-based IDs** - Will continue in EAV model
- **UUID-based IDs** - Continues in EAV model
- **Thread-safe** - Concurrent read/write via RwLock
- **Property types** - Will map to Value enum in Phase 3
- **Auto-save** - On drop, works reliably
- **Cross-platform** - Endian-safe file format

### Phase 3 (Next) - Datalog Core 🎯
### Phase 3 (Complete) - Datalog Core ✅

**Implemented Features**:
- ✅ EAV data model with Facts (entity, attribute, value, tx_id, asserted)
- ✅ Datalog parser (EDN syntax, lists, vectors, UUIDs, keywords)
- ✅ Pattern matching engine with variable unification
- ✅ Query executor (transact, retract, query, rule commands)
- ✅ **Recursive rules with semi-naive evaluation** (fixed-point iteration)
- ✅ **Transitive closure queries** (multi-hop reachability)
- ✅ **Cycle handling** (graphs with cycles converge correctly)
- ✅ RuleRegistry (thread-safe rule management)
- ✅ RecursiveEvaluator (delta-based fixed-point iteration)
- ✅ REPL with multi-line support and comments
- ✅ Persistent storage with postcard serialization

**Test Coverage**: 123 tests (94 unit + 26 integration + 3 doc)

**Demo**: `demo_recursive.txt` - Working examples of recursive rules

**Migration Strategy**:
1. Add EAV types alongside existing property graph types
2. Implement Datalog parser (new module)
3. Build query executor with pattern matching
4. Add recursive rule evaluation
5. Update REPL to support both syntaxes temporarily
6. Gradually migrate tests
7. Eventually deprecate property graph types
### Phase 4 (Next) - Bi-temporal Support 🎯

**Key Implementation Tasks**:
- EDN parser for Datalog syntax
- Pattern matching engine
- Variable unification
- Semi-naive evaluation for recursion
- Stratification for safe recursion
**Planned Features**:
- Transaction time queries (`:as-of tx-id`)
- Valid time dimensions (`valid_from`, `valid_to`)
- Time travel queries (`:valid-at timestamp`)
- History tracking and audit trails
- Bi-temporal joins

### Philosophy-Aligned Development

Expand All @@ -368,14 +398,16 @@ When implementing features, always ask:

## Future Work (Roadmap)

**Phase 3** (3-4 months): Datalog Core
- EAV data model
- Datalog parser (EDN syntax)
- Pattern matching and unification
- Recursive rules (semi-naive evaluation)
- Updated REPL
**Phase 3** ✅ **COMPLETE** - Datalog Core
- ✅ EAV data model with Facts
- ✅ Datalog parser (EDN syntax)
- ✅ Pattern matching and unification
- ✅ Recursive rules (semi-naive evaluation)
- ✅ Transitive closure and cycle handling
- ✅ Updated REPL with multi-line and comments
- ✅ 123 comprehensive tests

**Phase 4** (3-4 months): Bi-temporal Support
**Phase 4** (3-4 months): Bi-temporal Support - **NEXT**
- Transaction time (tx_id, tx_time)
- Valid time (valid_from, valid_to)
- Time travel queries (:as-of, :valid-at)
Expand All @@ -391,6 +423,10 @@ When implementing features, always ask:
- Indexes (EAVT, AEVT, AVET, VAET)
- Query optimization
- Benchmarking
- **Evaluate rkyv**: Consider switching from postcard to rkyv for zero-copy
deserialization. rkyv offers 2x better performance for reads/writes but adds
complexity. Worth evaluating when implementing memory-mapped database access
or when WAL performance becomes critical.

**Phase 7** (3-4 months): Cross-platform
- WASM (IndexedDB backend)
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
name = "minigraf"
version = "0.1.0"
edition = "2024"
description = "A tiny, portable GQL (Graph Query Language) engine"
description = "Zero-config, single-file, embedded graph database with bi-temporal Datalog queries"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
bincode = "1.3"
postcard = { version = "1.0", features = ["alloc"] }
anyhow = "1.0"
uuid = { version = "1.0", features = ["v4", "v5", "serde"] }
clap = { version = "4.5", features = ["derive"] }

[profile.release]
panic = "abort"
Loading
0