Multi-Tenant HR & Payroll SaaS
Multi-tenant HR and payroll SaaS for Australian businesses: Encore.dev/TypeScript services and React apps for staff, scheduling, timesheets, leave, award-based pay runs and billing. Built with Claude Code, in production on DigitalOcean.
Lead Full-Stack Engineer (AI-Assisted) · 2025 · SaaS / HR & Payroll
Tech: TypeScript, Encore.dev, Node.js, Drizzle ORM, PostgreSQL, React, Vite, shadcn/ui, Tailwind CSS, TanStack Query, Stripe, Redis, Docker, DigitalOcean, GitHub Actions, Sentry, Multi-Tenant SaaS, Claude Code
The problem
Australian payroll has to get modern awards, pay rates, leave, public holidays and superannuation right every pay period. A SaaS on top of that also needs strict tenant isolation, reliable billing and a UI people are happy to use. That's usually several teams and several years of work.
The approach
Encore.dev microservices with clear boundaries (identity, HR/payroll, payments, messaging, cron, gateway) over multi-tenant PostgreSQL via Drizzle, one shared API contract, and React/shadcn front-ends. I designed, built, refactored and documented it with Claude Code.
The architecture
An API gateway in front of the service fleet. A master database holds the tenant registry and each tenant gets its own database. Stripe handles subscriptions, several React SPAs sit on top, and it deploys to DigitalOcean through GitHub Actions with secrets injected per environment.
Outcomes
- Multi-tenant SaaS in production: a set of services plus web and admin clients
- A separate database per tenant for security and compliance
- Australian payroll rules: modern awards, pay rates, leave, public holidays, superannuation
- Stripe billing with plans, progressive billing and coupons
- Designed and built with Claude Code
What it is
A multi-tenant HR and payroll SaaS for the Australian market, running in production. It's made of identity and access, the core HR/payroll engine, payments and billing, messaging, scheduled jobs, an API gateway, three React web apps and a shared contracts package.
I built the whole thing on my own with Claude Code: the architecture, the code, the big refactors and the docs. If you want to see what I can deliver, this is the one to look at.
Why payroll is hard
Payroll doesn't forgive mistakes. In Australia it has to encode modern awards, pay rates and penalties, leave accruals, public holidays and superannuation, and every calculation has to be right every pay period. The SaaS side adds tenant isolation, reliable billing and a UI people are happy to use. Normally that's a multi-team, multi-year programme.
I wanted a properly split platform instead of a monolith: clear service boundaries, strong data isolation and one consistent API contract, built at the pace AI-assisted development allows.
Services and clients
One API gateway sits in front of the Encore.dev (TypeScript) services. React clients call them, and everything runs on DigitalOcean with PostgreSQL and Redis.
flowchart TB
subgraph Clients
UI[Main Web App<br/>React + shadcn]
ADM[Admin Portal<br/>React + Tremor]
CF[Cashflow UI<br/>React]
end
GW[API Gateway<br/>auth / routing]
subgraph Services[Encore.dev microservices]
ID[Identity]
HR[HR / Payroll]
PAY[Payments]
MSG[Messaging]
CRON[Cron Trigger]
COMMON[Common]
end
ST[(Shared Types<br/>API contract)]
PG[(PostgreSQL<br/>multi-tenant)]
RD[(Redis)]
EXT[Stripe / Email / Firebase]
Clients --> GW
GW --> Services
Services --> ST
Services --> PG
ID --> RD
PAY --> EXT
MSG --> EXT
How tenants are isolated
Isolation happens at the database level. A master database holds the tenant registry and shared reference data, and each tenant gets its own database, so one customer's data can't leak into another's. The HR service keeps separate Drizzle schemas and migration configs for the master and tenant layers.
flowchart LR
REQ[Authenticated request<br/>tenant context]
RES[Tenant Resolver]
MASTER[(Master DB<br/>tenant registry)]
T1[(Tenant A DB)]
T2[(Tenant B DB)]
T3[(Tenant C DB)]
REQ --> RES
RES --> MASTER
RES -->|route to tenant| T1
RES --> T2
RES --> T3
What happens on a request
sequenceDiagram
participant C as Client (React)
participant GW as API Gateway
participant ID as Identity
participant HR as HR Service
participant DB as Tenant DB
C->>GW: Request + JWT
GW->>ID: Validate token + claims
ID-->>GW: User + tenant + roles
GW->>HR: Forward (tenant context)
HR->>DB: Query tenant database
DB-->>HR: Data
HR-->>C: Standardized API response
The payroll engine
The HR service does most of the work. It's split into modules: staff, scheduling, timesheets, leave, awards, pay periods, pay runs and reports, plus tenant and task management. A pay run takes approved timesheets, applies award rules and pay rates, accounts for leave and public holidays, and produces payslips.
flowchart LR
SCH[Scheduling] --> TS[Timesheets]
TS --> APP[Approval]
APP --> PR[Pay Run]
AW[Awards & Pay Rates] --> PR
LV[Leave] --> PR
PH[Public Holidays] --> PR
PR --> SLIP[Payslips]
PR --> RPT[Reports]
PR --> SUPER[Superannuation]
Billing
A separate payments service handles Stripe subscription billing: plans and pricing, progressive billing and coupons. Webhooks keep subscription state in sync, and the service also generates PDF invoices.
sequenceDiagram
participant T as Tenant Admin
participant UI as Web App
participant PAY as Payments Service
participant S as Stripe
T->>UI: Choose plan / apply coupon
UI->>PAY: Create subscription
PAY->>S: Create customer + subscription
S-->>PAY: Subscription created
S-->>PAY: Webhook (invoice.paid / updated)
PAY->>PAY: Sync subscription state
PAY-->>UI: Billing status
One API contract for every service
Early on, each service returned things slightly differently. I moved them all onto one shared package with common response wrappers, a catalogue of 30+ error codes, pagination and metadata. Every service and front-end now uses the same shapes, and the types are checked at compile time.
Front-ends
- Main web app (for tenants): React 18, Vite, shadcn/ui, Tailwind, TanStack Query, React Hook Form, and Stripe Elements for checkout.
- Admin portal (internal ops): Tremor analytics dashboards, TanStack Table, FullCalendar scheduling, and a Monaco editor for configuration.
- Cashflow management UI: a small, focused cashflow tool.
Tooling and deployment
- Framework: Encore.dev gives typed service definitions, local dev that knows about the infrastructure, and clean service-to-service calls.
- Data: Drizzle ORM on PostgreSQL, with separate migration pipelines for master and tenant databases.
- Quality: TypeScript everywhere, ESLint/Prettier, Vitest, and Sentry for monitoring.
- Delivery: Dockerized services on DigitalOcean. GitHub Actions CI/CD pulls environment config from a secret manager for each environment (staging and production).
- AI: I designed, built and refactored every service with Claude Code, including the platform-wide API standardization and several domain refactors (awards/pay rates, retirement savings, public holidays).
Results
- A multi-tenant HR and payroll SaaS in production, made of coordinated services and clients.
- A database per tenant for security and compliance.
- Australian payroll rules covered: modern awards, pay rates, leave, public holidays and superannuation.
- Stripe billing with plans, progressive billing and coupons.
- One typed API contract shared across all services.
- Built solo with AI, without cutting corners on architecture or code quality.