Skip to content

Overview

Layeron Storage (storage) gives your backend application a unified interface for storing durable unstructured files (like images, logs, or PDFs) and fast, low-latency key-value pairs (like user sessions, configurations, or tokens).

Rather than forcing you into paying hosted SaaS markups, Layeron Storage compiles directly into native Cloudflare R2 and Cloudflare KV resources inside your own Cloudflare account, keeping your storage costs at base infrastructure rates.

Terminal window
import { backend } from "@layeron/core"
import { storage } from "@layeron/modules"
const app = backend()
// 1. Declare an R2-backed blob storage bucket
const mediaBucket = storage.bucket({
name: "avatars",
access: "private",
})
// 2. Declare a KV-backed low-latency store
const sessionStore = storage.kv({
name: "sessions",
ttlSeconds: 86400, // 24 hours default expiration
})
app.use(mediaBucket)
app.use(sessionStore)

Layeron provides two storage models tailored for distinct workloads:

Storage VariantUnderlying Cloudflare ResourceBest Used For
storage.bucketCloudflare R2Unstructured blobs: User uploads, generated reports, raw logs, images, and files up to 5 TB. Supports temporary upload links.
storage.kvCloudflare KVLow-latency, read-heavy strings/JSON: Session configurations, feature flags, configuration overrides, and indexing mappings.

  • Decoupled Architecture: Each Storage instance creates a dedicated Storage Product Worker that processes read/write operations via type-safe Product RPC, isolating heavy I/O workloads from your API’s primary thread.
  • Base Infrastructure Pricing: All files and KV values live in your Cloudflare account, ensuring you pay only base Cloudflare R2/KV pricing with zero markups.
  • Zero-Knowledge Encryption: Pass a Secret reference to automatically encrypt data (using AES-GCM-256) on the product worker boundary before it is written to disk, preventing plaintext visibility inside Cloudflare.
  • Native Lifecycles & TTLs: Configure R2 object deletion with deleteAfterDays, or set KV key expirations with ttlSeconds.
  • Pre-signed Access Links: Programmatically generate short-lived upload/download URLs, including one-time URLs and custom signed URL hosts for private bucket access.
  • Product Archive Backend: Layeron products such as Log can use generated Storage bucket instances for retained archives, keeping R2 ownership, lifecycle, encryption, and future catalog work in one product.
  • Get started: Declare a bucket and KV namespace, upload files, read objects, and store JSON values.
  • Guarantees and limits: Understand R2 consistency, KV propagation, object sizes, lifecycles, encryption, signed URLs, and custom hosts.
  • Examples: Adapt pre-signed uploads, encrypted vaults, session storage, and paginated listing patterns.
  • API reference: Review bucket, KV, encryption, lifecycle, signed URL, and read handle contracts.