How porta0922/nutripro works
1. Top-level shape
NutriPro is a single Next.js application (Pages Router) backed by Supabase. The app serves multiple user roles from one codebase: nutritionist, patient, student, tutor, university admin, and system admin. The architecture is strongly domain-driven, but not microservice-based.
2. Entry points and routing
The main navigation starts at the landing page and unified sign-in flow, then branches into role-specific route trees under pages/. Each role has its own dashboard and subpages, which acts as the primary architectural boundary for UI and data access.
3. Authentication and route protection
Supabase Auth is the identity provider in production. middleware.ts enforces access control at the route layer, while lib/auth.tsx and related pages manage session state and role-based redirects. There is also a development mock-auth path for local testing, which bypasses real authentication when enabled.
4. Backend/data layer
The persistent backend is Supabase Postgres plus Supabase Storage. Database access is done through the Supabase JS client in lib/supabaseClient.ts, with Row Level Security enforcing most authorization rules in the database itself. This means the application trusts both route guards and DB policies, not just UI checks.
5. Core clinical domain
The nutritionist/patient subsystem covers clients, appointments, anthropometrics, body composition, diets, progress photos, and notifications. UI components, hooks, schemas, and Supabase tables line up closely here: forms capture clinical data, hooks fetch/update it, and charts/lists display longitudinal history.
6. Academic practice domain
A second major bounded context handles student, tutor, and university workflows. It includes practice patients, meal plans, tutor reviews, field trips, and institutional administration. This subsystem is separate from the real-patient workflow in both routes and permissions, because practice data is marked and governed differently.
7. Administration and subscriptions
The admin area manages platform-wide concerns such as nutritionist accounts, universities, reports, support, audit, and subscriptions. This is the highest-privilege boundary in the system and is the main place where privileged API routes and database operations are exposed.
8. Client-side state and shared UI
contexts/ provides cross-cutting state for language and notifications, while hooks/ encapsulates domain fetch/mutation logic for clients, diets, anthropometrics, food portions, students, tutors, and reviews. components/ is organized into reusable domain widgets and form panels, so pages mostly compose prebuilt pieces rather than implementing logic inline.
9. Validation and domain rules
Zod schemas in schemas/ validate key forms such as anthropometrics and appointments before data is submitted. This creates a validation boundary on the client side that complements Supabase constraints and RLS on the server side.
10. Notifications and scheduled jobs
Notifications are a first-class subsystem, with a UI center, database support, and a Supabase Edge Function for appointment reminders. The cron-driven function under supabase/functions/send-appointment-reminders is the clearest background process in the repository and is likely the only scheduled automation path.
11. File and document handling
PDFs and images are stored in Supabase Storage buckets, mainly diets, progress_photos, and profile_pictures. Diet plans and patient reports flow from forms/components into storage-backed records, then back out to embedded viewers, downloads, or generated exports.
12. API routes as server-side escape hatches
The app uses Next.js API routes for privileged or orchestration-style tasks such as admin actions, auth/profile helpers, exports, photo deletion, setup flows, and job execution. These routes are the main server-side integration surface outside of direct client-to-Supabase calls.
13. Utility and rendering support
Shared utilities like PDF generation and currency formatting support the clinical and admin workflows. The repo also includes global theming and layout helpers, which suggests most UI consistency is handled centrally rather than per module.
14. Operational/deployment boundary
The repository is productionized with Docker, Nginx config, Next.js config, and extensive Supabase SQL migrations/seeds. The architecture therefore spans frontend, database, storage, and edge automation, with docs and SQL scripts serving as the source of truth for schema, policies, and deployment behavior.
Main entry points: middleware.ts Route guard · supabaseClient.ts Supabase client · auth.tsx Session auth · useClients.ts Clients hook
Components 30
App UI
Pages, route trees, and shared client-side interface composition.
- Landing · Public entry point and navigation into the authenticated flows.
pages/index.tsx - Sign in · Unified login entry that branches users into role-specific app areas.
pages/auth/signin.tsx - Nutri dashboard · Primary workspace for nutritionist clinical workflows.
pages/nutritionist/dashboard.tsx - Student dashboard · Practice-oriented workspace for student users.
pages/student/dashboard.tsx - Tutor dashboard · Tutor workspace for reviews, students, and practice patients.
pages/tutor/dashboard.tsx - University dashboard · Institutional workspace for university administration.
pages/universidad/dashboard.tsx - Admin area · Highest-privilege platform administration and subscription boundary.
pages/admin/index.tsx - Client view · Patient-facing dashboard for appointments, plans, and progress.
pages/client/dashboard.tsx - Theme · Global visual tokens and app-wide styling configuration.
theme.ts - Global styles · Base CSS for application-wide presentation.
styles/globals.css
Domain Modules
Reusable clinical, academic, and admin-facing feature components and hooks.
- Notifications · In-app notification center and message surface.
components/NotificationCenter.tsx - Diet builder · Interactive diet-plan composition and template workflow.
components/DietPlanBuilder.tsx - Anthro form · Capture and edit anthropometric measurements.
components/AnthropometricForm.tsx - Field trips · Student practice workflow for field trips and related records.
components/student/FieldTripForm.tsx - Meal review · Tutor review interface for meal plans and student practice work.
components/tutor/ReviewMealPlanModal.tsx - Admin metrics · Platform metrics and administrative overview cards.
components/admin/AdminMetricsCard.tsx - PDF export · Generates diet and report PDFs for clinical workflows.
utils/dietPlanPDF.ts
Auth & Data
Authentication, client data access, validation, and shared runtime state.
- Route guard · Enforces route protection and role-aware access control.
middleware.ts - Session auth · Session state, redirects, and client-side auth coordination.
lib/auth.tsx - Supabase client · Shared Supabase JS entry for database and storage access.
lib/supabaseClient.ts - Clients hook · Fetch and mutation logic for nutritionist client records.
hooks/useClients.ts - Student hook · Practice-patient access and updates for student workflows.
hooks/useStudentPatients.ts - Appointment schema · Client-side validation rules for appointment forms.
schemas/appointments.ts
Platform
Supabase backend, server routes, scheduled jobs, and deployment concerns.
- Metrics API · Server-side endpoint for privileged admin reporting.
pages/api/admin/metrics.ts - Client API · Server-side helper for creating and inviting clients.
pages/api/clients/create.ts - Reminder job · HTTP-triggered job execution for appointment reminders.
pages/api/jobs/process-reminders.ts - Mock auth · Development-only authentication bypass for local testing.
pages/api/auth/mock.ts - Reminder function · Scheduled automation that sends appointment reminders.
supabase/functions/send-appointment-reminders/index.ts - Schema & RLS · Database schema, permissions, policies, and feature tables.
supabase/migrations/1 - initial schema.sql - DB schema · Consolidated database schema and reference definitions.
supabase/schema.sql
Connections 26
- Landing → Sign in: start auth · Public users move from landing into the sign-in flow.
- Sign in → Session auth: session · Authentication pages rely on shared session and redirect logic.
- Session auth → Route guard: protect routes · Client auth state aligns with route-layer access control.
- Route guard → Nutri dashboard: gate · Role-protected navigation into nutritionist routes.
- Route guard → Student dashboard: gate · Role-protected navigation into student routes.
- Route guard → Tutor dashboard: gate · Role-protected navigation into tutor routes.
- Route guard → University dashboard: gate · Role-protected navigation into university routes.
- Route guard → Admin area: gate · Highest-privilege routes are protected at the edge.
- Session auth → Admin area: redirects · Role-aware redirects steer users to the correct area.
- Supabase client → Clients hook: data access · Client hooks consume the shared Supabase client.
- Supabase client → Student hook: data access · Practice data hooks use the shared Supabase client.
- Supabase client → Client API: db/storage · API routes use the shared client for server-side operations.
- Supabase client → Metrics API: db/storage · Admin endpoints read privileged data through Supabase.
- Appointment schema → Anthro form: validate · Forms are validated before submission.
- Clients hook → Anthro form: feed UI · Clinical forms and lists are driven by client data hooks.
- Clients hook → Diet builder: feed UI · Diet workflows read and mutate client-linked records.
- Student hook → Field trips: feed UI · Student practice components consume student-patient state.
- Student hook → Meal review: feed UI · Tutor review screens consume practice-patient state.
- Notifications → Nutri dashboard: surface · Notifications are a shared cross-cutting UI surface.
- Diet builder → PDF export: export · Diet plans can be rendered into PDF outputs.
- Theme → Global styles: style base · Global theming and CSS form the shared presentation layer.
- Reminder job → Reminder function: trigger · The app-side job endpoint orchestrates the scheduled function.
- Schema & RLS → DB schema: define · Migrations and schema files together define the database boundary.
- Schema & RLS → Supabase client: persisted model · The client reads and writes the schema enforced by migrations and RLS.
- Metrics API → Admin metrics: serve · Admin UI is backed by privileged server data.
- Mock auth → Sign in: dev path · Local testing can bypass production auth flow.