System Architecture

Overview

FoldDB's architecture uses a modular system that manages data through schema-based validation, atomic operations, and trust-based access control. The system prioritizes data integrity, secure access, and schema transformations with micropayments for data access.

Core Components

1. FoldDB Core

  • Atom Manager: Manages immutable data atoms and metadata
  • Collection Manager: Handles data organization and relationships
  • Field Manager: Processes field-level operations and validations
  • Context Manager: Maintains operational context and state
  • Version Control: Tracks data changes in append-only structure

2. Schema System

  • Schema Manager:
    • Manages schema lifecycle and versioning
    • Coordinates field mapping
    • Tracks schema relationships
    • Ensures thread-safety
  • Schema Interpreter:
    • Parses JSON schema definitions
    • Validates fields and types
    • Processes transformation rules
    • Validates relationships

3. DataFold Node

  • Application Container: Manages system resources and lifecycle
  • Web Server: Provides HTTP API interface
  • Request Handler: Processes incoming operations
  • Error Manager: Handles error recovery and logging
  • Schema Version Manager: Coordinates schema updates

4. Security Architecture

  • Permission Manager:
    • Calculates trust distance
    • Enforces field-level permissions
    • Manages explicit policies
    • Performs thread-safe permission checks
  • Authentication:
    • Uses public key authentication
    • Validates access control
    • Verifies permissions

5. Payment System

  • Payment Manager:
    • Integrates with Lightning Network
    • Prices dynamically based on trust distance
    • Manages hold invoices
    • Verifies payments
  • Payment Calculator:
    • Calculates per-field costs
    • Applies trust-based scaling factors
    • Aggregates operation costs

Data Flow

  1. Authenticate requests using public key
  2. Determine operation type (Query/Mutation/Schema)
  3. Check permissions based on trust distance and policies
  4. Calculate payment requirements if applicable
  5. Apply schema validations and transformations
  6. Execute atomic operation
  7. Format and return response
  8. Handle errors and recovery if needed

Technical Implementation

  • Built in Rust for performance and safety
  • Uses sled embedded database for storage
  • JSON for data and schema representation
  • Lightning Network for micropayments
  • Thread-safe concurrent operations
  • Docker support for containerization

Design Patterns

  • Repository pattern for data access
  • Strategy pattern for permission checks
  • Factory pattern for Atom creation
  • Builder pattern for schema construction
  • Interpreter pattern for schema definitions
  • Command pattern for database operations
  • Immutable data structures
  • Thread-safe concurrency patterns