Appearance

Visual style

Mode
Theme
Accent
Advanced
Text sizeScales the whole site
16 px
Reduce motionReduce animations or match your system
Separate light and darkChoose a theme, accent and font for each
50

Case study · E-commerce & backend

Creator Portfolio & Digital Products Store

A static Next.js creator portfolio and a standalone Hono commerce API on Cloudflare Workers that sells digital products: Razorpay payments, queue-backed fulfilment and expiring download links.

Type
E-commerce & backend
Industry
Photographers & Creatives
Role
Full-stack developer · Sole developer
Status
Live preview
Year
2026

Deployed to a preview address; it is not live on the brand's own domain.

The project

The goal: a creator portfolio, plus a way to sell digital products (files) directly, without a marketplace taking a cut or owning the customer relationship. I built both, as two separate applications in one repository.

  • Frontend: a static Next.js creator portfolio and storefront, deployed to Cloudflare Workers with OpenNext, using TanStack Query for server data, Zustand for client state and React Hook Form with Zod for forms.
  • Backend: a standalone Hono commerce API on Cloudflare Workers with Drizzle ORM on Neon Postgres, Razorpay for payments, R2 for private files, Cloudflare Queues for payment events and Resend for email.

The two are coupled only through runtime HTTP. There’s no shared package or build dependency, so either side can be redeployed, or replaced, independently.

The challenge

Selling files sounds simple until you list what has to be true:

  1. A buyer who pays must always receive their file, even if a webhook is delayed, duplicated or fails halfway.
  2. A buyer who didn’t pay must never receive it.
  3. Download links can’t be shared indefinitely.
  4. A buyer who loses their email needs a way back without contacting support.

The architecture

The API is organised in layers, so the payment and delivery rules can be tested without HTTP or a database:

presentation/   Hono routes (/v1/products, /v1/orders, /v1/webhooks/razorpay, /v1/download, /v1/admin/*),
                admin auth, validation, error handler, dependency injection via context
application/    use cases: CreateOrder, EnqueuePaymentEvent, ConfirmPayment, DownloadAsset,
                RequestFreshLink, VerifyFreshLink, SweepUnfulfilledOrders; ports for payment, queue, email, storage
domain/         Order, DownloadToken, Money and status value objects; domain errors
infrastructure/ Drizzle + Neon repositories, Razorpay adapter, R2 storage, Resend email, queue producer/consumer

The payment flow

  1. Create order. The API creates a pending order and a Razorpay order, with the amount computed server-side.
  2. Receive the webhook. Razorpay calls POST /v1/webhooks/razorpay. The route reads the raw body and the x-razorpay-signature header and passes both to a use case.
  3. Verify and enqueue. The use case checks the HMAC-SHA256 signature with a constant-time comparison, ignores events other than payment.captured, looks up the order and enqueues a payment message. The webhook returns immediately.
  4. Confirm idempotently. A queue consumer loads the order; if it’s already paid, it stops. Otherwise it marks it paid, revokes any existing tokens, issues a new download token and emails the link.
  5. Reconcile on a schedule. A cron trigger every six hours finds paid orders with no valid token and fulfils them, covering anything the queue path missed.

Download security

Files never leave private R2 storage directly. A download token is valid for 24 hours and five downloads; each download issues a short-lived signed URL. If a link expires, the buyer requests a fresh one, proves ownership with a verification code sent to their email (valid 15 minutes), and is limited to three requests per hour.

Engineering review: what I’d tighten

Writing this up meant re-reading the code critically. Two improvements I’d make before calling it finished:

  • Retry failed queue messages explicitly. The consumer acknowledges messages that succeed and logs failures, but doesn’t call retry() on them. Cloudflare Queues treats un-acked messages in a batch that completes successfully as delivered, so failed confirmations currently rely on the six-hourly sweep rather than the queue’s retries and dead-letter queue.
  • Make “mark paid” a conditional update. The idempotency check (isPaid()) and the write are separate steps. Two concurrent deliveries of the same event could both pass the check. A single UPDATE … WHERE status = 'pending' RETURNING … closes that gap.

Both are covered in the article linked below, along with the general pattern.

Highlights

Key implementation details

  • Two independently deployable apps (a static Next.js portfolio and a Hono commerce API) coupled only over HTTP: no shared package or build dependency.
  • Layered backend: presentation, application (use cases + ports), domain entities, infrastructure adapters.
  • Razorpay webhooks verified with HMAC-SHA256 over the raw body and a constant-time comparison.
  • Payment events go through a Cloudflare Queue with retries and, in production, a dead-letter queue.
  • Digital files in private R2 storage, delivered by download tokens valid for 24 hours and five downloads.
  • A cron trigger every six hours re-issues links for any paid order without a valid token.
  • Buyers can request a fresh link via an emailed verification code, rate-limited to three requests an hour.

Planning something similar?

Tell me about your project and what you want it to achieve. I'll reply with a suggested approach, scope and timeline.