# bao243/exe101-be architecture

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

- Interactive diagram: https://gitdiagram.com/bao243/exe101-be
- Repository: https://github.com/bao243/exe101-be

## Overview

EXE-BE is a nutrition and meal-planning backend API. Clients call the Express API; routing and authentication lead to user, meal, payment, notification, or image-based ingredient-recognition handlers, which return API results and update application data. The documented AI workflow detects ingredients from an image, matches them to the ingredient catalogue, then finds suitable meals; premium status can affect usage and filtering. The graph also preserves meal planning, saved meals, meal logs, payments, and realtime notifications. Relationships reflect the excerpts, source index, and README; unsampled subsystem internals are not inferred.

Main entry points: [`controller/MealController.js`](https://github.com/bao243/exe101-be/blob/main/controller/MealController.js) (Meal operations), [`router/index.js`](https://github.com/bao243/exe101-be/blob/main/router/index.js) (API router), [`controller/AIController.js`](https://github.com/bao243/exe101-be/blob/main/controller/AIController.js) (Image meal matching), [`controller/NotificationController.js`](https://github.com/bao243/exe101-be/blob/main/controller/NotificationController.js) (Notification operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_app["Express app<br/>[app.js]"]
  node_api_router["API router<br/>[index.js]"]
  node_auth["Authentication<br/>[auth.js]"]
  node_meal_routes["Meal routes<br/>[meal.js]"]
  node_ai_routes["AI routes<br/>[ai.js]"]
  node_user_routes["User routes<br/>[users.js]"]
  node_payment_routes["Payment routes<br/>[payment.js]"]
  node_noti_routes["Notification routes<br/>[noti.js]"]
end

subgraph group_nutrition["Nutrition features"]
  node_meal_controller["Meal operations<br/>[MealController.js]"]
  node_ai_controller["Image meal matching<br/>[AIController.js]"]
  node_gemini["Gemini recognition<br/>[gemini.js]"]
  node_meal_model[("Meals<br/>[meal.js]")]
  node_ingredient_model[("Ingredients<br/>[ingredient.js]")]
  node_category_model[("Meal categories<br/>[category.js]")]
  node_subcategory_model[("Meal subcategories<br/>[subCategory.js]")]
  node_plan_model[("Meal plans<br/>[mealPlan.js]")]
  node_saved_model[("Saved meals<br/>[savedMeal.js]")]
  node_log_model[("Meal logs<br/>[mealLogEntry.js]")]
end

subgraph group_accounts["Accounts and billing"]
  node_user_controller["User operations<br/>[UserController.js]"]
  node_user_model[("User accounts<br/>[user.js]")]
  node_payment_controller["Payment operations"]
  node_payment_model[("Payment records<br/>[payment.js]")]
end

subgraph group_messaging["Notifications"]
  node_noti_controller["Notification operations"]
  node_noti_model[("Notifications<br/>[noti.js]")]
  node_socket["Realtime socket<br/>[socket.js]"]
end

subgraph group_platform["Data and services"]
  node_redis[("Redis cache<br/>[redis.js]")]
  node_database_connect["Database connection<br/>[db.js]"]
  node_pagination["Pagination utilities<br/>[pagination.js]"]
end

node_client(("API client"))
node_redis_service[("Redis service")]
node_mongo_service[("MongoDB")]

node_client -->|"sends requests"| node_app
node_app -->|"mounts API"| node_api_router
node_app -->|"connects database"| node_database_connect
node_app -->|"starts cache"| node_redis
node_api_router -->|"routes meals"| node_meal_routes
node_api_router -->|"routes AI"| node_ai_routes
node_api_router -->|"routes users"| node_user_routes
node_api_router -->|"routes payments"| node_payment_routes
node_api_router -->|"routes notifications"| node_noti_routes
node_meal_routes -->|"guards requests"| node_auth
node_meal_routes -->|"dispatches to"| node_meal_controller
node_ai_routes -->|"guards requests"| node_auth
node_ai_routes -->|"dispatches to"| node_ai_controller
node_user_routes -->|"guards requests"| node_auth
node_user_routes -->|"dispatches to"| node_user_controller
node_payment_routes -->|"guards requests"| node_auth
node_payment_routes -->|"dispatches to"| node_payment_controller
node_noti_routes -->|"guards requests"| node_auth
node_noti_routes -->|"dispatches to"| node_noti_controller
node_auth -->|"loads account"| node_user_model
node_meal_controller -->|"queries meals"| node_meal_model
node_meal_controller -->|"resolves ingredients"| node_ingredient_model
node_meal_controller -->|"resolves categories"| node_category_model
node_meal_controller -->|"resolves subcategories"| node_subcategory_model
node_meal_controller -->|"creates plans"| node_plan_model
node_meal_controller -->|"manages saved meals"| node_saved_model
node_meal_controller -->|"records meal logs"| node_log_model
node_meal_controller -->|"requests notification"| node_noti_controller
node_meal_controller -->|"uses cache"| node_redis
node_ai_controller -->|"recognizes image"| node_gemini
node_ai_controller -->|"matches ingredients"| node_ingredient_model
node_ai_controller -->|"finds meals"| node_meal_model
node_ai_controller -->|"checks membership"| node_user_model
node_ai_controller -->|"reads latest plan"| node_plan_model
node_user_controller -->|"manages accounts"| node_user_model
node_user_controller -->|"checks membership"| node_payment_model
node_user_controller -->|"uses cache"| node_redis
node_payment_controller -->|"manages payments"| node_payment_model
node_payment_controller -->|"updates membership"| node_user_model
node_payment_controller -->|"requests notification"| node_noti_controller
node_noti_controller -->|"stores notifications"| node_noti_model
node_noti_controller -->|"summarizes plans"| node_plan_model
node_noti_controller -->|"emits events"| node_socket
node_meal_controller -->|"builds pages"| node_pagination
node_payment_controller -->|"builds pages"| node_pagination
node_user_controller -->|"builds pages"| node_pagination
node_database_connect -.->|"connects to"| node_mongo_service
node_meal_model -.->|"persists records"| node_mongo_service

click node_app "https://github.com/bao243/exe101-be/blob/main/app.js"
click node_api_router "https://github.com/bao243/exe101-be/blob/main/router/index.js"
click node_auth "https://github.com/bao243/exe101-be/blob/main/middlewares/auth.js"
click node_meal_routes "https://github.com/bao243/exe101-be/blob/main/routes/meal.js"
click node_ai_routes "https://github.com/bao243/exe101-be/blob/main/routes/ai.js"
click node_user_routes "https://github.com/bao243/exe101-be/blob/main/routes/users.js"
click node_payment_routes "https://github.com/bao243/exe101-be/blob/main/routes/payment.js"
click node_noti_routes "https://github.com/bao243/exe101-be/blob/main/routes/noti.js"
click node_meal_controller "https://github.com/bao243/exe101-be/blob/main/controller/MealController.js"
click node_ai_controller "https://github.com/bao243/exe101-be/blob/main/controller/AIController.js"
click node_gemini "https://github.com/bao243/exe101-be/blob/main/services/gemini.js"
click node_meal_model "https://github.com/bao243/exe101-be/blob/main/model/meal.js"
click node_ingredient_model "https://github.com/bao243/exe101-be/blob/main/model/meal/ingredient.js"
click node_category_model "https://github.com/bao243/exe101-be/blob/main/model/meal/category.js"
click node_subcategory_model "https://github.com/bao243/exe101-be/blob/main/model/meal/subCategory.js"
click node_plan_model "https://github.com/bao243/exe101-be/blob/main/model/mealPlan.js"
click node_saved_model "https://github.com/bao243/exe101-be/blob/main/model/savedMeal.js"
click node_log_model "https://github.com/bao243/exe101-be/blob/main/model/mealLogEntry.js"
click node_user_controller "https://github.com/bao243/exe101-be/blob/main/controller/UserController.js"
click node_user_model "https://github.com/bao243/exe101-be/blob/main/model/user.js"
click node_payment_controller "https://github.com/bao243/exe101-be/blob/main/controller/PaymentController.js"
click node_payment_model "https://github.com/bao243/exe101-be/blob/main/model/payment.js"
click node_noti_controller "https://github.com/bao243/exe101-be/blob/main/controller/NotificationController.js"
click node_noti_model "https://github.com/bao243/exe101-be/blob/main/model/noti.js"
click node_socket "https://github.com/bao243/exe101-be/blob/main/services/socket.js"
click node_redis "https://github.com/bao243/exe101-be/blob/main/services/redis.js"
click node_database_connect "https://github.com/bao243/exe101-be/blob/main/DB/db.js"
click node_pagination "https://github.com/bao243/exe101-be/blob/main/utils/pagination.js"

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_app,node_api_router,node_auth,node_meal_routes,node_ai_routes,node_user_routes,node_payment_routes,node_noti_routes,node_client toneBlue
class node_meal_controller,node_ai_controller,node_gemini,node_meal_model,node_ingredient_model,node_category_model,node_subcategory_model,node_plan_model,node_saved_model,node_log_model,node_redis_service,node_mongo_service toneAmber
class node_user_controller,node_user_model,node_payment_controller,node_payment_model toneMint
class node_noti_controller,node_noti_model,node_socket toneRose
class node_redis,node_database_connect,node_pagination toneIndigo
```

## Components

### API entry

- [Express app](https://github.com/bao243/exe101-be/blob/main/app.js): `app.js`
- [API router](https://github.com/bao243/exe101-be/blob/main/router/index.js): `router/index.js`
- [Authentication](https://github.com/bao243/exe101-be/blob/main/middlewares/auth.js): `middlewares/auth.js`
- [Meal routes](https://github.com/bao243/exe101-be/blob/main/routes/meal.js): `routes/meal.js`
- [AI routes](https://github.com/bao243/exe101-be/blob/main/routes/ai.js): `routes/ai.js`
- [User routes](https://github.com/bao243/exe101-be/blob/main/routes/users.js): `routes/users.js`
- [Payment routes](https://github.com/bao243/exe101-be/blob/main/routes/payment.js): `routes/payment.js`
- [Notification routes](https://github.com/bao243/exe101-be/blob/main/routes/noti.js): `routes/noti.js`

### Nutrition features

- [Meal operations](https://github.com/bao243/exe101-be/blob/main/controller/MealController.js): `controller/MealController.js`
- [Image meal matching](https://github.com/bao243/exe101-be/blob/main/controller/AIController.js): `controller/AIController.js`
- [Gemini recognition](https://github.com/bao243/exe101-be/blob/main/services/gemini.js): `services/gemini.js`
- [Meals](https://github.com/bao243/exe101-be/blob/main/model/meal.js): `model/meal.js`
- [Ingredients](https://github.com/bao243/exe101-be/blob/main/model/meal/ingredient.js): `model/meal/ingredient.js`
- [Meal categories](https://github.com/bao243/exe101-be/blob/main/model/meal/category.js): `model/meal/category.js`
- [Meal subcategories](https://github.com/bao243/exe101-be/blob/main/model/meal/subCategory.js): `model/meal/subCategory.js`
- [Meal plans](https://github.com/bao243/exe101-be/blob/main/model/mealPlan.js): `model/mealPlan.js`
- [Saved meals](https://github.com/bao243/exe101-be/blob/main/model/savedMeal.js): `model/savedMeal.js`
- [Meal logs](https://github.com/bao243/exe101-be/blob/main/model/mealLogEntry.js): `model/mealLogEntry.js`

### Accounts and billing

- [User operations](https://github.com/bao243/exe101-be/blob/main/controller/UserController.js): `controller/UserController.js`
- [User accounts](https://github.com/bao243/exe101-be/blob/main/model/user.js): `model/user.js`
- [Payment operations](https://github.com/bao243/exe101-be/blob/main/controller/PaymentController.js): `controller/PaymentController.js`
- [Payment records](https://github.com/bao243/exe101-be/blob/main/model/payment.js): `model/payment.js`

### Notifications

- [Notification operations](https://github.com/bao243/exe101-be/blob/main/controller/NotificationController.js): `controller/NotificationController.js`
- [Notifications](https://github.com/bao243/exe101-be/blob/main/model/noti.js): `model/noti.js`
- [Realtime socket](https://github.com/bao243/exe101-be/blob/main/services/socket.js): `services/socket.js`

### Data and services

- [Redis cache](https://github.com/bao243/exe101-be/blob/main/services/redis.js): `services/redis.js`
- [Database connection](https://github.com/bao243/exe101-be/blob/main/DB/db.js): `DB/db.js`
- [Pagination utilities](https://github.com/bao243/exe101-be/blob/main/utils/pagination.js): `utils/pagination.js`

### Other components

- **API client**
- **Redis service**
- **MongoDB**

## Connections

- API client → Express app: sends requests (evidence: `README.md`)
- Express app → API router: mounts API (evidence: `app.js`)
- Express app → Database connection: connects database (evidence: `app.js`)
- Express app → Redis cache: starts cache (evidence: `app.js`)
- API router → Meal routes: routes meals (evidence: `router/index.js`)
- API router → AI routes: routes AI (evidence: `router/index.js`)
- API router → User routes: routes users (evidence: `router/index.js`)
- API router → Payment routes: routes payments (evidence: `router/index.js`)
- API router → Notification routes: routes notifications (evidence: `router/index.js`)
- Meal routes → Authentication: guards requests (evidence: `routes/meal.js`)
- Meal routes → Meal operations: dispatches to (evidence: `routes/meal.js`)
- AI routes → Authentication: guards requests (evidence: `routes/ai.js`)
- AI routes → Image meal matching: dispatches to (evidence: `routes/ai.js`)
- User routes → Authentication: guards requests (evidence: `routes/users.js`)
- User routes → User operations: dispatches to (evidence: `routes/users.js`)
- Payment routes → Authentication: guards requests (evidence: `routes/payment.js`)
- Payment routes → Payment operations: dispatches to (evidence: `routes/payment.js`)
- Notification routes → Authentication: guards requests (evidence: `routes/noti.js`)
- Notification routes → Notification operations: dispatches to (evidence: `routes/noti.js`)
- Authentication → User accounts: loads account (evidence: `middlewares/auth.js`)
- Meal operations → Meals: queries meals (evidence: `controller/MealController.js`)
- Meal operations → Ingredients: resolves ingredients (evidence: `controller/MealController.js`)
- Meal operations → Meal categories: resolves categories (evidence: `controller/MealController.js`)
- Meal operations → Meal subcategories: resolves subcategories (evidence: `controller/MealController.js`)
- Meal operations → Meal plans: creates plans (evidence: `controller/MealController.js`)
- Meal operations → Saved meals: manages saved meals (evidence: `controller/MealController.js`)
- Meal operations → Meal logs: records meal logs (evidence: `controller/MealController.js`)
- Meal operations → Notification operations: requests notification (evidence: `controller/MealController.js`)
- Meal operations → Redis cache: uses cache (evidence: `controller/MealController.js`)
- Image meal matching → Gemini recognition: recognizes image (evidence: `controller/AIController.js`)
- Image meal matching → Ingredients: matches ingredients (evidence: `controller/AIController.js`)
- Image meal matching → Meals: finds meals (evidence: `controller/AIController.js`)
- Image meal matching → User accounts: checks membership (evidence: `controller/AIController.js`)
- Image meal matching → Meal plans: reads latest plan (evidence: `controller/AIController.js`)
- User operations → User accounts: manages accounts (evidence: `controller/UserController.js`)
- User operations → Payment records: checks membership (evidence: `controller/UserController.js`)
- User operations → Redis cache: uses cache (evidence: `controller/UserController.js`)
- Payment operations → Payment records: manages payments (evidence: `controller/PaymentController.js`)
- Payment operations → User accounts: updates membership (evidence: `controller/PaymentController.js`)
- Payment operations → Notification operations: requests notification (evidence: `controller/PaymentController.js`)
- Notification operations → Notifications: stores notifications (evidence: `controller/NotificationController.js`)
- Notification operations → Meal plans: summarizes plans (evidence: `controller/NotificationController.js`)
- Notification operations → Realtime socket: emits events (evidence: `controller/NotificationController.js`)
- Meal operations → Pagination utilities: builds pages (evidence: `controller/MealController.js`)
- Payment operations → Pagination utilities: builds pages (evidence: `controller/PaymentController.js`)
- User operations → Pagination utilities: builds pages (evidence: `controller/UserController.js`)
- Database connection → MongoDB: connects to
- Meals → MongoDB: persists records
