Filelayer

Open-source Node library · Apache-2.0 · alpha

The file layer for SaaS applications.

Per-file permissions, links you can take back, and a record of every allowed and denied access, for the files your users upload. A library in your own process, on your own Postgres and the S3 or R2 bucket you already own.

Keep your storage. You are adding a dependency, not a vendor.

npm install @filelayer/core

Alpha. Developer preview. v0.37.1. The schema can still change in any 0.x release. Every number behind that word →

What your agent would write by hand

Without Filelayer, the same feature took about 2.9 times as much code and left about 3.1 times as many security-sensitive decisions to whoever maintains it.

  • Lines of application and infrastructure code, wired as in productionabout 2.9 times as many
  • Kinds of security-sensitive decision left to whoever maintains the codeabout 3.1 times as many

Ask a coding agent for private uploads, sharing you can take back and an access log, and it writes them into your application. We built one such workspace five times: once with Filelayer, and four times by agents following each platform's own documentation. Two of the four, raw S3 and Supabase, run here. They took 794 and 569 lines against Filelayer's 233, and 24 and 25 kinds of security-sensitive decision against its 8: places where a wrong choice leaks data and nothing reports it. The method, all five builds, the attacks, and where each alternative is better →

In production, on your Postgres and your bucket

import pg from 'pg';
import { Filelayer, S3Storage } from '@filelayer/core';

const fl = new Filelayer(new pg.Pool({ connectionString: process.env.DATABASE_URL }), new S3Storage({
  endpoint: process.env.S3_ENDPOINT!, bucket: 'files', region: 'auto',
  accessKeyId: process.env.S3_ACCESS_KEY_ID!, secretAccessKey: process.env.S3_SECRET_ACCESS_KEY! }));

const { id } = await fl.files.put(bytes, { org: 'acme', owner: 'alice' });
const file = await fl.files.get(id, { as: 'alice' });
Compiled against the library by a check in CI. Apply schema.sql once and keep the bucket private: Quickstart §7 → To try it with nothing to set up, Filelayer.quickstart() runs Postgres in process.

One file model, from simple to complex

A public avatar and a board deck under legal hold are the same row, authorized by the same function, on the same table. There is no second code path for the simple case, and no migration when the simple case grows up.

// A public avatar
const { url } = await fl.files.put(bytes, { public: true });

// The same file, now owned by someone
const { id } = await fl.files.put(bytes, { owner: 'user_123' });
const file  = await fl.files.get(id, { as: 'user_123' });

// The same file, now inside a tenant with roles
await fl.files.put(bytes, { org: 'acme', owner: 'user_123' });

// The same file, now shared, with an expiry, a cap, and revocable
const share = await fl.shares.create(id, {
  as: 'user_123', expiresIn: 3600, maxDownloads: 3, password: 'hunter2',
});
await fl.shares.revoke(share.grantId, { as: 'user_123' });   // this link, now

// For a named person, unshare: create() is not idempotent, so one grant id
// is not necessarily all of their access.
await fl.shares.unshare(id, { as: 'user_123', user: 'user_456' });
Verbatim from the README, where every sample is compiled and executed in CI. Promoting a file from tier 1 to tier 4 is adding an option to a call, not a migration.

How it fits

You tell Filelayer who the caller is. It decides what they may do, serves the bytes with the right headers, and writes the audit event.

Your bucket keeps the bytes. Your Postgres keeps the metadata, the grants and the audit chain. Filelayer owns neither. It owns the model between them. Nothing moves, and nothing about your storage bill changes.

Node ≥ 22 and a Postgres you already run. The package installs zero runtime dependencies.

It is authorization middleware, not row-level security: a client that queries your Postgres directly bypasses it. Where that boundary is, exactly →

Readable by machines, not just by people

Every one of these ships inside the npm tarball.

  • llms.txt: the integration map, ordered by what an implementer has to get right first.
  • An MCP server: filelayer-mcp, a stdio server you run yourself. One process acts for one user, fixed at start. Nothing is hosted.
  • The Agent Skill, for the agent writing the integration, and a CLI (filelayer doctor, schema status, usage-report) for checking a deployment.
  • errors.json, every error code with what it means and what to do, and OpenAPI 3.1 for the two HTTP routes it serves.
  • The tests: 861 across 170 suites travel with the package, so you can run them against what you installed.

Using a coding agent? Point it at the map:

Add Filelayer to my app: https://github.com/filelayer/filelayer/blob/main/llms.txt

The state of it, in numbers

Every figure below is produced by a job you can read, on every commit, and is reproducible from the repository. The full set, including what this project has not earned yet, is on the trust page, which is where we keep the numbers that do not flatter us.

  • Version0.37.1, alpha
  • Storage adapter against live Cloudflare R212 tests, every commit
  • Storage adapter against live AWS S312 tests, every commit
  • Tests (most on PGlite; concurrency, audit retention and the MCP server on a real PostgreSQL 17), every commit861 across 170 suites
  • Concurrency, against a real PostgreSQL8 tests, every commit
  • Adversarial suite26 attacks, 0 breaches
  • Runtime dependencies0
  • LicenceApache-2.0, with a patent grant

The core library is and will remain Apache-2.0. Who maintains it, and what happens if he stops →

The library is free and complete under Apache-2.0, with no limit on files, users or applications. The paid plans are support and reviews. Pricing →

Production deployments, maintainers, independent review and the rest of the set: the trust page →

The one precondition: Filelayer cannot make your bucket private. Keys are not secrets, so a public bucket bypasses everything above it.

The full trust page →  ·  Security policy →  ·  Where we are the wrong tool →

Give your files a model

A file you actually own, in a process you actually run.

npm install @filelayer/core