# cubestar1/health-monitor-next architecture

> Architecture diagram of the GitHub repository cubestar1/health-monitor-next, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cubestar1/health-monitor-next
- Repository: https://github.com/cubestar1/health-monitor-next

## Overview

##### Project Type and Purpose
- HealthHub is a full-stack, AI-powered health data management platform.
- Frontend: Next.js 13 App Router (TypeScript/React)
- Backend: Next.js serverless API routes + external FastAPI (Python) service
- Data store: Supabase (PostgreSQL + pgvector)
- AI/ML: Langchain, OpenAI, Cohere embeddings, Gemini, HeyGen video

##### File Structure
- `app/` → Next.js pages & server components (app-router layout)
- `app/api/.../route.ts` → Next.js serverless endpoints
- `app/(auth)`, `(chat)`, `(health)`, `(marketing)` → route groups for major UX flows
- `components/`, `hooks/`, `lib/` → UI pieces, custom React hooks, configuration & Supabase clients
- `public/` → static assets (images for landing, dashboards)
- `actions/` → NextAuth/Supabase auth handlers
- No direct Python code here; the README points to a separate FastAPI repo

##### README Insights
- Real-time sensor data from Arduino/ESP8266 → streams into Supabase
- Medical-record ingestion pipeline (PyPDF2, Tesseract OCR) → Cohere embeddings → vector DB
- RAG pipeline via Langchain for chat assistant
- External integrations: Strava, Nutritionix, Tavily, Resend, HeyGen

##### Main System Components
a. Client Layer
- Web browser (React UI)
- Mobile Web / PWA
- Edge devices: Arduino/ESP8266 (sensor data producer)
b. Frontend Layer
- Next.js App (UI pages, layouts, global providers)
- React hooks and context for state, real-time subscriptions (Supabase JS)
c. API Layer (Next.js Serverless)
- app/api routes for chat, nutrition, health-reports, Strava, signup, RAG queries
- Auth middleware (Supabase)
- Proxy to Python FastAPI for heavy AI tasks
d. Backend Layer
- External FastAPI service
– Chat operations & RAG orchestration (Langchain)
– Medical record processing, embedding generation
e. Data Layer
- Supabase PostgreSQL + pgvector (vector DB extension)
- Supabase Auth
f. External Services
- AI: OpenAI, Cohere, Gemini, HeyGen
- Health APIs: Nutritionix, Strava, Tavily
- Email: Resend

##### Component Interactions
- Browser ↔ Next.js UI (React Server/Client components)
- UI ↔ Next.js API routes (REST/Route handlers)
- API routes ↔ Supabase (via server/client SDK) for real-time reads & writes
- API routes ↔ FastAPI backend (HTTP calls) for AI pipelines
- FastAPI ↔ External AI services (OpenAI, Cohere, Tavily, HeyGen)
- Arduino/ESP8266 → Supabase (direct PostgreSQL inserts or via an ingestion endpoint)
- UI ↔ External APIs (Strava OAuth & data) via dedicated API routes

##### Architectural Patterns & Principles
- Layered separation: UI / API / Backend / Data
- Serverless micro-endpoints (Next.js Route handlers)
- RAG microservice for AI tasks (FastAPI)
- Real-time event-driven flows via Supabase subscriptions
- Componentization in Next.js App Router (route groups & folders)

