Skip to content

FerriteDB is a developer-friendly backend service that provides a complete backend-as-a-service solution in a single self-contained binary. Built with Rust for performance, security, and reliability.

License

Notifications You must be signed in to change notification settings

foozio/ferritedb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

FerriteDB

License: MIT Rust

FerriteDB is a developer-friendly backend service that provides a complete backend-as-a-service solution in a single self-contained binary. Built with Rust for performance, security, and reliability.

✨ Features

  • πŸš€ Single Binary Deployment - Everything you need in one executable
  • πŸ“Š Dynamic Collections - Define data schemas without writing SQL
  • πŸ” Built-in Authentication - JWT-based auth with Argon2 password hashing
  • πŸ›‘οΈ Rule-based Access Control - Fine-grained permissions with CEL-like expressions
  • πŸ“‘ Realtime Updates - WebSocket subscriptions for live data
  • πŸ“ File Storage - Local and S3-compatible storage backends
  • 🌐 REST APIs - Automatic API generation for all collections
  • πŸ‘¨β€πŸ’» Admin Interface - Web-based management dashboard
  • πŸ“– API Documentation - Auto-generated OpenAPI specs with Swagger UI
  • πŸ”§ CLI Tools - Complete command-line interface for management

πŸš€ Quick Start

Installation

Homebrew (macOS / Linux)

brew tap ferritedb/tap
brew install ferritedb

Direct Download

Grab the latest release for your platform:

# macOS (Apple Silicon)
curl -L https://github.com/ferritedb/ferritedb/releases/latest/download/ferritedb-macos-arm64 -o ferritedb
chmod +x ferritedb

# macOS (Intel)
curl -L https://github.com/ferritedb/ferritedb/releases/latest/download/ferritedb-macos-x64 -o ferritedb
chmod +x ferritedb

# Linux (x64)
curl -L https://github.com/ferritedb/ferritedb/releases/latest/download/ferritedb-linux-x64 -o ferritedb
chmod +x ferritedb

# Windows
# Download ferritedb-windows-x64.exe from releases page

Build from Source

git clone https://github.com/ferritedb/ferritedb.git
cd ferritedb
cargo build --release

Start the Server

# Initialize example collections and seed data
./ferritedb seed

# Start the server
./ferritedb serve

That's it! FerriteDB is now running on http://localhost:8090

Access Points

Default Credentials

The seed command creates demo users:

πŸ“š Documentation

Creating Collections

Collections are dynamic schemas that define your data structure:

# Using the CLI
ferritedb admin create-collection posts \
  --field title:text:required \
  --field content:text \
  --field published:boolean:default=false \
  --field author_id:relation:users

# Or use the Admin UI at /admin

Access Rules

Define who can access your data with CEL-like expressions:

// List Rule: Anyone can see published posts
"record.published = true || @request.auth.id != ''";

// View Rule: Anyone can view published, owners can view drafts
"record.published = true || record.author_id = @request.auth.id";

// Create Rule: Only authenticated users
"@request.auth.id != ''";

// Update Rule: Only the author or admin
"record.author_id = @request.auth.id || @request.auth.role = 'admin'";

// Delete Rule: Only admins
"@request.auth.role = 'admin'";

REST API Usage

# Login
curl -X POST http://localhost:8090/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]", "password": "password123"}'

# Create a post
curl -X POST http://localhost:8090/api/collections/posts/records \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"title": "Hello World", "content": "My first post!", "published": true}'

# List posts
curl http://localhost:8090/api/collections/posts/records

# Get specific post
curl http://localhost:8090/api/collections/posts/records/POST_ID

# Update post
curl -X PATCH http://localhost:8090/api/collections/posts/records/POST_ID \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"title": "Updated Title"}'

Realtime Subscriptions

const ws = new WebSocket("ws://localhost:8090/realtime");

ws.onopen = () => {
  // Subscribe to posts collection
  ws.send(
    JSON.stringify({
      type: "subscribe",
      collection: "posts",
      filter: "record.published = true",
    })
  );
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log("Realtime update:", data);
};

File Uploads

# Upload file to a record
curl -X POST http://localhost:8090/api/files/posts/POST_ID/featured_image \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "[email protected]"

# Download file
curl http://localhost:8090/api/files/posts/POST_ID/featured_image

πŸ”§ Configuration

FerriteDB can be configured via environment variables, config files, or CLI arguments:

Environment Variables

