# thebishalghosh/healthapp-backend architecture

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

- Interactive diagram: https://gitdiagram.com/thebishalghosh/healthapp-backend
- Repository: https://github.com/thebishalghosh/healthapp-backend

## Overview

This is a Core PHP REST API for a mobile health and wellness app, plus a PHP admin portal. The documented implemented workflow is account registration/login and bearer-token authentication, followed by saving a health profile and calculating nutrition requirements from that profile. The README describes meal planning, AI, reminders, subscriptions, and other features as planned for this checkpoint, although corresponding source paths exist. Those branches are represented as product areas, not asserted as implemented. Connections are limited to routing or calls visible in excerpts, SOURCE INDEX references, or README statements.

Main entry points: [`backend/api/v1/ai/food-recommendations.php`](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/api/v1/ai/food-recommendations.php) (Food recommendations), [`backend/index.php`](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/index.php) (API router), [`backend/config/database.php`](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/config/database.php) (MySQL database), [`backend/admin/index.php`](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/admin/index.php) (Admin dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_front["API router<br/>[index.php]"]
  node_auth["Bearer authentication<br/>[auth.php]"]
  node_auth_endpoints["Account endpoints"]
  node_account["Account deactivation<br/>[account.php]"]
end

subgraph group_health["Health and nutrition"]
  node_profile["Health profile<br/>[profile.php]"]
  node_nutrition_api["Nutrition endpoints"]
  node_nutrition_service["Nutrition calculations"]
  node_health_tracking["Health tracking"]
  node_medical_profile["Medical profile"]
end

subgraph group_product["Product capabilities"]
  node_food_ai["Food recommendations"]
  node_food_location["Food region preferences"]
  node_food_history["Recommendation history"]
  node_food_lookup["Food nutrition lookup"]
  node_chat_api["Chat messaging<br/>[message.php]"]
  node_chat_service["Chatbot service<br/>[ChatbotService.php]"]
  node_gemini["Gemini integration<br/>[GeminiService.php]"]
  node_entitlements["Feature entitlements"]
  node_reminders["Reminder management<br/>[Reminder.php]"]
  node_settings["User settings<br/>[UserSettings.php]"]
  node_subscriptions["Subscription management<br/>[Subscription.php]"]
  node_payments["Razorpay integration"]
end

subgraph group_admin["Admin portal"]
  node_admin_auth["Admin authentication<br/>[auth.php]"]
  node_admin_dashboard["Admin dashboard<br/>[index.php]"]
  node_admin_header["Admin layout header<br/>[header.php]"]
  node_admin_footer["Admin layout footer<br/>[footer.php]"]
end

subgraph group_foundation["Shared foundation"]
  node_database[("MySQL database<br/>[database.php]")]
  node_bootstrap["Request bootstrap<br/>[bootstrap.php]"]
  node_response["JSON responses<br/>[response.php]"]
end

node_mobile(("Mobile client"))
node_admin_users[("Admin users")]
node_gemini_service["Google Gemini"]
node_razorpay_service["Razorpay"]

node_mobile -->|"sends requests"| node_front
node_front -->|"initializes"| node_bootstrap
node_front -->|"loads"| node_auth
node_front -->|"routes requests"| node_nutrition_api
node_front -->|"routes requests"| node_food_ai
node_front -->|"routes requests"| node_chat_api
node_auth_endpoints -.->|"validates credentials"| node_auth
node_profile -.->|"stores profile"| node_database
node_nutrition_api -.->|"calculates requirements"| node_nutrition_service
node_nutrition_api -.->|"stores history"| node_database
node_food_ai -->|"loads region"| node_food_location
node_food_ai -->|"builds daily context"| node_health_tracking
node_food_ai -->|"loads allergies"| node_medical_profile
node_food_ai -->|"checks access"| node_entitlements
node_food_ai -->|"requests recommendations"| node_gemini
node_chat_api -->|"delegates message"| node_chat_service
node_chat_service -->|"generates replies"| node_gemini
node_chat_service -->|"checks access"| node_entitlements
node_admin_dashboard -->|"requires session"| node_admin_auth
node_admin_dashboard -->|"renders header"| node_admin_header
node_admin_dashboard -->|"renders footer"| node_admin_footer
node_admin_auth -->|"queries admins"| node_database
node_admin_users -->|"authenticates against"| node_database
node_bootstrap -->|"loads connection"| node_database
node_bootstrap -->|"configures errors"| node_response
node_food_ai -.->|"records results"| node_food_history
node_food_ai -.->|"resolves nutrition"| node_food_lookup
node_reminders -->|"uses preferences"| node_settings
node_subscriptions -->|"delegates payment"| node_payments
node_payments -.->|"calls provider"| node_razorpay_service

click node_front "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/index.php"
click node_auth "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/core/auth.php"
click node_auth_endpoints "https://github.com/thebishalghosh/healthapp-backend/tree/main/backend/api/v1/auth"
click node_account "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/api/v1/account.php"
click node_profile "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/api/v1/health/profile.php"
click node_nutrition_api "https://github.com/thebishalghosh/healthapp-backend/tree/main/backend/api/v1/health/nutrition"
click node_nutrition_service "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/NutritionService.php"
click node_health_tracking "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/HealthTrackingService.php"
click node_medical_profile "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/HealthMedicalProfileService.php"
click node_food_ai "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/api/v1/ai/food-recommendations.php"
click node_food_location "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/FoodLocationService.php"
click node_food_history "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/FoodRecommendationHistoryService.php"
click node_food_lookup "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/FoodNutritionLookupService.php"
click node_chat_api "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/api/v1/chatbot/message.php"
click node_chat_service "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/ChatbotService.php"
click node_gemini "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/GeminiService.php"
click node_entitlements "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/EntitlementService.php"
click node_reminders "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/models/Reminder.php"
click node_settings "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/models/UserSettings.php"
click node_subscriptions "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/models/Subscription.php"
click node_payments "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/RazorpayService.php"
click node_admin_auth "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/admin/includes/auth.php"
click node_admin_dashboard "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/admin/index.php"
click node_admin_header "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/admin/includes/header.php"
click node_admin_footer "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/admin/includes/footer.php"
click node_database "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/config/database.php"
click node_bootstrap "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/bootstrap.php"
click node_response "https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/core/response.php"

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_front,node_auth,node_auth_endpoints,node_account,node_mobile toneBlue
class node_profile,node_nutrition_api,node_nutrition_service,node_health_tracking,node_medical_profile,node_admin_users toneAmber
class node_food_ai,node_food_location,node_food_history,node_food_lookup,node_chat_api,node_chat_service,node_gemini,node_entitlements,node_reminders,node_settings,node_subscriptions,node_payments toneMint
class node_admin_auth,node_admin_dashboard,node_admin_header,node_admin_footer toneRose
class node_database,node_bootstrap,node_response,node_gemini_service,node_razorpay_service toneIndigo
```

## Components

### API and identity

- [API router](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/index.php): `backend/index.php`
- [Bearer authentication](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/core/auth.php): `backend/core/auth.php`
- [Account endpoints](https://github.com/thebishalghosh/healthapp-backend/tree/main/backend/api/v1/auth): `backend/api/v1/auth`
- [Account deactivation](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/api/v1/account.php): `backend/api/v1/account.php`

### Health and nutrition

- [Health profile](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/api/v1/health/profile.php): `backend/api/v1/health/profile.php`
- [Nutrition endpoints](https://github.com/thebishalghosh/healthapp-backend/tree/main/backend/api/v1/health/nutrition): `backend/api/v1/health/nutrition`
- [Nutrition calculations](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/NutritionService.php): `backend/services/NutritionService.php`
- [Health tracking](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/HealthTrackingService.php): `backend/services/HealthTrackingService.php`
- [Medical profile](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/HealthMedicalProfileService.php): `backend/services/HealthMedicalProfileService.php`

### Product capabilities

- [Food recommendations](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/api/v1/ai/food-recommendations.php): `backend/api/v1/ai/food-recommendations.php`
- [Food region preferences](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/FoodLocationService.php): `backend/services/FoodLocationService.php`
- [Recommendation history](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/FoodRecommendationHistoryService.php): `backend/services/FoodRecommendationHistoryService.php`
- [Food nutrition lookup](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/FoodNutritionLookupService.php): `backend/services/FoodNutritionLookupService.php`
- [Chat messaging](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/api/v1/chatbot/message.php): `backend/api/v1/chatbot/message.php`
- [Chatbot service](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/ChatbotService.php): `backend/services/ChatbotService.php`
- [Gemini integration](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/GeminiService.php): `backend/services/GeminiService.php`
- [Feature entitlements](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/EntitlementService.php): `backend/services/EntitlementService.php`
- [Reminder management](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/models/Reminder.php): `backend/models/Reminder.php`
- [User settings](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/models/UserSettings.php): `backend/models/UserSettings.php`
- [Subscription management](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/models/Subscription.php): `backend/models/Subscription.php`
- [Razorpay integration](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/services/RazorpayService.php): `backend/services/RazorpayService.php`

### Admin portal

- [Admin authentication](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/admin/includes/auth.php): `backend/admin/includes/auth.php`
- [Admin dashboard](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/admin/index.php): `backend/admin/index.php`
- [Admin layout header](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/admin/includes/header.php): `backend/admin/includes/header.php`
- [Admin layout footer](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/admin/includes/footer.php): `backend/admin/includes/footer.php`

### Shared foundation

- [MySQL database](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/config/database.php): `backend/config/database.php`
- [Request bootstrap](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/bootstrap.php): `backend/bootstrap.php`
- [JSON responses](https://github.com/thebishalghosh/healthapp-backend/blob/main/backend/core/response.php): `backend/core/response.php`

### Other components

- **Mobile client**
- **Admin users**
- **Google Gemini**
- **Razorpay**

## Connections

- Mobile client → API router: sends requests
- API router → Request bootstrap: initializes (evidence: `backend/index.php`)
- API router → Bearer authentication: loads (evidence: `backend/index.php`)
- API router → Nutrition endpoints: routes requests (evidence: `backend/index.php`)
- API router → Food recommendations: routes requests (evidence: `backend/index.php`)
- API router → Chat messaging: routes requests (evidence: `backend/index.php`)
- Account endpoints → Bearer authentication: validates credentials
- Health profile → MySQL database: stores profile
- Nutrition endpoints → Nutrition calculations: calculates requirements
- Nutrition endpoints → MySQL database: stores history
- Food recommendations → Food region preferences: loads region (evidence: `backend/api/v1/ai/food-recommendations.php`)
- Food recommendations → Health tracking: builds daily context (evidence: `backend/api/v1/ai/food-recommendations.php`)
- Food recommendations → Medical profile: loads allergies (evidence: `backend/api/v1/ai/food-recommendations.php`)
- Food recommendations → Feature entitlements: checks access (evidence: `backend/api/v1/ai/food-recommendations.php`)
- Food recommendations → Gemini integration: requests recommendations (evidence: `backend/api/v1/ai/food-recommendations.php`)
- Chat messaging → Chatbot service: delegates message (evidence: `backend/api/v1/chatbot/message.php`)
- Chatbot service → Gemini integration: generates replies (evidence: `backend/services/ChatbotService.php`)
- Chatbot service → Feature entitlements: checks access (evidence: `backend/services/ChatbotService.php`)
- Admin dashboard → Admin authentication: requires session (evidence: `backend/admin/index.php`)
- Admin dashboard → Admin layout header: renders header (evidence: `backend/admin/index.php`)
- Admin dashboard → Admin layout footer: renders footer (evidence: `backend/admin/index.php`)
- Admin authentication → MySQL database: queries admins (evidence: `backend/admin/includes/auth.php`)
- Admin users → MySQL database: authenticates against
- Request bootstrap → MySQL database: loads connection (evidence: `backend/bootstrap.php`)
- Request bootstrap → JSON responses: configures errors (evidence: `backend/bootstrap.php`)
- Food recommendations → Recommendation history: records results (evidence: `backend/api/v1/ai/food-recommendations.php`)
- Food recommendations → Food nutrition lookup: resolves nutrition
- Reminder management → User settings: uses preferences (evidence: `backend/cron/reminders.php`)
- Subscription management → Razorpay integration: delegates payment (evidence: `backend/services/RazorpayService.php`)
- Razorpay integration → Razorpay: calls provider
