Clover is a cloud file storage and management web application. It is basically a lightweight clone of Google Drive. The site is hosted on Vercel with Next.js, while a separate Cloudflare Worker backend owns Cloudflare D1 auth/file metadata and Cloudflare R2 private file objects. You can upload files, preview them, and share them with other users in your instance of the application.
- Email OTP sign-in and sign-up with hashed sessions
- Optional Cloudflare Turnstile protection for auth flows
- Private file storage in Cloudflare R2
- D1-backed file metadata, sharing records, sessions, and rate limits
- File upload, preview, download, rename, share, and delete flows
- Dashboard with storage usage and recent files
- Operations scripts for D1 backup and stale upload cleanup
- Frontend: Next.js App Router, React, TypeScript, Tailwind CSS
- UI: Radix primitives, local shadcn/ui-style components, Phosphor Icons
- Backend: Cloudflare Workers, D1, R2
- Auth/email: Email OTP, Resend, optional Cloudflare Turnstile
- Deployment: Vercel for the Next.js app, Cloudflare for the Worker backend
Clover uses a split deployment:
- The Next.js app handles the UI, server actions, cookies, and user-facing API routes.
- The Cloudflare Worker owns auth verification, D1 queries, R2 object access, upload validation, and file authorization.
- The R2 bucket is private. File view and download requests are proxied through authenticated routes that check ownership or sharing access before streaming the object.
Uploads currently use a server-mediated direct upload route:
- The browser asks the Next.js app for an upload intent.
- The Worker reserves a pending file row in D1.
- The browser uploads to a Next.js route.
- The Next.js route forwards the file to the Worker.
- The Worker writes the object to R2 and activates the file after validating size and ownership.
This keeps R2 private and simple to operate, but it is not a presigned browser-to-R2 upload flow. The app intentionally caps files at 50 MB. For larger files or heavier usage, the next step would be presigned/direct R2 uploads with the same completion validation.
- Node.js 22+ and npm. This repo includes
.nvmrcfor Node 22.16.0. - A Cloudflare account with Workers, D1, and R2 enabled.
- A Resend account and verified sender for production OTP email.
Install dependencies:
npm installCreate the Cloudflare resources:
npx wrangler d1 create clover-db
npx wrangler r2 bucket create clover-files
npx wrangler r2 bucket create clover-backupsCopy and edit the local config files:
cp .env.example .env.local
cp wrangler.example.jsonc wrangler.jsoncUpdate wrangler.jsonc with the generated D1 database_id. Use the same long random CLOVER_BACKEND_SECRET in .env.local and the Worker secret.
Configure Worker secrets:
npx wrangler secret put CLOVER_BACKEND_SECRET
npx wrangler secret put AUTH_HASH_PEPPER
npx wrangler secret put RESEND_API_KEY
npx wrangler secret put RESEND_FROM_EMAILApply D1 migrations:
npm run db:migrations:apply
npm run db:migrations:apply:remoteRun the backend and frontend in separate terminals:
npm run backend:dev
npm run devOpen http://localhost:3000.
Frontend/Vercel variables:
AUTH_COOKIE_NAMECLOVER_BACKEND_URLCLOVER_BACKEND_SECRETNEXT_PUBLIC_TURNSTILE_SITE_KEYif Turnstile is enabled
Worker secrets:
CLOVER_BACKEND_SECRETAUTH_HASH_PEPPERRESEND_API_KEYRESEND_FROM_EMAILTURNSTILE_SECRET_KEYif Turnstile is enabled
Worker vars:
TURNSTILE_ENABLEDAUTH_DEBUG_OTP_LOGGINGfor local-only OTP debugging without Resend
Cloudflare API credentials such as CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID, and CLOUDFLARE_DATABASE_ID are only for Wrangler, Drizzle Kit, and operations scripts. Keep them in your shell or CI secrets, not in source or Vercel runtime variables.
npm run dev # Start the Next.js app
npm run backend:dev # Start the Cloudflare Worker locally
npm run lint # Run ESLint
npm run build # Build the Next.js app
npm run backend:deploy # Deploy the Worker
npm run db:migrations:apply # Apply local D1 migrations
npm run db:migrations:apply:remote # Apply remote D1 migrations
npm run backup:d1 # Export remote D1 and upload to backup R2
npm run cleanup:uploads # Remove stale pending uploadsDeploy the frontend to Vercel and the backend to Cloudflare Workers:
npm run db:migrations:apply:remote
npm run build
npm run backend:deploySet Vercel environment variables before deploying the frontend, then point CLOVER_BACKEND_URL at the deployed Worker URL.
Clover is released under the MIT License.
This project was originally based on the JavaScript Mastery storage management tutorial and has since been adapted with a custom Cloudflare Workers/D1/R2 backend, OTP auth, private object access, and deployment/operations tooling.
