The problem
Clinics in Brazil sit on a stack that hasn’t moved in a decade — phone scheduling, paper records, manual reconciliation when a procedure is split between a clinic and an independent professional. We’re building a SaaS that fits both the clinic operator and the marketplace of professionals working out of it, with first-class scheduling, services discovery, and a payment split that doesn’t require a finance person to compute.
Architecture
Next.js 16 App Router on PostgreSQL via Prisma 7. Auth on Better Auth with a role hierarchy SUPER_ADMIN > ADMIN > CLINIC_MANAGER > PROFESSIONAL > PATIENT. Files (medical records, profile media) on MinIO in dev and S3-compatible storage in production.
Tenant A Tenant B Tenant C
──────── ──────── ────────
clinic ops solo professional clinic + marketplace
│ │ │
└────────────────────┼────────────────────┘
│
Next.js 16 App Router · React 19
Better Auth · session-aware everywhere
│
┌────────────────┼────────────────┐
▼ ▼ ▼
PostgreSQL MinIO / S3 Payment splits
(Prisma 7, (provider-agnostic,
cents-based webhook-driven)
money)
Architectural discipline
A four-layer rule the codebase enforces:
UI Components → Hooks → Services → Repositories → Database (Prisma)
Components and hooks never import the Prisma client. Services never bypass repositories. API routes and server actions are thin: validate input via Zod schemas in src/schemas/, delegate to a service, return through typed response helpers (apiSuccess, apiList, apiError). The pattern keeps multi-tenant logic single-sourced — every read and write touches a repository that scopes by tenant.
Money values are stored as integers in cents. finalValueInCents = transferValueInCents + commissionValueInCents. No floats anywhere near financial code.
Engineering practice
I’m leading the engineering side — defining the architecture, picking the stack, code review, sprint cadence, and onboarding the team. Tests run on Vitest with a real PostgreSQL fixture (no mocks for data-layer tests; production parity wins over speed).
Status
In active build — first paying tenants targeted for mid-2026. The architecture decisions made now (multi-tenant from day one, schema-first from the spec, repository-scoped queries) are designed to keep the cost of adding the tenth and hundredth tenant linear, not exponential.