diff --git a/PHILOSOPHY.md b/PHILOSOPHY.md index 1e4750715a..b5b91ecbf7 100644 --- a/PHILOSOPHY.md +++ b/PHILOSOPHY.md @@ -432,8 +432,8 @@ The `.graph` file format must be: - Single-file storage, persistent graph database, embedded API - GQL-inspired PoC (archived at `archive/gql-phase-2`) -**Phase 3**: 🎯 Datalog Core (NEXT - 3-4 months) -- EAV data model, basic facts and queries, recursive rules +**Phase 3**: ✅ Datalog Core (COMPLETE) +- EAV data model, basic facts and queries, recursive rules, semi-naive evaluation **Phase 4**: 🎯 Bi-temporal Support (3-4 months) - Transaction time + valid time, time travel queries, history diff --git a/README.md b/README.md index 4549db7092..45832037d1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Clippy Status](https://github.com/adityamukho/minigraf/actions/workflows/rust-clippy.yml/badge.svg)](https://github.com/adityamukho/minigraf/actions/workflows/rust-clippy.yml) [![License: MPL 2.0](https://img.shields.io/badge/License-MPL_2.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0) [![Rust Edition](https://img.shields.io/badge/rust-2024-orange.svg)](https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html) -[![Phase](https://img.shields.io/badge/phase-2%20complete-blue.svg)](https://github.com/adityamukho/minigraf/blob/main/ROADMAP.md) +[![Phase](https://img.shields.io/badge/phase-3%20complete-blue.svg)](https://github.com/adityamukho/minigraf/blob/main/ROADMAP.md) > **The SQLite of bi-temporal graph databases** - Embedded Datalog engine written in Rust @@ -18,7 +18,7 @@ Minigraf is a **single-file embedded graph database** that lets you: - ✅ **Embed anywhere** - Native, WASM, mobile, IoT - one `.graph` file - ✅ **Zero configuration** - Just `Minigraf::open("data.graph")` and you're done -**Status**: Early development. Phase 2 complete (persistent storage). Now pivoting from GQL to Datalog for better temporal semantics. +**Status**: Early development. Phase 3 complete (Datalog with recursive rules). Now starting Phase 4 (bi-temporal support). ## Why Datalog? @@ -30,23 +30,25 @@ Minigraf is a **single-file embedded graph database** that lets you: 4. **Proven at scale** - 40+ years of research, production use (Datomic, XTDB) 5. **Graph-native** - Facts (Entity-Attribute-Value) are literally edges -## Current Status - Phase 2 +## Current Status - Phase 3 Complete -Minigraf has **persistent storage foundation** ready for Datalog: +Minigraf has **working Datalog query engine with recursive rules**: +- ✅ **EAV data model** - Entity-Attribute-Value facts with transaction IDs +- ✅ **Datalog queries** - Pattern matching with variable unification +- ✅ **Recursive rules** - Semi-naive evaluation, transitive closure - ✅ **Single `.graph` file** - Page-based storage (4KB pages) - ✅ **Embedded database API** - Use like SQLite (`Minigraf::open()`) - ✅ **Cross-platform** - Works on Linux, macOS, Windows, iOS, Android - ✅ **Auto-persistence** - Changes auto-save when database is dropped -- ✅ **Storage abstraction** - File, Memory backends (IndexedDB future) -- ✅ **54 tests passing** - Comprehensive test coverage -- 🎯 **Query language** - Transitioning from GQL to Datalog (Phase 3) +- ✅ **123 tests passing** - Comprehensive test coverage +- 🎯 **Next: Bi-temporal support** - Transaction time + valid time (Phase 4) **GQL Archive**: Previous GQL implementation preserved at `archive/gql-phase-2` branch and `gql-phase-2-complete` tag. -## Quick Start (Future API) +## Quick Start -### Embedded Datalog Database +### Embedded Datalog Database (Working!) ```rust use minigraf::Minigraf; @@ -75,20 +77,23 @@ let past_db = db.as_of(tx_100); let old_results = past_db.query(...)?; ``` -### Interactive Console (Current - In-memory) +### Interactive Console (Datalog REPL) ```bash -# Build and run the REPL (currently supports basic graph operations) +# Build and run the Datalog REPL cargo run # Run tests cargo test +# Try the recursive rules demo +cargo run < demo_recursive.txt + # Run examples cargo run --example embedded ``` -## Datalog Query Language (Planned - Phase 3) +## Datalog Query Language (Phase 3 - Working!) ### Basic Facts @@ -210,10 +215,10 @@ The `.graph` file uses a page-based format (like SQLite): **Phase 1**: ✅ Property graph PoC (Complete) **Phase 2**: ✅ Persistent storage (Complete) -**Phase 3**: 🎯 Datalog core (3-4 months) -- Basic facts and queries -- Recursive rules -- Pattern matching +**Phase 3**: ✅ Datalog core (Complete) +- ✅ Basic facts and queries +- ✅ Recursive rules +- ✅ Pattern matching **Phase 4**: 🎯 Bi-temporal support (3-4 months) - Valid time + transaction time @@ -305,17 +310,23 @@ Comprehensive test coverage: cargo test ``` -Current tests (54 total): -- Property graph operations (Phase 1-2 foundation) -- Storage backend operations -- Persistence and recovery -- Concurrency and edge cases - -Future tests (Phase 3+): -- Datalog parser -- Recursive rule evaluation -- Bi-temporal queries -- Transaction isolation +Current tests (123 total): +- ✅ **94 unit tests** - Core Datalog, EAV model, parser, matcher, executor +- ✅ **26 integration tests** - Complex queries, recursive rules, concurrency +- ✅ **3 doc tests** - Inline documentation examples + +**Phase 3 Coverage** (Complete): +- ✅ Datalog parser (EDN syntax) +- ✅ Recursive rule evaluation (semi-naive) +- ✅ Transitive closure queries +- ✅ Pattern matching and unification +- ✅ Storage backend operations +- ✅ Concurrency and thread safety + +**Future tests** (Phase 4+): +- ⏳ Bi-temporal queries (:as-of, :valid-at) +- ⏳ Transaction isolation (ACID) +- ⏳ Crash recovery (WAL) ## Comparison to Similar Projects diff --git a/ROADMAP.md b/ROADMAP.md index 59eb9cfaa6..84edc27c8e 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -55,23 +55,23 @@ --- -## Phase 3: Datalog Core 🎯 NEXT +## Phase 3: Datalog Core ✅ COMPLETE **Goal**: Implement core Datalog query engine -**Status**: 🎯 In Progress (Expected: 3-4 months) +**Status**: ✅ Completed (January 2026) **Priority**: 🔴 Critical - Foundation for everything else -### 3.1 EAV Data Model +### 3.1 EAV Data Model ✅ **Features**: -- 🎯 Migrate from property graph to Entity-Attribute-Value model -- 🎯 Fact representation: `(Entity, Attribute, Value)` -- 🎯 Entities as UUIDs (keep existing ID system) -- 🎯 Attributes as keywords (`:person/name`, `:friend`) -- 🎯 Values: primitives or entity references -- 🎯 Update storage format to support EAV tuples +- ✅ Migrate from property graph to Entity-Attribute-Value model +- ✅ Fact representation: `(Entity, Attribute, Value)` +- ✅ Entities as UUIDs (keep existing ID system) +- ✅ Attributes as keywords (`:person/name`, `:friend`) +- ✅ Values: primitives or entity references +- ✅ Update storage format to support EAV tuples **Technical Approach**: ```rust @@ -100,14 +100,14 @@ enum Value { - Gradually migrate tests - Eventually deprecate property graph types -### 3.2 Datalog Parser +### 3.2 Datalog Parser ✅ **Features**: -- 🎯 Parse basic Datalog queries (EDN syntax) -- 🎯 Query structure: `[:find ?vars :where [clauses]]` -- 🎯 Pattern matching: `[?e :attr ?v]` -- 🎯 Variable binding -- 🎯 Constants and entity references +- ✅ Parse basic Datalog queries (EDN syntax) +- ✅ Query structure: `[:find ?vars :where [clauses]]` +- ✅ Pattern matching: `[?e :attr ?v]` +- ✅ Variable binding +- ✅ Constants and entity references **Example Queries**: ```datalog @@ -135,13 +135,13 @@ enum Value { - Variable extraction - Pattern recognition -### 3.3 Query Executor (Basic) +### 3.3 Query Executor (Basic) ✅ **Features**: -- 🎯 Pattern matching against fact database -- 🎯 Variable unification -- 🎯 Join multiple patterns -- 🎯 Return results as tuples +- ✅ Pattern matching against fact database +- ✅ Variable unification +- ✅ Join multiple patterns +- ✅ Return results as tuples **Implementation**: - Naive evaluation initially (optimize in Phase 6) @@ -149,13 +149,13 @@ enum Value { - Cartesian product + filter (like nested loops) - Return binding sets -### 3.4 Recursive Rules +### 3.4 Recursive Rules ✅ **Features**: -- 🎯 Define rules: `[(rule-name ?args) [body]]` -- 🎯 Stratified recursion (safe subset) -- 🎯 Rule evaluation via semi-naive evaluation -- 🎯 Transitive closure queries +- ✅ Define rules: `[(rule-name ?args) [body]]` +- ✅ Stratified recursion (safe subset) +- ✅ Rule evaluation via semi-naive evaluation +- ✅ Transitive closure queries **Example Rules**: ```datalog @@ -179,13 +179,13 @@ enum Value { - Stop when no new facts produced - Detect cycles, prevent infinite loops -### 3.5 REPL for Datalog +### 3.5 REPL for Datalog ✅ **Features**: -- 🎯 Interactive Datalog console -- 🎯 Transact facts -- 🎯 Query with Datalog -- 🎯 Pretty-print results +- ✅ Interactive Datalog console +- ✅ Transact facts +- ✅ Query with Datalog +- ✅ Pretty-print results **Commands**: ```clojure @@ -206,20 +206,23 @@ enum Value { (exit) ``` -### 3.6 Tests +### 3.6 Tests ✅ **Test Coverage**: -- EAV data model CRUD -- Datalog parser (all query forms) -- Pattern matching -- Variable unification -- Multi-pattern joins -- Recursive rule evaluation -- Transitive closure queries +- ✅ EAV data model CRUD (8 tests) +- ✅ Datalog parser (all query forms) (15 tests) +- ✅ Pattern matching (6 tests) +- ✅ Variable unification (included in matcher tests) +- ✅ Multi-pattern joins (10 integration tests) +- ✅ Recursive rule evaluation (15 tests) +- ✅ Transitive closure queries (9 integration tests) +- ✅ Concurrency (7 integration tests) -**Deliverable**: Working Datalog query engine with recursion +**Total: 123 tests passing** ✅ -**Timeline**: 3-4 months +**Deliverable**: ✅ Working Datalog query engine with recursion (Complete!) + +**Timeline**: ✅ Completed in ~3 weeks (January 2026) --- @@ -588,11 +591,13 @@ tx.commit()?; // or tx.rollback()? **GQL Archive**: `archive/gql-phase-2` branch, `gql-phase-2-complete` tag -### v0.3.0 - 🎯 Phase 3 (Datalog Core) -- EAV data model -- Datalog queries -- Recursive rules -- Pattern matching +### v0.3.0 - ✅ Phase 3 Complete (Datalog Core) +- ✅ EAV data model +- ✅ Datalog queries +- ✅ Recursive rules +- ✅ Pattern matching +- ✅ Semi-naive evaluation +- ✅ 123 tests passing ### v0.4.0 - 🎯 Phase 4 (Bi-temporal) - Transaction time @@ -663,13 +668,13 @@ When evaluating features, ask: - ✅ Phase 1: Complete (December 2025) - ✅ Phase 2: Complete (January 2026) -- 🎯 Phase 3: 3-4 months (Datalog core) -- 🎯 Phase 4: 3-4 months (Bi-temporal) +- ✅ Phase 3: Complete (January 2026) - Datalog core with recursive rules +- 🎯 Phase 4: 3-4 months (Bi-temporal) - **NEXT** - 🎯 Phase 5: 2-3 months (ACID + WAL) - 🎯 Phase 6: 2-3 months (Performance) - 🎯 Phase 7: 3-4 months (Cross-platform) - 🎯 Phase 8: Ongoing (Ecosystem) -- 🎯 **v1.0.0: 12-15 months** from now (vs. 24-30 months with GQL) +- 🎯 **v1.0.0: 11-14 months** from now (Phase 3 completed faster than expected!) **Note**: This is a hobby project. Timeline is flexible but realistic. @@ -681,21 +686,30 @@ When evaluating features, ask: ## Current Focus -**Right Now**: Planning Phase 3 - Datalog Core +**Right Now**: ✅ Phase 3 Complete! Planning Phase 4 - Bi-temporal Support + +**Phase 3 Achievements**: +1. ✅ Designed and implemented EAV data model +2. ✅ Implemented Datalog parser (EDN syntax) +3. ✅ Built query executor with pattern matching +4. ✅ Added recursive rules with semi-naive evaluation +5. ✅ Updated REPL for Datalog with multi-line support +6. ✅ Comprehensive test coverage (123 tests) -**Immediate Next Steps**: -1. Design EAV data model -2. Implement Datalog parser (EDN syntax) -3. Build basic query executor -4. Add recursive rules -5. Update REPL for Datalog -6. Migrate tests +**Immediate Next Steps (Phase 4)**: +1. Add transaction time tracking (tx_id, tx_time) +2. Implement :as-of queries +3. Add valid time dimensions (valid_from, valid_to) +4. Implement :valid-at queries +5. Support bi-temporal queries +6. Test time travel and history features **Key Decisions Made**: - ✅ Pivot to Datalog (simpler, better for temporal) - ✅ Bi-temporal as first-class feature (not afterthought) - ✅ Keep single-file philosophy -- ✅ Target 12-15 months to v1.0 +- ✅ Recursive rules with semi-naive evaluation +- ✅ Target 11-14 months to v1.0 (ahead of schedule!) See [GitHub Issues](https://github.com/adityamukho/minigraf/issues) for specific tasks. @@ -726,4 +740,4 @@ We're not competing with GraphLite anymore. We're creating a new category. --- -Last Updated: Phase 2 Complete, Datalog Pivot (January 2026) +Last Updated: Phase 3 Complete - Datalog with Recursive Rules (January 2026)