Skip to content

Kevinsillo/anvildb

Repository files navigation

AnvilDB

License: MIT PHP Version Rust Tests

Embedded JSON document database powered by a Rust core, with language wrappers via FFI or subprocess.

Zero external dependencies. No MySQL, PostgreSQL, SQLite, or PDO required. Just your filesystem and raw speed.


Motivation

AnvilDB was born out of a real need: working in environments where you have no installation permissions on the operating system. Without being able to install MySQL, PostgreSQL, or additional extensions, I needed a lightweight database with zero external dependencies that could run on the filesystem alone.

The goal was to have something fast for scaffolding projects and prototyping ideas without friction — an implementation that is often temporary, but needs to work from the very first moment with no configuration or infrastructure. Just copy, use, and move on.

Features

  • Rust-powered core compiled as a native shared library (.so / .dylib / .dll)
  • Joins — INNER and LEFT joins across collections via hash join (O(n+m))
  • Write buffering — batched disk writes with configurable threshold and timer
  • Compression — all data compressed on disk (deflate), transparent to the API
  • Encryption at rest — optional AES-256-GCM, per-file nonce, key as hex string
  • Lazy loading — collections loaded on first access, not at startup
  • In-memory indexes (hash, unique, and range/BTreeMap) for sub-millisecond lookups
  • Aggregations — sum, avg, min, max, count with optional group_by
  • CSV export/import for data portability
  • LRU cache with automatic invalidation on writes
  • Atomic writes via temp file + rename to prevent corruption
  • Schema validation to enforce document structure
  • Bulk operations for efficient batch inserts
  • Cross-platform precompiled binaries (Linux, macOS, Windows / x86_64, aarch64)

Wrappers

The core exposes a C API (anvildb.h) and a JSON-over-pipes protocol (anvildb-server) — any language can integrate via FFI or subprocess.

Language Package Status
PHP anvildb-php Available

Want to create a wrapper for another language? See the Wrapper Development Guide.

Architecture

graph TD
    App[Application] --> Wrapper[Language Wrapper]

    Wrapper -->|FFI · direct| Core[Rust Core Engine]
    Wrapper -->|Subprocess · stdin/stdout| Server[anvildb-server] --> Core

    Core --> FS[("Filesystem (.anvil)")]
Loading

Core internals: Write Buffer · LRU Cache · In-memory Indexes (Hash, Unique, Range) · Query Engine (filter, join, sort, paginate) · Schema Validation · Codec (deflate + AES-256-GCM) · Atomic Storage

Performance

10,000 records | PHP 8.4 | Linux x86_64

Operation Time Throughput
Bulk insert (10x1000) 204ms ~49k docs/s
Read all (10k docs) 22ms ~454k docs/s
Filter query 4.6ms
Filter + sort + limit 3.7ms
Count with filter 0.2ms

With compression, encryption, atomic writes, and schema validation active.

Full benchmark history: BENCHMARKS.md

Project Structure

anvildb/
├── core/                # Rust core engine
│   ├── src/             #   Engine, FFI, storage, query, indexing
│   └── tests/           #   Rust integration tests
├── wrappers/php/        # PHP FFI wrapper
│   ├── src/             #   AnvilDb, Collection, Query, FFI, Exception
│   ├── tests/           #   PHPUnit tests
│   └── docs/            #   PHP-specific documentation
├── docs/                # Core documentation
├── benchmarks/          # Benchmark scripts
└── Cargo.toml           # Workspace root

Documentation

Full documentation at docs/index.md — development, architecture, C API reference, error codes, testing, CI/CD, wrapper development.

Contributing

See CONTRIBUTING.md for guidelines.

Acknowledgments

AnvilDB is built on top of these excellent open-source projects:

Crate Description License
serde / serde_json Serialization framework & JSON support MIT / Apache-2.0
uuid UUID generation (v4) MIT / Apache-2.0
miniz_oxide Pure Rust deflate compression MIT / Apache-2.0
aes-gcm AES-256-GCM authenticated encryption MIT / Apache-2.0
log Logging facade MIT / Apache-2.0
env_logger Log output to stderr (optional, dev only) MIT / Apache-2.0
getrandom OS-level random number generation MIT / Apache-2.0

License

MIT

About

Embedded JSON document database powered by Rust. In-memory indexes, joins, encryption at rest, compression, and a fluent query builder. Zero external dependencies — no MySQL, SQLite, or PDO required.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors