How nutri-vision/frontend works
Project type and purpose
• From the file tree and README, this is a full-stack, medical-grade, PWA nutrition dashboard built on Next.js 14.
• Its purpose is to let users securely log food (text, image, voice, barcode), analyze nutrition against medical conditions, and view AI-powered health insights via a responsive, HIPAA-compliant interface.
File structure
Top-level breakdown:
• app/ – Next.js App Router pages and layouts (Server & Client Components)
• components/ – Reusable React UI pieces (including custom health flows and main dashboard widgets)
• components/ui/ – Shadcn/ui–based atomic UI primitives
• hooks/ – Custom React hooks (use-mobile, use-toast)
• lib/ – Utility functions (e.g., encryption, date formatting)
• public/ – Static assets and PWA manifest
• styles/ – Global CSS (Tailwind) and configuration
• config files – next.config.mjs, tailwind.config.ts, tsconfig.json, postcss.config.mjs
• package.json and locks – Defines dependencies: React, Next.js, Tailwind, Recharts, React Hook Form, crypto-js, speech, Radix UI, etc.
README for additional insights
• Frontend stack: Next.js 14 (App Router & Server Components), TypeScript, Tailwind, Shadcn/ui, Recharts, React Hook Form.
• Security: NextAuth for auth, AES-256, end-to-end encryption, zero-knowledge.
• External integrations: OpenAI, Vision API, Speech API, Nutrition API, Drug Interaction API, FHIR server, HL7.
• Data stores: Relational DB (DATABASE_URL), Redis cache, third-party healthcare services.
• PWA: Offline, service worker, push notifications.
a. Main components
• Client (Browser or Mobile)
– PWA shell (Service Worker, IndexedDB cache)
– Next.js React UI (app router, layouts, pages)
– UI Components (dashboard, onboarding, logging flows)
• Next.js Server (Vercel Node Server or Self-hosted)
– Server Components & API routes (NextAuth, server-side data fetching)
– Authentication & Authorization layer (NextAuth + encryption)
– Business Logic layer (Onboarding, Logging, Dashboard, Profile)
• Data Layer
– Primary Database (e.g., Postgres)
– Redis cache for session & alerts
– File store for uploaded images
• External Services
– AI Services: OpenAI (NLP), Vision API (image recognition), Speech API (voice logging)
– Medical APIs: Nutrition API, Drug Interaction API
– Healthcare Integration: FHIR Server, HL7 endpoints
• Monitoring & Support
– Sentry for errors, Web Vitals for performance, security scanners
b. Relationships & interactions
• Browser ←→ Next.js Server: SSR/SSG data requests, hydration, PWA sync
• Next.js Server → Database/Redis: CRUD for user profiles, logs, sessions
• Next.js Server → External AI & Medical APIs: meal recognition, interaction checks, recommendations
• Next.js Server → FHIR / HL7: provider data exchange
• Service Worker ↔ IndexedDB: offline reads/writes and background sync
c. Architectural patterns & principles
• Separation of concerns: UI layer vs. server/business logic vs. data store
• App Router with Server & Client Components for optimized data fetching
• PWA offline-first pattern with service workers
• Zero-knowledge encryption boundary around sensitive data
• Micro-layering: Authentication service, Logging service, Analytics service, Profile service
d. Key technologies & frameworks
• Next.js 14 App Router
• TypeScript, Tailwind CSS, Shadcn/ui, Recharts, React Hook Form
• NextAuth for security
• Redis for caching
• OpenAI, Vision, Speech SDKs
• FHIR & HL7 for healthcare