System architecture
How the platform is put together
A high-level view prepared for public presentation. Credentials, internal endpoints, configuration values, thresholds and anything security-sensitive are deliberately left out.
System overview
Request path, from client to data
Browsers and the installable PWA talk to a single Next.js application. Pages render on the server, route handlers serve JSON actions, and a scheduled job applies due employment changes. All data access goes through typed domain services.
Clients
Employee PWA
Mobile-first, installable, offline fallback
Manager & HR web app
Desktop work surface, responsive
Store code display
Rotating code shown at each location
Edge
Request proxy
Route-level role routing; every handler re-checks access
Application
Server-rendered pages
React Server Components
Route handlers
JSON APIs for punch, review, HR actions
Scheduled job
Daily employment-change apply
Domain services
Attendance & exceptions
Roster & leave
People & lifecycle
Access & audit
Data
PostgreSQL
Managed, pooled connections, constraints for invariants
Private object storage
Selfies and documents; served only via authorized route
Frontend
React Server Components for data-heavy pages, with client components only where interaction needs them: punch flow, roster editor, dialogs. A shared design-token layer covers a mobile-first employee UI and a desktop work surface for managers and HR. Heavy libraries load lazily, and database code is kept out of browser bundles.
Backend and APIs
Route handlers validate input, resolve the caller's effective access, and delegate to domain services. Business-day boundaries are computed in the business timezone, independent of the server timezone. Punches are idempotent, and raw punch events are immutable.
Authentication
Server-backed sessions
Sessions are stored on the server, so they can be revoked and re-validated on every request instead of trusting a token until it expires.
Step 1
Sign in
Staff code and password; password hashing; first-login password change.
Step 2
Server-backed session
A session record is created; the browser holds a signed, HTTP-only cookie.
Step 3
Every request
The session is validated against the database, so revocation and account changes apply immediately.
Step 4
Effective access
Position → capability keys + data scope, resolved once per request.
Step 5
Enforcement
Route handlers and pages check capability and scope before reading or writing data.
Step 6
Audit
Sensitive actions and sign-in events are recorded.
Role-based access control
Position-driven capabilities and data scope
Access is not hard-coded per role. A position grants capability keys and a data scope; the server resolves them into effective access for each request, and navigation is built from the same model.
User
Sign-in identity
Employee
Person record, home store
Position
e.g. Sales Associate, Store Manager, Area Manager, HR
Capability keys
What actions are allowed, e.g. review exceptions, manage roster
Data scope
Self · Assigned stores · All stores
Effective access
Resolved per request on the server
Navigation
Derived from the same capabilities, so the UI and the server agree
Data model
Domains and key relationships
PostgreSQL models grouped into eight domains, evolved through reviewed migrations. Important invariants, such as one current workplace membership or one scheduled change per employee, are enforced with database constraints and partial unique indexes.
Identity & access
- User
- Session
- Position
- Permission
- Login audit
Organisation
- Store
- Department
- Store code
- Workplace assignment
- Managed store
Attendance
- Punch event
- Daily summary
- Exception
- Day closing
- Temporary assignment
Scheduling
- Store shift
- Roster assignment
- Public holiday
Leave
- Leave request
- Leave ledger
- Replacement credit
- Attachment
People & HR
- Profile
- Employment change
- Staff code reservation
- Document
- Timesheet
Communication
- Announcement
- Recipient
- Acknowledgement
Audit
- Audit log
- Import batch
- • An Employee has one home store, any number of dated workplace assignments, and optional managed stores.
- • A Punch event records the actual location and is never edited; corrections and reviews reference it.
- • Employment changes are rows with a lifecycle state; the employee record changes only when one is applied.
- • Leave balances are derived from ledger entries rather than mutable counters.
Storage and privacy
Private by default
Selfies and documents live in private object storage. They have no public URLs and are served only through an authenticated, authorized route.
Record-level checks
File access is authorized against the record a file belongs to, not just the user's role.
Encrypted fields
Confidential identifiers are encrypted at the application layer with authenticated encryption bound to their record, and revealing them requires re-authentication.
Deployment and delivery
From plan to production
The app is hosted on Vercel with a managed PostgreSQL database. Merging to main deploys automatically, so schema changes are applied in an approved window before the merge, behind read-only preflight checks.
01
Plan
Read-only investigation, written plan, approval
02
Pull request
AI-assisted implementation, human review
03
CI gate
Lint · build & typecheck · test suites on ephemeral Postgres
04
Preflight
Read-only production checks; frozen baseline
05
Migrate
Approved window; migrations before merge
06
Merge & deploy
Automatic production deployment
07
Postflight
Smoke checks, dry runs, owner acceptance; rollback target recorded
Technology
| Technology | Used for |
|---|---|
| Next.js 16 | App Router, server components, route handlers |
| React 19 | UI |
| TypeScript | End to end |
| Tailwind CSS 4 | Design tokens, responsive UI |
| Prisma 6 | Schema, migrations, data access |
| PostgreSQL | Managed database |
| Object storage | Private, server-mediated file storage |
| Vercel | Hosting, scheduled jobs |
| GitHub Actions | CI quality gate |
| PWA | Installable, offline fallback |
Major versions in the production stack.