Projects Archive

DentaCares

A dental clinic SaaS I designed, built and run on my own. The treatment recorded at the chair is the same record that moves the stock, the lab case, the invoice, the dentist's commission and the accounts, in English and Arabic.

Visit site
DentaCares

Category

Full-Stack

Year

2026

Duration

Feb 2025 – present

Team

1 engineer

Connected apps

5

API modules

60+

Commits

~2,500

Cross-clinic leaks

0 / 475 routes

Slowest query

106 s → 0.2 s

Overview

  • I studied dentistry for five years before I became a software engineer, and DentaCares is the system I wanted in every clinic I trained in. It runs the whole clinic loop: booking → chair → lab → invoice → insurance → stock → payroll → P&L.
  • Five connected surfaces share one NestJS API: the clinic dashboard (React 19, installable on phones), a public website with online booking for every clinic (Next.js, custom domains), a platform admin console, an English/Arabic marketing site, and an Electron tray app that files X-rays straight into the patient record.
  • The core idea: the treatment recorded at the chair is the same record that moves the stock, the lab case, the invoice, the dentist's commission and the accounts. Nothing is entered twice, so the numbers can be trusted by construction.
  • Every screen ships in English and Arabic, right to left. RTL, digit handling and font metrics were designed in from the start rather than mirrored afterwards.

The problem

  • Owners knew what came in each month, not what they kept. Nobody could say whether a crown made money once the lab bill, the materials and the dentist's commission were subtracted.
  • Lab cases were chased on WhatsApp, and patients often arrived for a fitting before the crown did.
  • Commissions and payroll were worked out in a spreadsheet at month-end, then argued over.
  • Stock ran out without warning, because nothing connected a filling at the chair to the composite on the shelf.
  • The market offered either a simple appointment book or generic ERP that dentists could not read, and very little of it worked properly in Arabic.
  • On the engineering side: a multi-tenant system where hundreds of endpoints take an id in the URL (one missed clinic filter is a data leak between clinics), money that has to reconcile across branches and currencies, and real-time screens on a clustered Node API.

The solution

  • Scheduling without double booking: the calendar works in the clinic's time zone, not the browser's, and a dentist or room can never be double-booked. PostgreSQL advisory locks enforce it on the server, so two receptionists clicking the same slot cannot both win. Appointment status moves through one server-side state machine, and the waiting room syncs live over Socket.IO.
  • Clinical records at the chair: an interactive dental chart (FDI / Universal / Palmer) with per-tooth history, treatment plans with phases and signed acceptance, prescriptions checked against allergies, consent forms with e-signature, and a medical-history form patients fill on their own phone from a QR code.
  • Labs, insurance and stock on the same record: lab cases warn when they will miss the fitting, insurance claims split each session between insurer and patient and batch monthly per insurer, and materials are consumed per procedure with "runs out in N days" forecasts.
  • Money that always adds up: every money write is one transaction with row locks taken in id order, ledger rows go through a single service that refuses overdrafts, refunds are linked reversal rows rather than deletes, and totals are owned by database triggers. Amounts are stored as bigint minor units with a currency code, and FX rates are snapshotted at write time so historical reports never move.
  • Tenant isolation I can prove: a global interceptor resolves every UUID route parameter to its owning clinic and answers 404 before the handler runs. A probe signs up a second clinic through the real flow and calls all ~475 id-bearing routes with the first clinic's ids.
  • A tamper-evident audit trail: every write is captured by a global interceptor into a monthly-partitioned, append-only table where each row carries the hash of the previous one, and an offline verifier proves nothing was edited or deleted.
  • Infrastructure: NestJS 11 on a 5-worker Node cluster behind nginx, PostgreSQL 18 with Drizzle and PgBouncer, Redis for the Socket.IO adapter, cache and rate limits, Cloudflare R2 for files, Sentry and Better Stack with one request id end to end, and blue/green Docker deploys from GitHub Actions.

Architecture

DentaCares system architecture

Decisions & trade-offs

One global tenant interceptor, not a check in every handler

About 475 routes take an id in the URL, and one forgotten clinic filter is a data leak between clinics. A global interceptor resolves every UUID parameter to its owning clinic and answers 404 before the handler runs. A probe that signs in as a second clinic and calls every route proves it: 0 cross-clinic reads and 0 of 238 cross-clinic writes. The cost is an extra lookup on every request that carries an id.

Money totals owned by the database, not the services

An early refund path wrote ledger rows directly, and a stored balance drifted from its transactions. Now every money write goes through one transactional service that takes row locks in id order, amounts are bigint minor units, and running totals are kept by triggers that services cannot overwrite. The cost: part of the logic lives in SQL (51 hand-written migrations), where it is less visible than in the TypeScript.

Double booking stopped on the server, with advisory locks

The calendar's check in the browser is only there for a good experience. The real rule, that a dentist or a room can never be double-booked, is enforced on the server with PostgreSQL advisory locks, so two receptionists clicking the same slot cannot both win. The cost is that competing bookings wait their turn, which is fine at clinic volume.

WebSocket-only real-time across a five-worker cluster

The API runs as a five-worker Node cluster. Long-polling would need sticky sessions, so clients connect over WebSockets only, Socket.IO fans out through the Redis adapter, and only worker 0 runs crons. The cost: there is no fallback transport for a network that blocks WebSockets.

Outcomes

  • A production SaaS with five integrated surfaces, built and run by one engineer: ~2,500 commits, 60+ API modules, ~650k lines of TypeScript.
  • Profit per treatment after materials, lab cost and dentist commission: the report that answers whether a crown actually makes money.
  • 0 cross-clinic reads and 0 of 238 cross-clinic writes across ~475 id-bearing routes once the tenant interceptor shipped.
  • P&L, overview, cash and treatment-profitability reports agree to the cent for the same period, enforced by an end-to-end suite.
  • Swept every GET endpoint against a three-year volume database: a patient-credit query went from 13–106 s to 0.2 s, and the inter-branch report from 20 s to 0.2 s.
  • Frontend entry bundle cut from 571 KB to 178 KB gzipped by splitting locales out of the entry chunk.
  • Full English and Arabic (RTL) coverage, multi-branch and multi-currency, with four subscription tiers billed from the admin console.
  • CI on every pull request with ~220 unit specs and ~40 database-backed e2e suites; zero-downtime blue/green deploys.

My role

Founder and sole engineer: product, UX and design system, backend, frontend, DevOps and the business behind it.

NestJS, TypeScript, PostgreSQL, Redis, React, Electron, Node.js, Docker

Gallery