Skip to content

BrowserDB is a high-performance, embedded database designed specifically for browser environments. It provides efficient data storage and retrieval capabilities with support for hierarchical file organization, LSM trees, and various indexing mechanisms.

License

Notifications You must be signed in to change notification settings

Intro0siddiqui/Browser-db

Repository files navigation

BrowserDB πŸš€

Lightning-fast, privacy-first database for modern browsers, now in Pure Rust!

BrowserDB is a high-performance, browser-native database designed as a modern alternative to IndexedDB. Built with a LSM-tree hybrid architecture and intelligent HeatMap indexing, it delivers sub-millisecond queries with 95% cache hit rates.

Build Status Performance Memory Usage License

⚑ Quick Start

Get up and running in 2 minutes:

# 1. Clone the repository
git clone https://github.com/browserdb/browserdb.git
cd browserdb/bindings

# 2. Build and run the example
cargo run --release --example basic_usage

🎯 First database operation:

use browserdb::{BrowserDB, HistoryEntry};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Open/create database
    let db = BrowserDB::open("my_app.bdb")?;
    
    // Store some data
    db.history().insert(&HistoryEntry {
        timestamp: 1234567890,
        url_hash: 123,
        title: "My First Page".to_string(),
        visit_count: 1
    })?;
    
    // Retrieve data
    let entry = db.history().get(123)?;
    println!("Entry: {:?}", entry);
    
    Ok(())
}

🎯 Why BrowserDB?

Feature BrowserDB (Rust) IndexedDB SQLite
Read Performance 890K+ ops/sec 10K ops/sec 50K ops/sec
Write Performance 700K+ ops/sec 1K ops/sec 10K ops/sec
Memory Efficiency <50MB 100MB+ 80MB+
Cache Hit Rate 95% 70% 85%
Query Latency <0.1ms 10ms 2ms

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Application   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Pure Rust     β”‚    β”‚   HeatMap       β”‚
β”‚     Engine      │◄──►│    Index        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LSM-Tree       β”‚
β”‚   Storage       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   .bdb Files    β”‚
β”‚   (Persistent)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components

  • πŸ”₯ HeatMap Indexing: Intelligent caching with 95% hit rates
  • ⚑ LSM-Tree Storage: Optimized BTreeMap-based MemTable and SSTables
  • πŸ—‚οΈ .bdb Format: Universal browser database format
  • πŸ”„ Mode Operations: Persistent vs Ultra (in-memory) modes
  • πŸ›‘οΈ Data Integrity: CRC32 validation and corruption recovery

πŸš€ Key Features

Performance

  • 890K+ reads/second - Sub-millisecond query response
  • 700K+ writes/second - High-throughput data ingestion
  • 95% cache hit rate - Intelligent HeatMap optimization
  • <50MB memory footprint - Efficient resource usage

Reliability

  • Atomic operations - ACID compliance for data integrity
  • Corruption recovery - Automatic detection and repair
  • Multi-mode support - Persistent and Ultra (RAM) modes
  • Zero Dependencies - Pure Rust implementation

🧩 Modular SQL Subsystem

BrowserDB now features a Modular SQL Engine. Adhering to the Unix Philosophy ("Do one thing and do it well"), the core remains a lightning-fast KV store, while SQL is an optional layer on top.

use browserdb::BrowserDB;

// 1. Open the raw, fast core
let db = BrowserDB::open("my.db")?;

// 2. Enable SQL Layer
let sql = std::sync::Arc::new(db).sql();

// 3. Execute SQL
sql.execute("CREATE TABLE users (id INT PRIMARY_KEY, name TEXT)")?;
sql.execute("INSERT INTO users VALUES (1, 'Alice')")?;
let result = sql.execute("SELECT * FROM users WHERE id = 1")?;

This architecture allows you to mix Raw Performance (700k+ ops/sec) with Structured Queries in the same application.

πŸƒβ€β™‚οΈ Performance Benchmarks

# Run performance stress test
cd bindings
cargo run --release --example stress_test

# Recent Results (Typical on modern hardware):
# Write Throughput:     714,529 ops/sec
# Read Throughput:      896,192 ops/sec
# Persistence:          Verified

πŸ“ Project Structure

browserdb/
β”œβ”€β”€ πŸ“„ README.md              # This file
β”œβ”€β”€ πŸ“ bindings/              # πŸ¦€ Main Rust Crate
β”‚   β”œβ”€β”€ src/                 
β”‚   β”‚   β”œβ”€β”€ core/            # Core Database Logic
β”‚   β”‚   β”‚   β”œβ”€β”€ lsm_tree.rs  # Storage engine
β”‚   β”‚   β”‚   β”œβ”€β”€ format.rs    # File format
β”‚   β”‚   β”‚   β”œβ”€β”€ heatmap.rs   # Indexing & Bloom Filters
β”‚   β”‚   β”‚   └── modes.rs     # Mode management
β”‚   β”‚   └── lib.rs           # Public API
β”‚   β”œβ”€β”€ examples/            # πŸ’‘ Usage examples
β”‚   └── Cargo.toml           # Rust configuration
β”œβ”€β”€ πŸ“ scripts/               # πŸ› οΈ Utility scripts
└── πŸ“ docs/                  # πŸ“š Documentation

🎯 Use Cases

Browser Applications

  • History Management: Fast search through browsing history
  • Bookmark Storage: Efficient CRUD operations for bookmarks
  • Session Recovery: Quick session restoration
  • Resource Caching: High-performance cache layer

Web Applications

  • Offline Support: Robust local data persistence
  • Real-time Apps: High-throughput event storage
  • Analytics: Efficient data collection and querying
  • Content Management: Fast content indexing and retrieval

πŸ› οΈ Development

Prerequisites

  • Rust 1.75+

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“Š Database File Types

File Purpose Typical Size Access Pattern
history.bdb Browsing trails 10-50MB High read/search
cookies.bdb Session data 5-20MB Frequent read/write
cache.bdb Resource cache 100-500MB Burst reads
localstore.bdb Per-origin KV 1-10MB Write-heavy
settings.bdb Configuration <1MB Rare writes

πŸ”’ Security & Privacy

  • Local-first: All data stays on the user's device
  • No tracking: Zero telemetry or analytics collection
  • Privacy by design: Minimal data exposure
  • Open source: Auditable codebase

πŸ“„ License

BSD-3-Clause - Open standard for universal browser adoption

🀝 Community


πŸš€ Get Started Now | πŸ“š Read Docs

Built with ❀️ for the modern web

About

BrowserDB is a high-performance, embedded database designed specifically for browser environments. It provides efficient data storage and retrieval capabilities with support for hierarchical file organization, LSM trees, and various indexing mechanisms.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •