Skip to content
E-commerce + ERP sync

Next.js E-commerce

A storefront kept in sync with the ERP every hour.

A production e-commerce platform for a standalone fashion brand: storefront, order management and finance in one Next.js app, with courier shipping and exchanges from the admin panel and an hourly ERP sync that keeps online stock in line with the physical stores.

Internal company system, not public
Role
Sole developer
Timeline
Jun 2026 – present
Status
In production
Hosting
DigitalOcean · Docker
Next.js E-commerce main screen
01

The problem

Launching a standalone online brand required a web storefront that could plug into the company's existing physical infrastructure. Orders had to ship through the courier straight from the admin panel, and stock that changes in the stores every day had to be reflected online to prevent overselling.

02

What I built

Built the full storefront and admin panel as sole developer. Customers browse, filter and buy with email sign-in and password reset; admins and a dedicated order-management role process orders, print shipping barcodes and send parcels to the courier through its API in one click. Staff can also create orders and exchange orders from the admin, with exchanges synced to the courier and every change to shipping details recorded in an audit log.

A finance module tracks confirmed, delivered, returned and in-transit orders from the courier's statuses, including the reasons customers refused a parcel. Products, sizes, prices and stock come from the ERP through an hourly sync, with a button to re-sync a single product on demand and the sync log visible in the admin. Low-stock alerts are backed by warehouse stock, and products can be hidden from the storefront in one click.

Banners are managed from the admin with a live homepage preview, and a Meta catalog feed and Pixel events support the brand's advertising.

03

Under the hood

Next.js 16 (App Router) with Prisma and PostgreSQL, deployed as a multi-stage Docker build on DigitalOcean. Caddy terminates TLS with a Cloudflare origin certificate and is the only container exposed; the app container publishes no port, the managed database is reachable only inside the private network, and product and banner images are served from DigitalOcean Spaces through its CDN. The ERP sync runs hourly from the server's crontab: it writes each run's snapshot to a staging table first, then upserts it into the live catalog in controlled transactions, so the storefront never reads half-synced data.

When the online store's own stock of a size runs low, the sync tops it up from what the warehouse has available, so sizes stay orderable.

  • TypeScript
  • Next.js
  • React
  • Tailwind CSS
  • Prisma
  • PostgreSQL
  • Auth.js
  • Zod
  • Resend
  • Docker
  • Caddy
  • Cloudflare
  • DigitalOcean
04

Results

  • Online stock follows the ERP every hour, with a one-click re-sync for any single product.
  • Orders and exchanges go from placed to handed to the courier without leaving the admin panel.
  • Delivered, returned and in-transit orders are tracked in one finance view, with the courier's refusal reasons attached.
  • The brand's ads run on a product feed generated from the live catalog.
05

Technical challenges

Problems I ran into while building and running it, and how I solved them.

  1. A sync that never blocks checkout+

    Each product's images are checked on the CDN during the sync. Doing those HTTP calls inside a database transaction would hold locks while waiting on the network and could block checkout writes, so images are resolved first, with limited concurrency, and the database writes run only after that.

  2. An hourly job that never runs twice+

    A full sync can take longer than usual when the ERP is busy, and two overlapping runs would fight over the same rows. The cron job runs on the Droplet itself rather than inside the app container, because it needs the full Prisma tooling the slim production image doesn't ship, and its wrapper takes a file lock so it skips the hour if the previous run is still going. That lock can't see the admin's "Sync" button, which runs inside the container, so both paths also share a guard in the database: each one records its run in the same sync-run table and refuses to start while another run is marked as running. That shared table is also why the hourly runs show up in the admin next to manual ones.

  3. From two databases to one+

    The first version staged ERP data in MongoDB before syncing it to PostgreSQL. Once the pipeline was stable I moved staging into a PostgreSQL table that each run replaces wholesale, which removed a second database to run and back up without losing the isolation between ERP data and the live catalog.

  4. Sync progress without hammering the database+

    A full sync logs thousands of lines, one per product. Writing each as its own database update would be wasteful, so lines are buffered and flushed about once a second to a sync-run record that the admin page reads to show progress live.

  5. Build-time vs runtime secrets+

    Next.js bakes public environment variables into the bundle at build time, while server secrets must only exist at runtime. After an API key went missing during the Docker build, I documented and separated the two: public values pass through Docker build arguments, secrets come only from the runtime environment file.