Unitrition Architecture Deep-Dive: Engineering a Headless HealthTech & Precision Nutrition Platform with Next.js 16, WordPress & Supabase
Executive and technical breakdown of Unitrition (unitrition.info): decoupling WordPress CMS from Next.js 16 App Router, integrating USDA FoodData Central API for real-time Bread Units and glycemic curve modeling across 10 clinical diet frameworks, and securing user data with Supabase RLS.

1. Executive Summary & The HealthTech Challenge
Patients and health-conscious individuals managing strict dietary protocols (such as Type 1/Type 2 Diabetes, Ketogenic, Low-FODMAP, or Renal diets) face a daily cognitive burden: cross-referencing raw nutrition labels against complex clinical guidelines and manually calculating Bread Units (BU / Carbohydrate Exchanges) and glycemic load.
Meanwhile, traditional medical portals built on monolithic CMS templates suffer from slow mobile performance when querying large nutritional databases and lack interactive client-side modeling tools.
Unitrition (unitrition.info) was engineered to bridge clinical nutrition data and modern fullstack performance. By combining Headless WordPress, Next.js 16 App Router (React 19), Supabase PostgreSQL, and the U.S. Department of Agriculture (USDA) FoodData Central API, the platform delivers sub-second food compatibility scoring across 10 dietary frameworks, real-time Bread Units calculation, and interactive glycemic curve visualizations.
2. Architecture Decision Records (ADR - Why We Chose This Stack)
| Architectural Decision | Rejected Alternative | Engineering & Business Rationale |
|---|---|---|
| Hybrid Headless Stack (Next.js 16 + Headless WordPress REST API) | Monolithic PHP WordPress Theme with Custom AJAX | Nutritionists and medical editors keep the familiar WordPress/ACF Pro editorial workflow, while end users get a blazing-fast React 19 App Router frontend with 95+ PageSpeed and zero PHP template bottlenecks. |
| Supabase PostgreSQL + Auth for User Profiles | Storing User Accounts Inside WordPress wp_users | Decoupling user authentication and personal diet logs into Supabase with Row Level Security (RLS) prevents WordPress plugin vulnerabilities from ever exposing sensitive user health preferences. |
| Next.js Server-Side Proxy for USDA FoodData API | Direct Client-Side fetch() to USDA API | Protects the private USDA API key from client exposure, normalizes inconsistent third-party JSON schemas on the server, and applies edge caching to prevent rate-limit exhaustion. |
| Bilingual Route & Schema.org Graph (`EN / ES`) | Client-Only Translation Strings without URL Routing | Dedicated localized URLs with hreflang alternates and medical/nutrition Schema.org structured data maximize organic discovery across English and Spanish search markets. |
wp_usersfetch() to USDA APIhreflang alternates and medical/nutrition Schema.org structured data maximize organic discovery across English and Spanish search markets.3. Core Mechanisms: How Unitrition Works Under the Hood
Mechanism 1: The USDA FoodData Central Proxy & Nutrient Normalization Pipeline
The USDA FoodData Central database contains ratusan of thousands of food items (Foundation Foods, SR Legacy, Branded Foods), each reporting nutrients in slightly different nested structures and unit IDs (e.g., Energy in kcal vs kJ, Total Carbohydrate by difference, Dietary Fiber, Total Sugars).
When a user searches for an ingredient in Unitrition:
NormalizedFoodItem interface.stale-while-revalidate headers so popular food lookups resolve in under 30ms.// Conceptual blueprint of the Bread Units (BU) & Net Carbs calculation
export interface NormalizedMacros {
caloriesKcal: number
totalCarbsGrams: number
dietaryFiberGrams: number
sugarsGrams: number
proteinGrams: number
fatGrams: number
}
export function calculateBreadUnits(macros: NormalizedMacros, portionGrams: number) {
const factor = portionGrams / 100
const digestibleCarbs = Math.max(0, (macros.totalCarbsGrams - macros.dietaryFiberGrams) * factor)
// 1 Bread Unit (BU) = 12g of digestible carbohydrates
const breadUnits = Number((digestibleCarbs / 12).toFixed(2))
return { digestibleCarbs: Number(digestibleCarbs.toFixed(1)), breadUnits }
}Mechanism 2: Deterministic 10-Diet Traffic-Light Scoring Engine
Rather than relying on slow or unpredictable LLM calls to judge whether a food fits a diet, Unitrition uses a deterministic clinical rule matrix across 10 diet protocols:
- Each diet profile defines strict macronutrient ratios, glycemic load ceilings, and excluded food groups.
- When a user selects a diet plan and searches foods, the engine computes a color-coded compatibility score:
- Green (Optimal Fit): Within macro targets and low glycemic impact.
- Amber (Moderate / Portion Control): Requires strict portion scaling based on calculated Bread Units.
- Red (Avoid): Exceeds carbohydrate/sodium/lipid thresholds for the active protocol.
Mechanism 3: Continuous Glucose Monitoring (CGM) Curve Simulation & PDF Export
To help users visualize *why* fiber and protein slow down glucose absorption compared to refined sugars, Unitrition includes an interactive Glycemic Response Simulator:
- Based on the ratio of digestible carbohydrates, dietary fiber, fat, and protein in the selected portion, the engine models the projected postprandial glucose curve over a 180-minute window.
- Users can compile their selected foods and meal calculations into a clean, print-ready PDF Nutrition Report directly in the browser.
Mechanism 4: Decoupled Editorial CMS via Headless WordPress & ISR
Educational nutrition articles and clinical guides are managed in a hardened headless WordPress instance using Advanced Custom Fields (ACF Pro):
- Next.js fetches structured post payloads via the WP REST API during build and Incremental Static Regeneration (ISR).
- Every article automatically generates Schema.org `Article` and `FAQPage` JSON-LD markup to capture medical and dietary search snippets.
4. Engineering Glossary: Every Key Term Explained
- Headless CMS Architecture:
- *What it is*: Separating the back-end content management panel (WordPress) from the front-end presentation layer (Next.js).
- *Why it matters*: Content editors work in a familiar interface, while visitors experience instant React page transitions and superior security because the CMS admin panel is hidden from public traffic.
- Incremental Static Regeneration (ISR):
- *What it is*: A Next.js mechanism that updates static pages in the background after deployment when CMS content changes, without rebuilding the entire site.
- *Why it matters*: Combines the speed of static HTML with the freshness of a dynamic database.
- Bread Units (BU / Carbohydrate Exchange):
- *What it is*: A clinical unit used in nutrition and diabetes management (1 BU equals 10g-12g of digestible carbohydrates) to estimate insulin requirements and glycemic impact.
- *Why it matters*: Automating BU calculation across variable gram portions eliminates manual math errors for users.
- Server-Side API Proxy:
- *What it is*: An intermediate backend endpoint that forwards client requests to an external service (USDA API), attaches secret keys on the server, and sanitizes the response.
- *Why it matters*: Prevents API key theft and insulates the frontend from third-party API breaking changes.
- Supabase Row Level Security (RLS):
- *What it is*: Fine-grained access control inside PostgreSQL that enforces
auth.uid() = user_idon every database query. - *Why it matters*: Ensures one user can never read or modify another user's saved dietary profile.
5. Defense-in-Depth Security Posture
Where This Architecture is Deployed in Production
These architectural patterns are not abstract theory - they are fully deployed and benchmarked in these live production builds:
Custom Web Development for Businesses & Clinics in Seville & Spain
Fast, accessible, client-generating websites for businesses, clinics, and professional firms in Seville and across Spain. Zero slow page builders and zero hidden fees.
Planning a tech stack migration or new build?
Discuss architectural requirements with my interactive RAG AI assistant or connect directly for an engineering assessment.
Related Engineering Articles
Next.js 16 vs Headless WordPress vs Custom PHP: Objective TCO, Performance & SEO Analysis (2026)
An engineering breakdown comparing architecture, maintenance overhead, Total Cost of Ownership (TCO), and Google Core Web Vitals across Next.js 16, Headless WordPress, and custom PHP.
Fullstack AI Lab Architecture Deep-Dive: Compiling 1,135+ MDX Lessons in 90 Seconds with Next.js 16 & Rust MDX-RS
Complete executive and technical breakdown of the Fullstack AI Lab interactive engineering platform: how we cut SSG build times by 14x (from 21.6m to 1.5m), engineered an in-browser WebAssembly WordPress sandbox, an AI Technical Interview Engine, interactive runtime simulators, and a zero-metaphor NotebookLM audio engine.