##### Technologies & Frameworks to Highlight
- Next.js 13 App Router, React Server Components
- Supabase JS & server SDK, Supabase Auth
- FastAPI (Python), Uvicorn
- Langchain RAG pipeline
- Vector DB (pgvector), Cohere embeddings
- OpenAI, Gemini, Tesseract, PyPDF2, Nutritionix, Tavily, HeyGen, Resend

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        BR["Web Browser"]:::ui
        PW["Mobile PWA"]:::ui
        AR["Arduino/ESP8266"]:::ui
    end

    subgraph "Next.js Frontend"
        direction TB
        NL["app/layout.tsx"]:::ui
        NP["app/page.tsx"]:::ui
        NG["app/globals.css"]:::ui

        subgraph "Auth Module"
            SA["Signin Page"]:::ui
            SR["Register Page"]:::ui
        end

        subgraph "Chat Module"
            CL["app/(chat)/layout.tsx"]:::ui
            CP["app/(chat)/chat/page.tsx"]:::ui
            CS["app/(chat)/chat-stream/page.tsx"]:::ui
        end

        subgraph "Health Module"
            DH["Dashboard Flow"]:::ui
            HH["Health Flow"]:::ui
        end

        subgraph "Marketing Module"
            ML["app/(marketing)/layout.tsx"]:::ui
            MA["app/(marketing)/about/page.tsx"]:::ui
            MI["app/(marketing)/ideation/page.tsx"]:::ui
            MP["app/(marketing)/pricing/page.tsx"]:::ui
            MPR["app/(marketing)/privacy/page.tsx"]:::ui
        end

        subgraph "Voice & Video"
            VA["Voice Assistant"]:::ui
            VD["app/(app)/video-assistant/page.tsx"]:::ui
        end

        subgraph "Global Components"
            TP["components/global/theme-provider.tsx"]:::ui
            QP["components/global/query-provider.tsx"]:::ui
            SB["components/global/app-sidebar.tsx"]:::ui
            LC["components/landing/"]:::ui
        end
    end

    subgraph "Next.js Serverless API"
        direction TB
        CSrv["app/api/chat/route.ts"]:::api
        COps["app/api/chat-operations/route.ts"]:::api
        CStr["app/api/chat-stream/route.ts"]:::api
        RQ["app/api/rag-query/route.ts"]:::api
        RQ2["app/api/rag-query-v2/route.ts"]:::api
        Nut["app/api/nutrition/route.ts"]:::api
        Cons["app/api/nutrition/consumed/route.ts"]:::api
        Daily["app/api/nutrition/daily/route.ts"]:::api
        Weekly["app/api/nutrition/weekly/route.ts"]:::api
        Monthly["app/api/nutrition/monthly/route.ts"]:::api
        HR["app/api/health-report/route.ts"]:::api
        Doc["app/api/documents/generate/route.ts"]:::api
        StrAuth["app/api/strava/auth/route.ts"]:::api
        StrAct["app/api/strava/activities/route.ts"]:::api
        Signup["app/api/signup/route.ts"]:::api
        Callback["app/api/auth/callback/route.ts"]:::api
        Hey["app/api/heygen-chat/route.ts"]:::api
        Token["app/api/get-access-token/route.ts"]:::api
        DBS["app/api/db-structure/route.ts"]:::api
    end

    FASTAPI["FastAPI AI Microservice"]:::micro

    subgraph "Supabase"
        Auth["Auth"]:::db
        PG["PostgreSQL + pgvector"]:::db
    end

    subgraph "External Services"
        OPENAI["OpenAI"]:::ext
        COHERE["Cohere"]:::ext
        GEMINI["Gemini"]:::ext
        HEYGEN["HeyGen"]:::ext
        NUTAP["Nutritionix"]:::ext
        STRAVA["Strava"]:::ext
        TAVILY["Tavily"]:::ext
        RESEND["Resend"]:::ext
    end

    BR -->|"HTTP/React"| NL
    PW -->|"HTTP/React"| NL
    AR -->|"Sensor Data"| PG
    NL -->|"REST Calls"| CSrv
    NL -->|"Realtime Subscriptions"| PG
    CSrv -->|"SQL Queries"| PG
    CSrv -->|"Proxy HTTP"| FASTAPI
    FASTAPI -->|"Embed & Store"| PG
    FASTAPI -->|"AI Calls"| OPENAI
    FASTAPI -->|"AI Calls"| COHERE
    FASTAPI -->|"AI Calls"| GEMINI
    FASTAPI -->|"Video Gen"| HEYGEN
    CSrv -->|"Nutrition API"| NUTAP
    CSrv -->|"Health API"| STRAVA
    CSrv -->|"Health API"| TAVILY
    CSrv -->|"Email"| RESEND

    click NL "https://github.com/cubestar1/health-monitor-next/blob/main/app/layout.tsx"
    click NP "https://github.com/cubestar1/health-monitor-next/blob/main/app/page.tsx"
    click NG "https://github.com/cubestar1/health-monitor-next/blob/main/app/globals.css"
    click SA "https://github.com/cubestar1/health-monitor-next/blob/main/app/(auth)/signin/page.tsx"
    click SR "https://github.com/cubestar1/health-monitor-next/blob/main/app/(auth)/register/page.tsx"
    click CL "https://github.com/cubestar1/health-monitor-next/blob/main/app/(chat)/layout.tsx"
    click CP "https://github.com/cubestar1/health-monitor-next/blob/main/app/(chat)/chat/page.tsx"
    click CS "https://github.com/cubestar1/health-monitor-next/blob/main/app/(chat)/chat-stream/page.tsx"
    click DH "https://github.com/cubestar1/health-monitor-next/tree/main/app/(app)/dashboard/"
    click HH "https://github.com/cubestar1/health-monitor-next/tree/main/app/(app)/health/"
    click ML "https://github.com/cubestar1/health-monitor-next/blob/main/app/(marketing)/layout.tsx"
    click MA "https://github.com/cubestar1/health-monitor-next/blob/main/app/(marketing)/about/page.tsx"
    click MI "https://github.com/cubestar1/health-monitor-next/blob/main/app/(marketing)/ideation/page.tsx"
    click MP "https://github.com/cubestar1/health-monitor-next/blob/main/app/(marketing)/pricing/page.tsx"
    click MPR "https://github.com/cubestar1/health-monitor-next/blob/main/app/(marketing)/privacy/page.tsx"
    click VA "https://github.com/cubestar1/health-monitor-next/tree/main/app/(app)/voice-assistant/"
    click VD "https://github.com/cubestar1/health-monitor-next/blob/main/app/(app)/video-assistant/page.tsx"
    click TP "https://github.com/cubestar1/health-monitor-next/blob/main/components/global/theme-provider.tsx"
    click QP "https://github.com/cubestar1/health-monitor-next/blob/main/components/global/query-provider.tsx"
    click SB "https://github.com/cubestar1/health-monitor-next/blob/main/components/global/app-sidebar.tsx"
    click LC "https://github.com/cubestar1/health-monitor-next/tree/main/components/landing/"
    click CSrv "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/chat/route.ts"
    click COps "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/chat-operations/route.ts"
    click CStr "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/chat-stream/route.ts"
    click RQ "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/rag-query/route.ts"
    click RQ2 "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/rag-query-v2/route.ts"
    click Nut "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/nutrition/route.ts"
    click Cons "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/nutrition/consumed/route.ts"
    click Daily "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/nutrition/daily/route.ts"
    click Weekly "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/nutrition/weekly/route.ts"
    click Monthly "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/nutrition/monthly/route.ts"
    click HR "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/health-report/route.ts"
    click Doc "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/documents/generate/route.ts"
    click StrAuth "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/strava/auth/route.ts"
    click StrAct "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/strava/activities/route.ts"
    click Signup "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/signup/route.ts"
    click Callback "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/auth/callback/route.ts"
    click Hey "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/heygen-chat/route.ts"
    click Token "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/get-access-token/route.ts"
    click DBS "https://github.com/cubestar1/health-monitor-next/blob/main/app/api/db-structure/route.ts"

    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef api fill:#DFF2BF,stroke:#6b8e23,color:#6b8e23;
    classDef micro fill:#FFEFB4,stroke:#d2691e,color:#d2691e;
    classDef db fill:#E0BBE4,stroke:#800080,color:#800080;
    classDef ext fill:#EEEEEE,stroke:#666666,color:#666666;
```
