Two AI layers · rules-first · Zod-validated
A gym booking SaaS where AI does real work.
One advisor reads live bookings and greenlights safe overbooking inside a DB transaction. A second one reads your blood panel and rewrites the week's class plan around what it finds — rules classify the markers, the model programs on top.
AI advisor
Grok reads live bookings and returns strict JSON: expected shows, risk band, verdict.
Invariants in Postgres
CHECK constraints + partial unique indexes so bugs can't drive credits negative.
Redis cache
60s advice cache keyed by the booking-set hash. ~25× faster on repeat calls.
Rate-limited
Throttler on top of Redis protects the Grok key from runaway spend.
Architecture
Feature-first NestJS, with repositories
Controller → service → repository. Services never touch Prisma. Shared Zod schemas validate both the HTTP boundary and the AI contract. New features don't bloat the root.