# dropensource/mediq architecture

> Architecture diagram of the GitHub repository dropensource/mediq, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dropensource/mediq
- Repository: https://github.com/dropensource/mediq

## Overview

This monorepo contains three user-facing products: MediQ for personal health tracking, a gym-member app for logging training and body measurements, and a gym-owner dashboard for managing members, exercises, and programs. The visible member logging flow routes chat input through intent and exercise-resolution logic, then saves exercise or body-composition data. MediQ’s tree shows broader health, diet, insights, reports, and cycle-tracking capabilities. Edges are limited to relationships shown in excerpts or SOURCE INDEX references; some feature internals and integrations are unsampled.

Main entry points: [`apps/gym-member/src/features/logChat/store/useLogChatStore.ts`](https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/features/logChat/store/useLogChatStore.ts) (Chat logging), [`apps/mediq/src/shared/hooks/useHealthMetricsDirect.ts`](https://github.com/dropensource/mediq/blob/main/apps/mediq/src/shared/hooks/useHealthMetricsDirect.ts) (Health metrics), [`apps/gym-owner-dashboard/src/lib/supabase.ts`](https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/lib/supabase.ts) (Dashboard data client), [`apps/gym-owner-dashboard/src/app/exercises/page.tsx`](https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/app/exercises/page.tsx) (Exercise management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_member["Gym Member"]
  node_log_chat["Chat logging<br/>[useLogChatStore.ts]"]
  node_exercise_flow["Exercise dialogue"]
  node_intent["Intent detection<br/>[intentDetector.ts]"]
  node_exercise_catalog["Exercise catalog"]
  node_exercise_log["Exercise records"]
  node_body_service["Body measurements<br/>[bodyCompService.ts]"]
  node_member_profile["Health profile"]
  node_body_engine["Composition engine"]
  node_gym_session[("Gym session state")]
end

subgraph group_owner["Gym Management"]
  node_owner_exercises["Exercise management<br/>[page.tsx]"]
  node_owner_auth["Owner authentication<br/>[AuthContext.tsx]"]
  node_owner_members["Member management<br/>[membersService.ts]"]
  node_owner_programs["Program management<br/>[programsService.ts]"]
  node_owner_db_client["Dashboard data client<br/>[supabase.ts]"]
end

subgraph group_mediq["MediQ Health"]
  node_mediq_metrics["Health metrics"]
  node_mediq_health_data["Health data services"]
  node_mediq_dashboard["Health dashboard"]
  node_mediq_diet["Diet tracking"]
  node_mediq_insights["Insights and trends"]
  node_mediq_reports["Report upload"]
  node_report_storage["Report storage<br/>[storageService.ts]"]
  node_mediq_chatbot["Health chatbot"]
  node_chat_rules["Chat rule engine<br/>[ruleEngine.ts]"]
  node_lab_matcher["Lab test matcher<br/>[labTestMatcher.ts]"]
  node_cycle_tracker["Cycle tracking"]
end

subgraph group_shared["Shared Data"]
  node_auth_context["MediQ auth state<br/>[AuthContext.tsx]"]
  node_profile_context["Profile state<br/>[ProfileContext.tsx]"]
  node_sync_context["Sync progress state"]
  node_data_package["Data and auth package"]
end

node_member_actor(("Gym member"))
node_owner_actor(("Gym owner"))
node_patient(("MediQ user"))
node_supabase[("Supabase")]
node_cognito["Amazon Cognito"]

node_member_actor -.->|"logs activity"| node_log_chat
node_log_chat -->|"detects intent"| node_intent
node_log_chat -->|"routes exercise turns"| node_exercise_flow
node_exercise_flow -->|"resolves exercises"| node_exercise_catalog
node_log_chat -->|"saves exercise"| node_exercise_log
node_log_chat -->|"saves measurements"| node_body_service
node_body_service -->|"uses profile data"| node_member_profile
node_member_profile -->|"records composition"| node_body_engine
node_owner_actor -.->|"manages exercises"| node_owner_exercises
node_owner_exercises -->|"checks access"| node_owner_auth
node_owner_exercises -->|"loads catalog"| node_owner_db_client
node_owner_members -->|"queries members"| node_owner_db_client
node_owner_programs -->|"queries programs"| node_owner_db_client
node_owner_auth -->|"authenticates"| node_cognito
node_owner_auth -->|"syncs user context"| node_owner_db_client
node_patient -.->|"reviews health"| node_mediq_dashboard
node_mediq_metrics -->|"reads user state"| node_auth_context
node_mediq_metrics -->|"reads active profile"| node_profile_context
node_mediq_metrics -->|"fetches summaries"| node_mediq_health_data
node_mediq_dashboard -.->|"presents metrics"| node_mediq_metrics
node_mediq_reports -.->|"uploads reports"| node_report_storage
node_report_storage -->|"stores files"| node_supabase
node_mediq_chatbot -.->|"matches requests"| node_chat_rules
node_chat_rules -->|"matches test names"| node_lab_matcher
node_auth_context -->|"uses auth services"| node_data_package
node_sync_context -.->|"tracks sync"| node_mediq_metrics

click node_log_chat "https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/features/logChat/store/useLogChatStore.ts"
click node_exercise_flow "https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/features/logChat/engine/exerciseChatFlow.ts"
click node_intent "https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/features/logChat/engine/intentDetector.ts"
click node_exercise_catalog "https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/services/exerciseCatalogService.ts"
click node_exercise_log "https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/services/exerciseLogService.ts"
click node_body_service "https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/services/bodyCompService.ts"
click node_member_profile "https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/services/healthProfileService.ts"
click node_body_engine "https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/services/bodyCompositionEngine.ts"
click node_gym_session "https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/store/useGymSessionStore.ts"
click node_owner_exercises "https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/app/exercises/page.tsx"
click node_owner_auth "https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/contexts/AuthContext.tsx"
click node_owner_members "https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/services/membersService.ts"
click node_owner_programs "https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/services/programsService.ts"
click node_owner_db_client "https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/lib/supabase.ts"
click node_mediq_metrics "https://github.com/dropensource/mediq/blob/main/apps/mediq/src/shared/hooks/useHealthMetricsDirect.ts"
click node_mediq_health_data "https://github.com/dropensource/mediq/tree/main/apps/mediq/src/shared/services"
click node_mediq_dashboard "https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/dashboard"
click node_mediq_diet "https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/diet"
click node_mediq_insights "https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/insights"
click node_mediq_reports "https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/upload"
click node_report_storage "https://github.com/dropensource/mediq/blob/main/apps/mediq/src/features/upload/services/storageService.ts"
click node_mediq_chatbot "https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/chatbot"
click node_chat_rules "https://github.com/dropensource/mediq/blob/main/apps/mediq/src/features/chatbot/engine/ruleEngine.ts"
click node_lab_matcher "https://github.com/dropensource/mediq/blob/main/apps/mediq/src/features/chatbot/services/labTestMatcher.ts"
click node_cycle_tracker "https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/period-tracker"
click node_auth_context "https://github.com/dropensource/mediq/blob/main/apps/mediq/src/shared/context/AuthContext.tsx"
click node_profile_context "https://github.com/dropensource/mediq/blob/main/apps/mediq/src/shared/context/ProfileContext.tsx"
click node_sync_context "https://github.com/dropensource/mediq/blob/main/apps/mediq/src/shared/context/SyncProgressContext.tsx"
click node_data_package "https://github.com/dropensource/mediq/tree/main/packages/data/src"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_log_chat,node_exercise_flow,node_intent,node_exercise_catalog,node_exercise_log,node_body_service,node_member_profile,node_body_engine,node_gym_session,node_patient toneBlue
class node_owner_exercises,node_owner_auth,node_owner_members,node_owner_programs,node_owner_db_client,node_supabase toneAmber
class node_mediq_metrics,node_mediq_health_data,node_mediq_dashboard,node_mediq_diet,node_mediq_insights,node_mediq_reports,node_report_storage,node_mediq_chatbot,node_chat_rules,node_lab_matcher,node_cycle_tracker toneMint
class node_auth_context,node_profile_context,node_sync_context,node_data_package toneRose
class node_member_actor,node_owner_actor,node_cognito toneIndigo
```

## Components

### Gym Member

- [Chat logging](https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/features/logChat/store/useLogChatStore.ts): `apps/gym-member/src/features/logChat/store/useLogChatStore.ts`
- [Exercise dialogue](https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/features/logChat/engine/exerciseChatFlow.ts): `apps/gym-member/src/features/logChat/engine/exerciseChatFlow.ts`
- [Intent detection](https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/features/logChat/engine/intentDetector.ts): `apps/gym-member/src/features/logChat/engine/intentDetector.ts`
- [Exercise catalog](https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/services/exerciseCatalogService.ts): `apps/gym-member/src/services/exerciseCatalogService.ts`
- [Exercise records](https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/services/exerciseLogService.ts): `apps/gym-member/src/services/exerciseLogService.ts`
- [Body measurements](https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/services/bodyCompService.ts): `apps/gym-member/src/services/bodyCompService.ts`
- [Health profile](https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/services/healthProfileService.ts): `apps/gym-member/src/services/healthProfileService.ts`
- [Composition engine](https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/services/bodyCompositionEngine.ts): `apps/gym-member/src/services/bodyCompositionEngine.ts`
- [Gym session state](https://github.com/dropensource/mediq/blob/main/apps/gym-member/src/store/useGymSessionStore.ts): `apps/gym-member/src/store/useGymSessionStore.ts`

### Gym Management

- [Exercise management](https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/app/exercises/page.tsx): `apps/gym-owner-dashboard/src/app/exercises/page.tsx`
- [Owner authentication](https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/contexts/AuthContext.tsx): `apps/gym-owner-dashboard/src/contexts/AuthContext.tsx`
- [Member management](https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/services/membersService.ts): `apps/gym-owner-dashboard/src/services/membersService.ts`
- [Program management](https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/services/programsService.ts): `apps/gym-owner-dashboard/src/services/programsService.ts`
- [Dashboard data client](https://github.com/dropensource/mediq/blob/main/apps/gym-owner-dashboard/src/lib/supabase.ts): `apps/gym-owner-dashboard/src/lib/supabase.ts`

### MediQ Health

- [Health metrics](https://github.com/dropensource/mediq/blob/main/apps/mediq/src/shared/hooks/useHealthMetricsDirect.ts): `apps/mediq/src/shared/hooks/useHealthMetricsDirect.ts`
- [Health data services](https://github.com/dropensource/mediq/tree/main/apps/mediq/src/shared/services): `apps/mediq/src/shared/services`
- [Health dashboard](https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/dashboard): `apps/mediq/src/features/dashboard`
- [Diet tracking](https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/diet): `apps/mediq/src/features/diet`
- [Insights and trends](https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/insights): `apps/mediq/src/features/insights`
- [Report upload](https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/upload): `apps/mediq/src/features/upload`
- [Report storage](https://github.com/dropensource/mediq/blob/main/apps/mediq/src/features/upload/services/storageService.ts): `apps/mediq/src/features/upload/services/storageService.ts`
- [Health chatbot](https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/chatbot): `apps/mediq/src/features/chatbot`
- [Chat rule engine](https://github.com/dropensource/mediq/blob/main/apps/mediq/src/features/chatbot/engine/ruleEngine.ts): `apps/mediq/src/features/chatbot/engine/ruleEngine.ts`
- [Lab test matcher](https://github.com/dropensource/mediq/blob/main/apps/mediq/src/features/chatbot/services/labTestMatcher.ts): `apps/mediq/src/features/chatbot/services/labTestMatcher.ts`
- [Cycle tracking](https://github.com/dropensource/mediq/tree/main/apps/mediq/src/features/period-tracker): `apps/mediq/src/features/period-tracker`

### Shared Data

- [MediQ auth state](https://github.com/dropensource/mediq/blob/main/apps/mediq/src/shared/context/AuthContext.tsx): `apps/mediq/src/shared/context/AuthContext.tsx`
- [Profile state](https://github.com/dropensource/mediq/blob/main/apps/mediq/src/shared/context/ProfileContext.tsx): `apps/mediq/src/shared/context/ProfileContext.tsx`
- [Sync progress state](https://github.com/dropensource/mediq/blob/main/apps/mediq/src/shared/context/SyncProgressContext.tsx): `apps/mediq/src/shared/context/SyncProgressContext.tsx`
- [Data and auth package](https://github.com/dropensource/mediq/tree/main/packages/data/src): `packages/data/src`

### Other components

- **Gym member**
- **Gym owner**
- **MediQ user**
- **Supabase**
- **Amazon Cognito**

## Connections

- Gym member → Chat logging: logs activity
- Chat logging → Intent detection: detects intent (evidence: `apps/gym-member/src/features/logChat/store/useLogChatStore.ts`)
- Chat logging → Exercise dialogue: routes exercise turns (evidence: `apps/gym-member/src/features/logChat/store/useLogChatStore.ts`)
- Exercise dialogue → Exercise catalog: resolves exercises (evidence: `apps/gym-member/src/features/logChat/engine/exerciseChatFlow.ts`)
- Chat logging → Exercise records: saves exercise (evidence: `apps/gym-member/src/features/logChat/store/useLogChatStore.ts`)
- Chat logging → Body measurements: saves measurements (evidence: `apps/gym-member/src/features/logChat/store/useLogChatStore.ts`)
- Body measurements → Health profile: uses profile data (evidence: `apps/gym-member/src/services/bodyCompService.ts`)
- Health profile → Composition engine: records composition (evidence: `apps/gym-member/src/services/healthProfileService.ts`)
- Gym owner → Exercise management: manages exercises
- Exercise management → Owner authentication: checks access (evidence: `apps/gym-owner-dashboard/src/app/exercises/page.tsx`)
- Exercise management → Dashboard data client: loads catalog (evidence: `apps/gym-owner-dashboard/src/app/exercises/page.tsx`)
- Member management → Dashboard data client: queries members (evidence: `apps/gym-owner-dashboard/src/services/membersService.ts`)
- Program management → Dashboard data client: queries programs (evidence: `apps/gym-owner-dashboard/src/services/programsService.ts`)
- Owner authentication → Amazon Cognito: authenticates (evidence: `apps/gym-owner-dashboard/src/contexts/AuthContext.tsx`)
- Owner authentication → Dashboard data client: syncs user context (evidence: `apps/gym-owner-dashboard/src/contexts/AuthContext.tsx`)
- MediQ user → Health dashboard: reviews health
- Health metrics → MediQ auth state: reads user state (evidence: `apps/mediq/src/shared/hooks/useHealthMetricsDirect.ts`)
- Health metrics → Profile state: reads active profile (evidence: `apps/mediq/src/shared/hooks/useHealthMetricsDirect.ts`)
- Health metrics → Health data services: fetches summaries (evidence: `apps/mediq/src/shared/hooks/useHealthMetricsDirect.ts`)
- Health dashboard → Health metrics: presents metrics
- Report upload → Report storage: uploads reports
- Report storage → Supabase: stores files (evidence: `apps/mediq/src/features/upload/services/storageService.ts`)
- Health chatbot → Chat rule engine: matches requests (evidence: `apps/mediq/src/features/chatbot/engine/ruleEngine.ts`)
- Chat rule engine → Lab test matcher: matches test names (evidence: `apps/mediq/src/features/chatbot/engine/ruleEngine.ts`)
- MediQ auth state → Data and auth package: uses auth services
- Sync progress state → Health metrics: tracks sync (evidence: `apps/mediq/src/shared/hooks/useHealthMetricsDirect.ts`)
