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.
import { backend } from "@layeron/core"import { storage } from "@layeron/modules"
const app = backend()
// 1. Declare an R2-backed blob storage bucketconst mediaBucket = storage.bucket({ name: "avatars", access: "private",})
// 2. Declare a KV-backed low-latency storeconst sessionStore = storage.kv({ name: "sessions", ttlSeconds: 86400, // 24 hours default expiration})
app.use(mediaBucket)app.use(sessionStore)Bucket vs. KV: Choose Your Variant
Section titled “Bucket vs. KV: Choose Your Variant”Layeron provides two storage models tailored for distinct workloads:
| Storage Variant | Underlying Cloudflare Resource | Best Used For |
|---|---|---|
storage.bucket | Cloudflare R2 | Unstructured blobs: User uploads, generated reports, raw logs, images, and files up to 5 TB. Supports temporary upload links. |
storage.kv | Cloudflare KV | Low-latency, read-heavy strings/JSON: Session configurations, feature flags, configuration overrides, and indexing mappings. |
Key Values & Product Features
Section titled “Key Values & Product Features”- 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 withttlSeconds. - 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.
Next Steps
Section titled “Next Steps”- 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.