← Projects

MatajerjoHow I run it

Matajerjo is a platform where Jordanian merchants launch their own Arabic/English online store. I built it and I run it in production myself. This page covers what runs where, how updates ship, how the data is backed up, and what happens when something breaks.

Every number on this page was checked against the live server on 14 Oct 2026.

The setup

Matajerjo production architecture Visitors reach Cloudflare over HTTPS. Cloudflare forwards to one VPS whose firewall only accepts Cloudflare. On the VPS, Caddy routes requests to four Node.js apps managed by pm2: the storefront with two workers, the merchant dashboard, the admin console and a job worker. The apps use PostgreSQL 16 in Docker. Product images are stored in Cloudflare R2. A nightly backup job and a five-minute health check run on the same server. Visitors HTTPS Cloudflare TLS · CDN cache for shop pages R2 product images One VPS · Ubuntu 24.04 firewall: Cloudflare only images Caddy reverse proxy · per-store certificates pm2 Storefront ×2 every shop Dashboard merchants Console platform admin Worker scheduled jobs PostgreSQL 16 in Docker · reachable from this server only Nightly backup 02:15 · 14 days kept on this server Health check every 5 minutes email on fail / recover
How a request reaches the database. Dashed boxes are the jobs that watch over it.
  • One VPS (Ubuntu 24.04, 4 vCPUs, 7.8 GB RAM) runs everything: production, a full staging copy with its own database, and the jobs that keep both healthy.
  • Cloudflare sits in front. It handles TLS for visitors and caches shop pages at the edge. The server's firewall only accepts web traffic that comes from Cloudflare.
  • Caddy routes each request to the right app. Every store gets its own certificate automatically, but only after the app confirms the domain belongs to a real store.
  • pm2 keeps four Node.js apps running: the storefront (two workers) that serves every shop, the merchant dashboard, the platform admin console, and a worker for scheduled jobs.
  • PostgreSQL 16 runs in Docker and only listens on the server itself, never on the public internet.
  • Product images live in Cloudflare R2 object storage, not on the server's disk.

The AI assistants

Matajerjo has three assistants built on the Claude API from Anthropic. Each one answers in Arabic or English and only gets the tools it needs.

  • In every shop, for shoppers: finds products, answers questions about prices, delivery fees and the shop's policies, and hands the conversation to the shop's WhatsApp when a person is needed. Every tool it has reads through the store the server resolved from the request, so it can't see another shop.
  • In the merchant dashboard: summarises orders, explains reports, finds products and customers, and drafts product descriptions. It can propose a stock, price or order status change, but the proposal is a card the merchant has to confirm, and the server re-checks their role, plan and the order's state at that moment.
  • On the marketing site, for visitors: explains the plans, recommends one, and points to the demo shops.

Each shop has a monthly message limit and a cost ceiling on the model. In the platform console, raising a limit asks for the admin password again, and switching the assistant off is one click.

How updates are deployed

A deploy is a git push. The server holds a Git repository with a hook that builds and releases what arrives. The rule: nothing reaches production without going through staging first.

  1. I push to the staging branch. The server builds it at staging.matajerjo.com, which has its own database, and I check it there.
  2. I push the same commit to production, so what I checked is exactly what ships.
  3. The hook runs, in order: install locked dependency versions → build → apply database migrations → sync plan settings → reload the apps with pm2.

The order matters. The build is the slowest step and the most likely to fail, so it runs while the old version is still serving. If any step before the reload fails, the deploy stops and visitors keep getting the previous version. Database changes must be additive (new tables or columns) so the old code keeps working while a migration runs; removing a column takes two deploys.

Lesson learned. On 30 Aug 2026 every page returned an error for about half an hour (five failed health checks in a row). A deploy shipped code that expected new database columns, but nothing ran the migration. The migration is now a step inside the deploy hook itself, and a test fails if the schema has a column that no migration creates.

How backups work

  • Every night at 02:15 (Amman time) a script dumps the whole database and compresses it.
  • It checks the result before trusting it: a file that is suspiciously small is rejected, because a failed dump can still produce a valid-looking archive, and the archive's integrity is tested.
  • The last two weeks are kept. On 14 Oct 2026 that was 15 nightly copies of about 2.2 MB each.
  • The health check below alerts me if the newest backup is ever more than 30 hours old, so backups can't stop silently.
  • Product images are in Cloudflare R2, separate from the server.

Known gap. Today these backups are stored on the same server as the database. If that server's disk were lost, the backups would be lost with it. The backup script can already upload each copy to a private storage bucket; setting that bucket up is my next step.

What happens if the server goes down

It depends on how much of it goes down.

  • One app crashes. pm2 restarts it automatically, and pm2 itself starts when the server boots.
  • Something breaks while the server is up. A health check runs every 5 minutes. It tests each app's health endpoint, the public site through Cloudflare, the database, disk space, backup age and certificate expiry. It emails me once when a check starts failing and once when it recovers, so an ongoing problem doesn't flood my inbox.
  • The whole server goes down. The apps and the database all live on this one server, so the platform is down until it's back, and the health check can't warn me because it runs on that same machine. Rebuilding means a new server, the app code from Git, the server's config files (copies are kept in the repository), and the database from the latest backup, which today is on the old server (see the gap above).

From 30 Aug to 14 Oct 2026 the health check ran 12,915 times. 12 runs failed: five during the 30 Aug incident above, and seven single failures of the public check that had cleared by the next run.