Skip to content
codelitdevPublic

About

Effortless file uploads, optimization and delivery via any AWS S3 compatible storage

Topics

Resources

Stars

21 stars

Watchers

1 watching

Forks

Repository files navigation

MediaLit logo

MediaLit

Storage for agents, apps and humans.

Upload, store, optimize and stream files on any S3-compatible storage, through a REST API,
a drop-in React uploader and video player, an MCP server, a CLI and a dashboard.

npm License: AGPL-3.0 Discord Integration tests Code quality

Website · Docs · Quick start · Self-hosting


Why MediaLit

Object storage only stores bytes. To use it for uploads in a real app you also need presigned URLs, bucket policies, CORS, thumbnails, video encoding, a database of what you stored, and a way to clean up files nobody uses. MediaLit is that layer, and it gives apps, AI agents and people one place to work on the same files.

  • Uploads straight from the browser. Your server hands out a short-lived signature, so your API key never reaches the browser. Large files upload in resumable chunks.
  • No orphaned files. Uploads stay temporary until you seal them, and MediaLit deletes the ones nobody keeps.
  • Built for agents. Claude, ChatGPT, Cursor and any MCP client can save and share files over OAuth. Coding agents can run the CLI.
  • Images and videos ready for the web. Images and videos get thumbnails when they're uploaded, and a sealed video gets a poster picked from the video, skipping dark frames. Each app can convert images to WebP, and turn videos into an MP4 optimized for the web or HLS streams that adapt to the viewer's connection.
  • Know when a file is ready. Media reports its processing status and metadata such as duration, dimensions and codecs, and signed webhooks tell your server when processing finishes or fails.
  • Public and private files, with signed links for private videos and streams, and quotas.
  • Open source and portable. Everything that runs medialit.cloud is in this repository. Self-host it on AWS S3, Cloudflare R2, MinIO or any S3-compatible storage, with the same API.

MediaLit is the file backend for CourseLit and more.

Quick start

Upload a file from your terminal:

npm install -g @medialit/cli
medialit login
medialit upload photo.jpg --public

Add an uploader to a React app:

import { MediaLitUploader } from "@medialit/react";
import "@medialit/react/styles.css";

<MediaLitUploader
    signatureEndpoint="/api/medialit/signature"
    onUploadComplete={(media) => console.log(media.file)}
/>;
// app/api/medialit/signature/route.ts
import { createSignatureHandler } from "medialit";

export const POST = createSignatureHandler({
    authorize: async () => !!(await getSession()), // your app's auth
});

Play a video with the best version MediaLit made of it, HLS, web MP4 or the original:

import { MediaLitVideo } from "@medialit/react";

// `media` comes from your server: medialit.get(mediaId) with the Node.js SDK.
<MediaLitVideo media={media} width={640} />;

Connect an AI agent: add https://api.medialit.cloud/mcp as a remote MCP server in your client and sign in.

See the docs for the full guides, the REST API and self-hosting.

How it works

The pieces

The API owns all product behavior. Every client, including the dashboard, goes through it. The worker runs the slow work in the background: it picks up jobs the API queues in PostgreSQL, so uploads and seals return quickly.

flowchart TB
    subgraph clients["Clients"]
        browser["Your web app<br/>@medialit/react"]
        server["Your server<br/>medialit SDK"]
        agent["AI agents<br/>MCP"]
        cli["medialit CLI"]
        web["Dashboard<br/>apps/web"]
    end

    api["API<br/>apps/api"]
    db[("PostgreSQL<br/>media, settings, job queue")]
    worker["Worker<br/>apps/api"]

    subgraph storage["S3-compatible storage"]
        private[("Private bucket")]
        public[("Public bucket / CDN")]
    end

    hook["Your webhook endpoint"]

    browser & server & agent & cli & web --> api
    api -- "media records, queued jobs" --> db
    api -- "uploads, thumbnails, WebP" --> private
    db -- "new jobs" --> worker
    worker -- "posters, MP4, HLS" --> private
    worker -- "publishes public files" --> public
    worker -- "signed webhooks" --> hook
Loading

Browsers and players load public files straight from the public bucket or your CDN, and private files through short-lived signed links.

Uploading a file

