FYLO on npm — @d31ma/fylo

Filesystem-first documents for Bun.

One canonical file per document version, prefix indexes for fast queries, schema-aware validation and versioning, field-level encryption with blind indexes, file-based RLS authorization, WORM append-only mode, and sync hooks when you want to replicate the root elsewhere.

bun add @d31ma/fylo
Read the docs
Canonical document files Prefix indexes RLS authorization Realtime listeners
1
Bun-native engine
6
Query operators
2
Index backends
WORM
Append-only mode
SQL API

Query documents
with familiar SQL.

FYLO parses a SQL dialect into collection operations so you can create, read, update, delete, and join document data without bringing in a separate database server.

  • SELECT, INSERT, UPDATE, DELETE, CREATE, DROP
  • WHERE conditions with $eq, $ne, $gt, $lt, $gte, $lte, $like
  • INNER, LEFT, RIGHT, OUTER cross-collection JOINs
  • GROUP BY, LIMIT, and result shaping helpers
app.ts
import Fylo from "@d31ma/fylo"

const fylo = new Fylo({ root: "/mnt/fylo" })

// Create a collection
await fylo.executeSQL("CREATE TABLE users")

// Insert a document
await fylo.executeSQL(
  'INSERT INTO users VALUES { "name": "Alice", "age": 28 }'
)

// Query with conditions
const results = await fylo.executeSQL(
  'SELECT * FROM users WHERE age > 18 LIMIT 10'
)

// Cross-collection join
const joined = await fylo.joinDocs({
  $leftCollection: "posts",
  $rightCollection: "users",
  $mode: "inner",
  $on: { userId: { $eq: "id" } }
})
Everything you need

Built for Bun.

A single Bun-native storage engine with schema versioning, field-level encryption, file-based RLS, WORM append-only mode, and sync hooks.

Canonical Documents

Every document version is its own JSON file under a predictable path. Inspect, debug, and rebuild from the filesystem directly.

Prefix Indexes

Zero-payload prefix indexes with local WAL+snapshot or S3 backends accelerate queries without storing document data in the index.

Realtime Listeners

Async iterators stream live changes from an append-only filesystem event journal, so document and query subscriptions stay reactive.

SQL + NoSQL APIs

Use collection methods like putData() and findDocs(), or run SQL-like commands through executeSQL().

Sync Hooks

FYLO leaves cloud replication to your app and gives you onWrite and onDelete hooks with await-sync and fire-and-forget modes.

Validation, Auth + Encryption

CHEX schema validation, per-collection versioning with upgraders, file-based RLS authorization, and field-level AES-256-GCM encryption with HMAC blind indexes — all in one Bun-native package.

Sync Hooks

Keep FYLO local.
Sync on your terms.

The current package writes to a local or mounted filesystem root and lets your application decide how that root gets mirrored to S3-compatible storage. Use sync hooks when you want replication behavior without handing over source-of-truth ownership.

  • Configure the root with root or FYLO_ROOT
  • Pick await-sync or fire-and-forget for replication timing
  • Upload the written file from event.path inside onWrite
  • Handle delete replication with a matching onDelete hook
sync.ts
import Fylo from "@d31ma/fylo"

const fylo = new Fylo({
  root: "/mnt/fylo",
  syncMode: "await-sync",
  sync: {
    async onWrite(event) {
      const file = Bun.file(event.path)
      await myS3Client.putObject({
        key: event.collection + "/" + event.docId + ".json",
        body: await file.arrayBuffer()
      })
    },
    async onDelete(event) {
      await myS3Client.deleteObject({
        key: event.collection + "/" + event.docId + ".json"
      })
    }
  }
})

await fylo.createCollection("users")
await fylo.putData("users", {
  name: "Ada",
  role: "admin"
})
Configuration

Zero config by default.
Everything configurable via env.

Drop a .env file in your project root. FYLO now prefers a single filesystem root with optional validation, encryption, and logging controls.

FYLO_ROOT
Filesystem root for FYLO collections. Defaults to <cwd>/.fylo-data when unset.
FYLO_SCHEMA_DIR
Directory containing per-collection JSON schemas, version manifests, and upgrader modules.
FYLO_STRICT
Set to any truthy value to validate documents against the head CHEX schema before every write.
FYLO_ENCRYPTION_KEY
Minimum 32 characters. Required when any schema declares $encrypted fields. Used for AES-256-GCM field encryption.
FYLO_CIPHER_SALT
Unique random salt per deployment for PBKDF2 key derivation. Prevents cross-instance precomputation.
FYLO_LOGGING
Enable console logging of document writes and internal operations for debugging.

Start with a local root.
Replicate when you need to.

FYLO keeps the source of truth on the filesystem and lets your app decide how that root gets synced anywhere else.