SD Portal.
A private business portal I built and run to organize my freelance work. Client info, projects, deliverables, invoices, a calendar, and file uploads live in one place, with watermarked proofs for clients and online invoice payment.


The problem
Freelance work spreads out fast: email threads, shared folders, invoices, and proofs all end up in different places. I wanted one place to run the business, built the way I work and hosted on hardware I control.
What I built
Clients and projects
Every client has a page with their projects, files and history in one place.
Deliverables and uploads
I upload files to a project and track what’s been delivered.
Watermarked proofing
Clients review work through a proof link that shows a watermarked copy.
Invoices
I build invoices inside the project they belong to.
Online payment
Invoices are set up to be paid online by card through Stripe Checkout. It runs in Stripe’s test mode until I switch on live payments.
Calendar
Deadlines and calls sit on one calendar across every project.
Team roles
Collaborators are given a role that controls what they can see and change.
Google sign-in
Everyone signs in with Google, so there are no passwords to manage.




How it’s set up
Private by default, public only where a client needs it.
SD Portal is a Next.js app with a SQLite database, run by systemd as a Node service. It answers only on the server itself. I use it over Tailscale from my laptop or phone, and sign-ins go through Google.
Clients never see the app. They get a proof link or a pay link, and Stripe sends payment notices to a webhook. Those three are the only routes the internet can reach.
Security and reliability
Security
- The app only listens on the server itself. I reach the full app over Tailscale, my private network.
- Only three things are public: client proof links, pay links, and the payment webhook. Each goes through a route that does one job and nothing else.
- Proof links only ever serve watermarked copies of the files.
- Payment amounts are calculated on the server, so nobody can change what they pay from the browser.
- Stripe payment notices are checked against their signature before anything is recorded.
Reliability
- Every night, a backup takes a safe snapshot of the database instead of copying a file that’s in use.
- It runs an integrity check on that snapshot before keeping it.
- Files are copied with hard links, so files that haven’t changed take up no extra space.
- Thirty nights of backups are kept.
- If a backup fails, an alert goes to my phone.
See the full nightly backup script
#!/usr/bin/env bash
# backup.sh — nightly copy of SD Portal's data to the 2TB drive on the server.
# Run by cron as my user (see README → Backups). Safe to run by hand any time:
# bash backup.sh
#
# Each run makes a dated folder under $BACKUP_ROOT containing:
# portal.db a consistent snapshot of the database (made while the portal keeps running)
# files/ every uploaded file. Unchanged files are hard links to the previous night's
# copy, so 30 nights of backups take about the space of one plus what changed.
# env.local your .env.local (secrets, so the backup folders are private to my user)
# Backups older than KEEP_DAYS are removed.
# Stop at the first error (-e), treat unset variables as errors (-u), and make a failure
# anywhere in a pipeline count as a failure (-o pipefail). Without these, a script can
# "succeed" after half its steps failed.
set -euo pipefail
# Locations and the alert bot's credentials come from a private config file, not shown here.
# Anything can still be overridden from outside, which is how it's tested.
source "$PRIVATE_CONFIG"
PORTAL_DIR="${PORTAL_DIR:?}"
BACKUP_MOUNT="${BACKUP_MOUNT:?}"
BACKUP_ROOT="${BACKUP_ROOT:?}"
NODE="${NODE:-node}"
KEEP_DAYS="${KEEP_DAYS:-30}"
TODAY="${TODAY:-$(date +%F)}" # 2026-10-15. Dates in this format sort correctly as text.
DEST="$BACKUP_ROOT/$TODAY"
WORK="$DEST.partial" # built here first; renamed to $DEST only when complete
log() { echo "$(date '+%F %T') $*"; }
# Telegram alert using the same bot as the drive-temperature alerts, if it's set up.
# The server's file uses TG_TOKEN / TG_CHAT; the other names are fallbacks.
alert() {
local file="$PRIVATE_CONFIG" token="" chat=""
if [[ -r "$file" ]]; then
# shellcheck disable=SC1090
source "$file"
token="${TG_TOKEN:-${TELEGRAM_BOT_TOKEN:-${BOT_TOKEN:-}}}"
chat="${TG_CHAT:-${TELEGRAM_CHAT_ID:-}}"
fi
if [[ -z "$token" ]]; then
log "(Telegram alert not sent: no bot token found in $file)"
return 0
fi
# || true: a failed alert must not hide the real error
curl -fsS --max-time 15 "https://api.telegram.org/bot${token}/sendMessage" \
--data-urlencode "chat_id=${chat}" --data-urlencode "text=$1" >/dev/null || true
}
fail() {
log "FAILED: $1"
alert "⚠️ SD Portal backup FAILED on $(hostname): $1"
exit 1
}
# Any command that errors (set -e) lands here, with the line number, instead of dying silently
trap 'fail "unexpected error on line $LINENO"' ERR
# 1. The 2TB drive must really be mounted. If the drive dropped off, its mount point is just an
# empty folder on the system drive, and "backing up" there would quietly fill it up.
mountpoint -q "$BACKUP_MOUNT" || fail "$BACKUP_MOUNT is not mounted (did the USB drive drop off?)"
[[ -f "$PORTAL_DIR/data/portal.db" ]] || fail "no database at $PORTAL_DIR/data/portal.db"
command -v "$NODE" >/dev/null || fail "Node not found ($NODE)"
command -v rsync >/dev/null || fail "rsync isn't installed (sudo apt install rsync)"
mkdir -p "$BACKUP_ROOT"
chmod 700 "$BACKUP_ROOT" # only my user can read the backups: they contain .env.local
# Leftovers from runs that died halfway (any night). Only *.partial folders, never real backups.
find "$BACKUP_ROOT" -mindepth 1 -maxdepth 1 -type d -name '????-??-??.partial' -exec rm -rf {} +
mkdir -p "$WORK"
# 2. Database snapshot. VACUUM INTO writes a complete, consistent copy even while the portal
# is reading and writing (copying the raw file mid-write can produce a broken copy).
# Then the copy is opened and checked before we trust it.
"$NODE" --no-warnings -e '
const { DatabaseSync } = require("node:sqlite");
const [src, dst] = process.argv.slice(1);
const db = new DatabaseSync(src);
db.exec("PRAGMA busy_timeout = 10000"); // wait for the portal to finish a write, up to 10s
db.prepare("VACUUM INTO ?").run(dst);
db.close();
const copy = new DatabaseSync(dst, { readOnly: true });
const check = copy.prepare("PRAGMA integrity_check").get().integrity_check;
if (check !== "ok") { console.error("integrity check: " + check); process.exit(1); }
const n = (t) => copy.prepare(`SELECT COUNT(*) AS n FROM ${t}`).get().n;
console.log(`${n("clients")} clients, ${n("invoices")} invoices, ${n("payments")} payments`);
' "$PORTAL_DIR/data/portal.db" "$WORK/portal.db" > "$WORK/summary.txt" \
|| fail "database snapshot failed: $(cat "$WORK/summary.txt" 2>/dev/null)"
chmod 600 "$WORK/portal.db"
# 3. Uploaded files. --link-dest: any file identical to last night's copy becomes a hard link
# to it (same data on disk, zero extra space) instead of a second copy.
PREVIOUS="$(find "$BACKUP_ROOT" -mindepth 1 -maxdepth 1 -type d -name '????-??-??' ! -name "$TODAY" | sort | tail -n 1)"
if [[ -d "$PORTAL_DIR/data/files" ]]; then
LINK=()
[[ -n "$PREVIOUS" && -d "$PREVIOUS/files" ]] && LINK=(--link-dest="$PREVIOUS/files")
# The trailing slashes matter: "copy what's INSIDE files/ into files/", not files/files/
rsync -a "${LINK[@]}" "$PORTAL_DIR/data/files/" "$WORK/files/"
fi
# 4. Settings and secrets, so a restore doesn't mean re-creating Google/Stripe/Gmail keys
if [[ -f "$PORTAL_DIR/.env.local" ]]; then
install -m 600 "$PORTAL_DIR/.env.local" "$WORK/env.local"
fi
# 5. Only now does it become a real backup: swap the finished folder into place
rm -rf "$DEST"
mv "$WORK" "$DEST"
# 6. Remove backups older than KEEP_DAYS. Only folders named like a date are ever touched.
CUTOFF="$(date -d "$TODAY - $KEEP_DAYS days" +%F)"
REMOVED=0
for dir in "$BACKUP_ROOT"/????-??-??; do
[[ -d "$dir" ]] || continue
name="$(basename "$dir")"
if [[ "$name" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ && "$name" < "$CUTOFF" ]]; then
rm -rf "$dir"
REMOVED=$((REMOVED + 1))
fi
done
KEPT="$(find "$BACKUP_ROOT" -mindepth 1 -maxdepth 1 -type d -name '????-??-??' | wc -l)"
log "OK $DEST: $(cat "$DEST/summary.txt"); db $(du -h "$DEST/portal.db" | cut -f1); $KEPT backups kept, $REMOVED old removed; total $(du -sh "$BACKUP_ROOT" | cut -f1)"What’s next
Off-site backups
Nightly backups now go to two drives at home. Next, a copy of my business data will also go off-site.
Live payments
Payments run on Stripe’s test setup today. Going live means switching to live keys and a live webhook.
A new sign-in library
I’m moving Google sign-in to a newer, actively maintained library.
Want a closer look?
I’m happy to walk through SD Portal on a call, with demo data.