PetPal / VetPal
Structured AI Platform for Pet Nutrition & Veterinary Workflow Exploration
“AI as one capability inside a data-rich, authenticated product — not as the database or the sole decision layer.”
The workflow problem and what changed
Organisation & workflow
A full-stack product exploring personalised pet-nutrition guidance and related guardian and veterinary workflows.
What was difficult
Useful guidance depends on structured profiles, conditions, weight, allergies, ingredients, recipes and role-based access—not a single chat exchange.
What changed
The product organises these data and workflow modules inside an authenticated application, with AI used as one bounded capability.
Why it mattered
Recommendations could be connected to structured information, rules and user roles rather than relying on an unguided chatbot as the product.
Relational Core & Satellite Domain Topology
Strict separation of schema storage, isolated domain execution micro-modules, and Row Level Security isolation between Owner and Veterinary surfaces.
Health & Condition Tracker
Recorded health conditions, relevant markers and chronological health history.
Weight History & Energy Ledger
Daily energy requirement (DER) calculations, MER formulas, historical trajectory curves.
Allergy & Sensitivity Matrix
Direct allergen matching, cross-reactivity flags, and hard ingredient exclusion filters.
Core Structured Pet Profile & Relational Schema
Structured profile record covering species, life stage, body condition scores, neutered status and recorded biometric history.
Ingredient & Recipe Engine
Macronutrient calibration, moisture density analysis, and gram-precise portion calculation.
AI Nutrition Guidance Engine
OpenAI API driven by schema-constrained system prompts. Strictly bounded contextual reasoning.
Vet Clinical Portal & Services
Prescription diet approvals, asynchronous triage, appointment records, and shared audit trail.
The Challenge
Why isolated conversational AI is a poor fit for structured pet-health and nutrition workflows.
Personalized pet-nutrition guidance is not a simple chat interaction. It depends on structured profile history, recorded conditions, life-stage calculations, ingredient constraints and review status.
Conversational Amnesia & Hallucination
General language models may treat each query in isolation or rely on incomplete conversational context. A nutrition workflow therefore needs to check recorded conditions and ingredient constraints before presenting a suggestion.
Mathematical Precision vs Probability
Daily Energy Requirement (DER) is deterministic: RER = 70 * (weight_kg)^0.75 multiplied by physiological factors. LLMs are probabilistic token predictors, not reliable arithmetic engines.
Comparative Architectural Failure Mode
User prompts: "Can my 8kg terrier eat pork chops?" → LLM responds generically with "Yes, in moderation" without cross-checking the dog's recent pancreatitis flare-up or sodium restriction profile in the clinic database.
System queries the structured profile → detects a recorded condition flag → blocks a conflicting suggestion → routes the item for an alternative or review.
The Thinking
Architectural principles that position AI as a bounded utility within a structured system.
Core Engineering Postulate
Treat AI as one capability inside a structured application, rather than as the database or sole decision layer. Core calculations, access rules and structured data remain separate from the AI subsystem.
Structured Pet Data Sovereignty
Key attributes—from body condition scoring and caloric targets to documented allergies—are stored in relational tables rather than relying only on chat history.
Row Level Security (RLS) Isolation
Row-level access policies scope guardian access to their records and clinic-role access to assigned records.
Decoupled Tripartite Architecture
Clean separation between the Next.js presentation tier, Express API validation pipelines, and relational storage. Complex caloric arithmetic happens in tested domain libraries, not UI components.
Dual-Portal Single Foundation
Pet owners use nutritional tracking while vet-facing roles can review health notes, diet-related workflows and activity history over the same structured records.
The Solution
Deep dive into five capability areas designed to support structured pet-nutrition guidance workflows.
A full-stack web application designed for pet guardians and vet-facing workflows. AI synthesis is prompted with stored recipe rules and profile history, while calculations remain outside the language model.
Longitudinal Pet Profile & Caloric Ledger
Tracks weight history over time and applies stored Resting Energy Requirement (RER) and Daily Energy Requirement (DER) formulas.
Allergen & Contraindication Matrix
Rule-based exclusion checks compare meal suggestions with stored ingredient and allergy constraints before presentation.
Schema-Constrained Prompt Injection
Requests pass through an Express backend that retrieves the relevant profile record, applies stored limits and supplies structured context to the language model.
"patient_id": "d3b07384-d113-...",
"caloric_cap_kcal": 1328,
"hard_exclusions": ["beef", "dairy", "high_sodium"],
"macronutrient_ratios": { "protein_pct": 28, "fat_pct": 12 },
"vet_oversight_status": "approved_diet_protocol"
}
PetPal: Guardian Self-Service Portal
Daily management features include meal logging, weight updates, treat counters and feeding schedules based on stored profile information.
- Portion converter based on target kibble density
- Daily caloric budget meter with treat allowance breakdown
- AI conversational inquiries backed by stored profile and health data
VetPal: Clinical Oversight & Audit
Role-based dashboard concept for vet-facing users to review feeding records, diet-plan information and proposed nutritional modifications.
- Multi-patient review and activity tracking
- Diet-plan review states and approval workflow concepts
- Integrated notes with timestamped revision history
System Architecture & Stack
Separation of concerns across presentation, routing, validation, database access and AI invocation.
Next.js 15 · React Server Components
TypeScript end-to-end. Leverages Server Components for fast server-rendered initial biometrics state, reducing client bundle weight and preventing layout shifts.
Node.js · Express RESTful Engine
Structured domain routing with runtime schema validation (Zod). Enforces request shape integrity, sanitizes telemetry payloads, and acts as the gatekeeper for AI calls.
Supabase PostgreSQL · RLS Policies
PostgreSQL schema with native Row Level Security. Granular authorization rules scope records and meal plans to authenticated guardians and authorised clinic roles.
OpenAI API · Jest · Docker
Bounded AI request pipelines. Jest unit and integration tests cover stored formulas and authorization behaviour. Containerized development environments support repeatable setup.
Outcome & Engineering Value
Summary of accomplishments and foundational competencies established by the PetPal / VetPal build.
Architectural Conclusion
PetPal / VetPal stands as a working demonstration of how modern AI capabilities belong inside a structured, authenticated product architecture. By anchoring AI recommendations to a relational schema guarded by multi-tenant Row Level Security and deterministic calculation services, the system eliminates the acute safety risks inherent in chat-first approaches.
Competencies Demonstrated
Complex Relational Data Modeling for Multi-Entity Domains
Modelled related entities across pet guardians, clinic roles, health events and dietary recipes using relational schemas and scoped services.
Modular API Design & Clean Separation of Concerns
Structured an Express API with explicit Data Transfer Objects (DTOs), strict runtime payload sanitization, and decoupled domain services ensuring mathematical formulas stay isolated from presentation logic.
Authenticated, RLS-Aware Data Architecture
Moves record-access rules closer to the data layer through PostgreSQL Row Level Security policies.
Full-Stack Product Thinking Balancing UX with Structured Domain Rules
Combined an approachable interface for pet owners logging meals with structured review workflows for vet-facing roles.
AI as a Bounded Utility Within a Structured System
Demonstrates context-grounded meal-planning guidance where the language model supports natural-language synthesis while calculations and stored constraints remain outside the model.
Have a similar workflow or systems problem?
If AI needs to work inside a structured, authenticated product rather than as a standalone chatbot, we can map the data, rules, and user workflows first.