export FERRITEDB_SERVER_HOST=0.0.0.0
export FERRITEDB_SERVER_PORT=8090
export FERRITEDB_DATABASE_URL=sqlite:data/ferritedb.db
export FERRITEDB_AUTH_JWT_SECRET=your-secret-key
export FERRITEDB_STORAGE_BACKEND=local
export FERRITEDB_STORAGE_LOCAL_BASE_PATH=data/storage

Configuration File

Create ferritedb.toml:

[server]
host = "0.0.0.0"
port = 8090
cors_origins = ["*"]

[server.rate_limit]
requests_per_minute = 60
burst_size = 10

[database]
url = "sqlite:data/ferritedb.db"
max_connections = 10
connection_timeout = 30
auto_migrate = true

[auth]
jwt_secret = "your-secret-key-change-in-production"
token_ttl = 900  # 15 minutes
refresh_ttl = 86400  # 24 hours
password_min_length = 8

[storage]
backend = "local"

[storage.local]
base_path = "data/storage"
max_file_size = 52428800  # 50MB

# Optional S3 configuration
# [storage.s3]
# bucket = "ferritedb-files"
# region = "us-east-1"
# access_key_id = "your-access-key"
# secret_access_key = "your-secret-key"

[features]
multi_tenant = false
full_text_search = false
metrics = false

πŸ› οΈ CLI Commands

Server Management

# Start server
ferritedb serve --host 0.0.0.0 --port 8090

# Database migrations
ferritedb migrate run
ferritedb migrate status

# Initialize examples
ferritedb seed

User Management

# Create admin user
ferritedb admin create --email [email protected]

# List users
ferritedb admin list

# Delete user
ferritedb admin delete [email protected]

Data Management

# Import data
ferritedb import posts data.json
ferritedb import users users.csv

# Export data
ferritedb export posts --output posts_backup.json

# Generate JWT for testing
ferritedb gen-jwt [email protected] --expires 3600

πŸ—οΈ Architecture

FerriteDB is built with a modular architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Admin UI      β”‚    β”‚   REST API      β”‚    β”‚   WebSocket     β”‚
β”‚   (Static)      β”‚    β”‚   (Axum)        β”‚    β”‚   (Realtime)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚              Core Engine                            β”‚
         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
         β”‚  β”‚Collections  β”‚ β”‚    Auth     β”‚ β”‚   Rules     β”‚   β”‚
         β”‚  β”‚   Service   β”‚ β”‚   Service   β”‚ β”‚   Engine    β”‚   β”‚
         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚              Data Layer                             β”‚
         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
         β”‚  β”‚   SQLite    β”‚ β”‚File Storage β”‚ β”‚   Schema    β”‚   β”‚
         β”‚  β”‚  Database   β”‚ β”‚(Local/S3)   β”‚ β”‚  Manager    β”‚   β”‚
         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Components

  • Core Engine: Business logic, collections, authentication, and rules
  • REST API: Axum-based HTTP server with middleware
  • Realtime: WebSocket server for live updates
  • Admin UI: Web-based management interface
  • CLI: Command-line tools for administration
  • Storage: Pluggable file storage (local/S3)
  • Database: SQLite with dynamic schema management

πŸ”’ Security

FerriteDB implements security best practices:

  • Password Hashing: Argon2id with secure parameters
  • JWT Tokens: Short-lived access tokens with refresh rotation
  • Input Validation: Comprehensive validation and sanitization
  • SQL Injection Prevention: Parameterized queries
  • CORS Protection: Configurable cross-origin policies
  • Rate Limiting: Configurable request throttling
  • PII Redaction: Automatic sensitive data masking in logs
  • CSRF Protection: Cross-site request forgery prevention
  • Audit Logging: Complete audit trail for admin actions

πŸš€ Deployment

Docker

FROM ferritedb/ferritedb:latest

# Copy configuration
COPY ferritedb.toml /app/ferritedb.toml

# Expose port
EXPOSE 8090

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD curl -f http://localhost:8090/healthz || exit 1

# Start server
CMD ["ferritedb", "serve"]

Docker Compose

version: "3.8"

services:
  ferritedb:
    image: ferritedb/ferritedb:latest
    ports:
      - "8090:8090"
    volumes:
      - ./data:/app/data
      - ./ferritedb.toml:/app/ferritedb.toml
    environment:
      - FERRITEDB_AUTH_JWT_SECRET=your-production-secret
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8090/healthz"]
      interval: 30s
      timeout: 10s
      retries: 3
    restart: unless-stopped

  # Optional: Reverse proxy
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./ssl:/etc/nginx/ssl
    depends_on:
      - ferritedb
    restart: unless-stopped