sequenceDiagram
    autonumber
    participant B as Browser<br/>(MediaLitUploader)
    participant S as Your server<br/>(medialit SDK)
    participant A as MediaLit API
    participant Q as PostgreSQL<br/>(job queue)
    participant W as Worker
    participant St as Storage

    B->>S: Ask for an upload signature
    S->>A: Create a signature (API key)
    A-->>S: Short-lived signature
    S-->>B: Signature
    B->>A: Upload the file with the signature<br/>(form data, or resumable chunks)
    A->>St: Stream the file to the private bucket
    A->>St: Save a thumbnail
    A-->>B: mediaId, temporary
    B->>S: Here is the mediaId
    S->>A: Seal mediaId (API key)
    A->>A: Read metadata, convert to WebP if the app asks
    A->>Q: Queue jobs: publish, video poster, MP4 or HLS
    A-->>S: Media, processing
    Q-->>W: New jobs
    W->>St: Make posters and video, publish public files
    W->>Q: Mark the media ready
    W->>S: Webhook: media.processing.ready
    S->>A: Get media
    A-->>S: Media with URLs for each derivative
    S-->>B: Media
    Note over B: Show it with MediaLitVideo<br/>or an img tag
Loading

Packages

Package Description Version
medialit Node.js SDK npm
@medialit/react MediaLitUploader, useMediaLitUpload and MediaLitVideo npm
@medialit/uploader Resumable uploads from the browser or Node.js npm
@medialit/cli The medialit command npm
@medialit/integration-tests Integration tests and a production synthetic check npm

The repository also contains the API and its worker (apps/api) and the dashboard (apps/web). The docs live in frontlit/docs and publish to medialit.cloud/docs through FrontLit.

Self-hosting

MediaLit needs PostgreSQL, two S3-compatible buckets (one private and one public), and the worker next to the API. The self-hosting guide covers AWS S3 with CloudFront, Cloudflare R2 and MinIO, along with upload limits and monitoring.

To stream video, give the worker room to encode and let browsers read video segments from your storage with a CORS rule.

MediaLit streams uploads into the private bucket as S3 multipart uploads, so the bucket needs a lifecycle rule that aborts incomplete multipart uploads. The guide shows how to set it up.

Upgrading? Follow the guide for each version you pass:

Development

Requirements: Bun 1.4.4, Docker, ffmpeg for thumbnails, posters and video encoding, and webp for image conversion. We develop on Linux; on Windows, use WSL.

sudo apt install ffmpeg webp
bun install

# Postgres, MinIO and Mailpit. The API and dashboard run on your machine.
docker compose -f docker-compose.local.yml up -d

# Configure the API (set EMAIL to your address) and create its tables.
cp apps/api/.env.example apps/api/.env
bun --filter @medialit/api db:migrate

bun --filter @medialit/api dev          # API on http://localhost:8000
bun --filter @medialit/api dev:worker   # Worker: background jobs
bun --filter @medialit/web dev          # Dashboard on http://localhost:3000

Without the worker, sealed files don't get their posters, MP4 or HLS, public files aren't published, and webhooks aren't sent. On its first start, the API creates a user for EMAIL and a default app. Sign in to the dashboard with EMAIL; the code arrives in Mailpit at http://127.0.0.1:8025. Create an API key in the app's settings, or set MEDIALIT_BOOTSTRAP_API_KEY in apps/api/.env to have the API create one at startup. The MinIO console is at http://127.0.0.1:9001 (medialit / medialit-secret).

If you run the dashboard on another port, set WEB_ORIGIN in apps/api/.env to match, or sign-in redirects fail.

Tests

bun run test                    # Unit tests
bun run test:integration:stack  # REST, WebP, video, MCP and CLI suites against a fresh stack

test:integration:stack is the check every pull request must pass. It starts its own Postgres, MinIO, Mailpit, API and worker on separate ports, so it doesn't touch your dev stack. To run the suites against an API that's already running:

MEDIALIT_APIKEY=... MEDIALIT_SERVER=localhost:8000 bun run test:integration

Contributing

Contributions are welcome. For anything larger than a small fix, please open an issue first so we can agree on the approach.

  1. Fork the repository and create a branch.
  2. Make your change, with tests. If you change a published package, add a changeset with bunx changeset.
  3. Run bun run lint, bun run prettier and bun run test, and bun run test:integration:stack for API, MCP or CLI changes.
  4. Open a pull request. The integration tests run on every pull request and must pass.

Questions are welcome on Discord or in GitHub issues.

Security

Please don't report security issues in public issues. Report them privately through GitHub's security advisories.

Licensing

MediaLit is split into two licenses:

  • AGPL-3.0-or-later covers the server (apps/api), the dashboard (apps/web) and internal tooling. If you run a modified MediaLit as a hosted service, you must share your changes under the same license. Self-hosting is free.
  • MIT covers the client packages you embed in your own products: medialit, @medialit/react, @medialit/uploader, and @medialit/cli. Each published MIT package ships its own LICENSE file.

The AGPL license text is in LICENSE.md.

About

Effortless file uploads, optimization and delivery via any AWS S3 compatible storage

Topics

Resources

Stars

21 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages