D2. Design Document

Explains the core ideas behind the code so a new developer can work with it confidently.

1: Architecture Diagram

Architecture Diagram

2. Code Repository and README

2.1: Repository Information

Repository URL: https://github.com/ethanbonsall/Pediatric-Blue-Book

The complete source code is archived in this GitHub repository. It contains all application code, configuration files, tests, and documentation needed to build and deploy the system.


2.2: README: How to build the system

Tech Stack

  • Framework: Next.js
  • Language: TypeScript
  • UI: React, Tailwind CSS, shadcn/ui
  • Backend: Supabase
  • Testing: Jest
  • Deployment: Vercel
  • Domain: Namecheap

Running the project locally

  • Clone repository:
    git clone https://github.com/ethanbonsall/Pediatric-Blue-Book.git
  • Navigate to web directory:
    cd pediatric-blue-book
    cd web
  • Install dependencies:
    npm install --force
  • Create .env.local file with Supabase keys inside /web
  • Run development server:
    npm run dev
  • The app will be available at http://localhost:3000/

Testing

Tests are written with Jest and stored in __tests__/.

  • Run tests:
    npm test
  • Watch mode:
    npm test:watch

2.3: Module Structure

modules

Module relationships

  • pages/ (index.tsx, admin.tsx, profile.tsx) import components/ui/ to build page UI
  • pages/_app.tsx wraps entire app, imports components/context/themecontext.tsx for global state
  • components/ui/ components import components/lib/types.ts for TypeScript types
  • All components use components/lib/supabase.tsx for database access
  • components/ui/ use components/lib/utils.ts for helper functions
  • app/api/delete-user/route.ts handles backend API logic
  • __tests__/ test files import components and run Jest tests
  • All .tsx/.ts files use TypeScript for type safety
  • Styling uses Tailwind CSS (configured in tailwind.config.ts)

3. Detailed Data Definitions

Database Schema

Tables:users

Purpose: User profile information

Column NameData TypeDescription
created_atTimestamp with timezoneAccount creation timestamp
first_nametextUser's first name
emailtextUser email address
titletextUser title or position
idUUIDPrimary key, unique user identifier
roletextUser role or permissions

Tables:nutrient needs

Purpose: Nutrient requirements for users

Column NameData TypeDescription
idbigintnutrient identifier
created_atTimestamp with timezoneTimestamp of nutrient added
nutrienttextNutrient name
age_bottomdouble precisionMinimum age for nutrient requirement
age_topdouble precisionMaximum age for nutrient requirement
amountdouble precisionrequired amount
measurement_typetextMeasurement type for nutrient amount
activity_leveltextActivity level for nutrient requirement
needs_typetextType of nutrient required
sextextSex of patient

Tables:ingredients

Purpose: recipe ingredients

The ingredient list for the formulas.

Column NameData TypeDescription
producttextProduct name
company_brandtextCompany or brand name
agetextAge group
notestextany notes
iduuidid of the product
activebooleanif active or not
approvedbooleanif approved or not
protein_sourcestextSources of protein
carbohydrate_sourcestextSources of carbohydrates
fat_sourcestextSources of fat
prebiotic_sourcestextSources of prebiotics
probiotic_sourcestextprobiotic sources
specialty_ingredientstextSpecialty ingredients
grams_per_scoopdouble precisionper scoop amount
grams_per_teaspoondouble precisionper teaspoon amount
grams_per_tablespoondouble precisionper tablespoon amount
grams_per_cupdouble precisionper cup amount
calories_per_gramdouble precisioncalories per gram
np100_total_protein_gdouble precisiontotal protein amount
np100_total_fat_gdouble precisiontotal fat amount
np100_total_carbohydrate_gdouble precisiontotal carbohydrate amount
np100_water_ml_standarddouble precisionstandard water amount in ml
np100_vitamin_a_mcg_redouble precisiontotal vit a amount
np100_vitamin_d_mcgdouble precisiontotal vit d amount
np100_vitamin_e_mgdouble precisiontotal vit e amount
np100_vitamin_k_mcgdouble precisiontotal vit k amount
np100_thiamin_mgdouble precisiontotal thiamin amount
np100_riboflavin_mgdouble precisiontotal riboflavin amount
np100_niacin_mgdouble precisiontotal niacin amount
np100_b6_mgdouble precisiontotal b6 amount
np100_b12_mcgdouble precisiontotal b12 amount
np100_vitamin_c_mgdouble precisiontotal vitamin c amount
np100_folic_acid_mcgdouble precisiontotal folic acid amount
np100_biotin_mcgdouble precisiontotal biotin amount
np100_pantothenic_acid_mgdouble precisiontotal pantothenic acid amount
np100_choline_mgdouble precisiontotal choline amount
np100_inositol_mgdouble precisiontotal inositol amount
np100_sodium_mgdouble precisiontotal sodium amount
np100_potassium_mgdouble precisiontotal potassium amount
np100_chloride_mgdouble precisiontotal chloride amount
np100_calcium_mgdouble precisiontotal calcium amount
np100_phosphorus_mgdouble precisiontotal phosphorus amount
np100_iron_mgdouble precisiontotal iron amount
np100_zinc_mgdouble precisiontotal zinc amount
np100_magnesium_mgdouble precisiontotal magnesium amount
np100_iodine_mcgdouble precisiontotal iodine amount
np100_manganese_mgdouble precisiontotal manganese amount
np100_selenium_mcgdouble precisiontotal selenium amount
np100_chromium_mcgdouble precisiontotal chromium amount
np100_molybdenum_mcgdouble precisiontotal molybdenum amount
np100_copper_mgdouble precisiontotal copper amount
probiotictexttotal probiotic amount
allergenstextany allergens
displacement_ml_per_gdouble precisiondisplacement amount
np100_standard_volumedouble precisionvolume of the fomula
npc_percent_free_waternumericpercentage of water
npc_percent_cal_from_chonumericpercentage of calories from carbohydrates
npc_percent_cal_from_fatnumericpercentage of calories from fat
npc_percent_cal_from_proteinnumericpercentage of calories from protein
np100_fluoride_mgdouble precisiontotal fluoride amount
np100_fiber_gdouble precisiontotal fiber amount

4. Design Rationale

4.1: Technology choices

  • TypeScript: compile-time type safety, better IDE support, clearer refactoring and documentation.
  • Next.js: team familiarity, SSR/SSG for performance/SEO, built-in API routes, seamless Vercel deploys.
  • Supabase: PostgreSQL (relational queries), row-level security for HIPAA, open-source/self-host option, SQL familiarity.
  • Vercel: team experience, automatic SSL & CI/CD, Next.js-optimized, free tier for launch.
  • Testing: Jest
  • Tailwind CSS: fast development with utility classes, team expertise, small purged bundles and consistent design.

4.2: Architechture

Three-layer separation (Presentation / Business Logic / Data Access) for defense-in-depth, clearer code, and HIPAA-compliant data isolation.


4.3: Data model

Soft delete (is_active)to meet retention/audit requirements and allow restores.

JSONB for input/outputto support evolving calculation schemas without migrations and keep good performance.

Separate calculations tableto preserve immutable history, enable comparisons and auditing.


4.4: Dependencies (core)

Next.js ^14, React ^18, TypeScript ^5, Supabase Client ^2.38, Tailwind CSS ^3.3, Zod ^3.22, Jest ^29 — chosen for stability, team familiarity, and features needed for secure, testable medical calculations.