Cloud Deployment

Railway

# Install Railway CLI
npm install -g @railway/cli

# Deploy
railway login
railway init
railway up

Fly.io

# Install Fly CLI
curl -L https://fly.io/install.sh | sh

# Deploy
fly launch
fly deploy

DigitalOcean App Platform

name: ferritedb
services:
  - name: api
    source_dir: /
    github:
      repo: your-username/your-ferritedb-fork
      branch: main
    run_command: ferritedb serve
    environment_slug: rust
    instance_count: 1
    instance_size_slug: basic-xxs
    envs:
      - key: FERRITEDB_AUTH_JWT_SECRET
        value: your-production-secret
        type: SECRET
    http_port: 8090
    health_check:
      http_path: /healthz

πŸ§ͺ Development

Prerequisites

  • Rust 1.75+
  • SQLite 3.35+

Setup

# Clone repository
git clone https://github.com/ferritedb/ferritedb.git
cd ferritedb

# Install dependencies
cargo build

# Run tests
cargo test

# Start development server
cargo run -- serve

# Run with debug logging
RUST_LOG=debug cargo run -- serve

Project Structure

ferritedb/
β”œβ”€β”€ crates/
β”‚   β”œβ”€β”€ core/           # Core business logic
β”‚   β”œβ”€β”€ server/         # HTTP server and routes
β”‚   β”œβ”€β”€ storage/        # File storage backends
β”‚   β”œβ”€β”€ rules/          # Rules engine
β”‚   └── sdk-rs/         # Rust client SDK
β”œβ”€β”€ admin/              # Admin UI (static files)
β”œβ”€β”€ migrations/         # Database migrations
β”œβ”€β”€ examples/           # Usage examples
β”œβ”€β”€ docs/               # Documentation
└── src/                # CLI application

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Add tests for new functionality
  5. Run tests: cargo test
  6. Run linting: cargo clippy
  7. Format code: cargo fmt
  8. Commit changes: git commit -m 'Add amazing feature'
  9. Push to branch: git push origin feature/amazing-feature
  10. Open a Pull Request

Development Commands

# Run all tests
just test

# Run with hot reload
just dev

# Lint code
just lint

# Format code
just fmt

# Build release
just build

# Generate documentation
just docs

πŸ“Š Performance

FerriteDB is designed for performance:

  • Memory Usage: ~10MB base memory footprint
  • Startup Time: <100ms cold start
  • Request Latency: <1ms for simple queries
  • Throughput: 10,000+ requests/second on modern hardware
  • Database: SQLite with WAL mode for concurrent reads
  • Caching: In-memory schema and rule caching

Benchmarks

# Run performance tests
cargo bench

# Load testing with wrk
wrk -t12 -c400 -d30s http://localhost:8090/api/collections/posts/records

🀝 Community

πŸ‘₯ Contributors

Maintainer

  • @foozio - Project Creator & Lead Maintainer

Core Contributors

We welcome contributions from the community! Here are the amazing people who have contributed to FerriteDB:

Featured Contributors:

  • @foozio - Core architecture, authentication system, rules engine, and project leadership

See our complete Contributors List for detailed contributions.

How to Contribute

We'd love your help making FerriteDB better! Here's how you can contribute:

  1. πŸ› Report Bugs - Found a bug? Open an issue
  2. πŸ’‘ Suggest Features - Have an idea? Request a feature
  3. πŸ“ Improve Documentation - Help make our docs better
  4. πŸ”§ Submit Code - Fix bugs or implement new features
  5. πŸ§ͺ Write Tests - Help us improve test coverage
  6. 🌍 Translate - Help make FerriteDB accessible worldwide

Recognition

All contributors will be recognized here and in our release notes. We believe in giving credit where credit is due!

Want to see your name here? Check out our Contributing Guide to get started.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ—ΊοΈ Roadmap

  • v1.1: Multi-tenancy support
  • v1.2: Full-text search with FTS5
  • v1.3: GraphQL API support
  • v1.4: Plugin system
  • v1.5: Distributed deployment
  • v2.0: PostgreSQL backend support

Built with ❀️ in Rust

For more information, visit our documentation or join our community.

About

FerriteDB is a developer-friendly backend service that provides a complete backend-as-a-service solution in a single self-contained binary. Built with Rust for performance, security, and reliability.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published