Skip to content

Suitcase

Database- and storage-agnostic user-generated content for TypeScript.

Suitcase is a standalone, database- and storage-agnostic solution for user-generated content. It gives an application one definition of what it stores, one upload flow, and one authorization model, while leaving the UI, the database, and the storage provider to you.

The architecture comes from stratforge.gg, where it served thousands of users monthly.

suitcase/definition.ts
// Example only. These declarations live inside withResources().
const companyOwner = owner({
schema: z.object({ companyId: z.string() }),
authorize: async ({ execution, owner }) => {
return isMemberOfCompany(execution.userId, owner.companyId);
},
});
const companyInvoice = resource("companyInvoice", {
bucket: "invoices",
owner: companyOwner,
read: read({
claim: z.object({ companyId: z.string() }),
verify: async ({ claim, execution }) => {
if (!(await isMemberOfCompany(execution.userId, claim.companyId))) {
throw ServiceError.forbidden("Not your company");
}
return claim;
},
expose: ({ requested, scope }) =>
requested.filter(({ owner }) => owner.companyId === scope.companyId),
}),
upload: companyOwner.upload({
mimeTypes: ["application/pdf"],
maxSize: "10 MB",
intent: z.object({ companyId: z.string(), folderId: z.string() }),
ownedBy: ({ claims }) => ({ companyId: claims.intent.companyId }),
}),
});
  • Resources are not assets. A resource is the logical row a user owns. An asset is the physical object. Several resources can share one asset, and the bytes are stored once.
  • Bytes skip your API. Uploads go straight to a presigned target. The operation endpoints carry only small JSON documents, never file bodies.
  • Authorization is part of the definition. Owners decide mutations and usage. Reads decide what a caller may be handed.
  • The edges are replaceable. Repositories, buckets, and job queues are ports. Use Drizzle and S3 today, or write your own adapter without touching the services.
  1. The client reads the kind’s limits with uploads.constraints.
  2. It claims the file with uploads.initialize and receives a presigned target.
  3. The bytes go straight to storage. No file passes through your API.
  4. uploads.finalize verifies the claims, reuses or promotes the asset, and creates the resource.
  5. resources.resolve turns ids into signed download URLs.

The client never sends an owner. The server derives it from the execution context, records it on the upload session, and checks the same owner authorizer for uploads, updates, deletes, and usage.

  • It does not render a file picker, a grid, or an upload button. @softzweig/suitcase-react provides hooks, not components.
  • It has no list operation. Query your own resource tables, then resolve the ids you found.
  • It does not authenticate users. forExecution receives the context your app already trusts.
  • It does not enforce quotas. Usage is reported, and upload.accept is where a policy belongs.
  • It does not retry uploads or store jobs durably by default. The bundled queues are deliberately simple.