# shounak151/smart-fridge-backend architecture

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

- Interactive diagram: https://gitdiagram.com/shounak151/smart-fridge-backend
- Repository: https://github.com/shounak151/smart-fridge-backend

## Overview

Smart Fridge Backend is an Express API for managing fridge inventory and helping users reduce food waste. A client requests operations through the server and feature routes; handlers manage users, foods, goals, groceries, and intake, with MongoDB-backed models. Food records support expiry status, nutrition lookups, consumption/waste tracking, and replenishment lists. Separate capabilities provide recipe and macro suggestions, image-based fridge scanning, and expiry alerts by SMS. The tree and sampled files establish the server mounts and several service calls; unsampled feature internals and some route-to-controller wiring are not inferred.

Main entry points: [`server.js`](https://github.com/shounak151/smart-fridge-backend/blob/main/server.js) (Express server), [`controllers/foodController.js`](https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/foodController.js) (Food operations), [`services/alertService.js`](https://github.com/shounak151/smart-fridge-backend/blob/main/services/alertService.js) (Alert service), [`services/geminiService.js`](https://github.com/shounak151/smart-fridge-backend/blob/main/services/geminiService.js) (Gemini service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry"]
  node_server["Express server<br/>[server.js]"]
  node_food_routes["Food routes<br/>[foodRoutes.js]"]
  node_goal_routes["Goal routes<br/>[goalRoutes.js]"]
  node_recipe_routes["Recipe routes<br/>[recipeRoutes.js]"]
  node_grocery_routes["Grocery routes<br/>[groceryRoutes.js]"]
  node_intake_routes["Intake routes<br/>[intakeRoute.js]"]
  node_auth_routes["Auth routes<br/>[authRoutes.js]"]
  node_vision_routes["Vision routes<br/>[visionRoutes.js]"]
end

subgraph group_inventory["Fridge inventory"]
  node_food_controller["Food operations<br/>[foodController.js]"]
  node_food_model["Food records<br/>[Food.js]"]
  node_grocery_controller["Grocery operations"]
  node_grocery_model["Grocery lists<br/>[GroceryList.js]"]
  node_expiry_service["Expiry status<br/>[expiryService.js]"]
  node_nutrition_service["Nutrition lookup"]
end

subgraph group_planning["Food planning"]
  node_goal_controller["Goal suggestions<br/>[goalController.js]"]
  node_goal_model["User goals<br/>[UserGoal.js]"]
  node_recipe_service["Recipe service<br/>[recipeService.js]"]
  node_ai_service["Gemini service<br/>[geminiService.js]"]
  node_intake_controller["Intake operations"]
  node_intake_model["Intake records<br/>[Intake.js]"]
end

subgraph group_account["Accounts and tracking"]
  node_auth_controller["Authentication<br/>[authController.js]"]
  node_user_model["User records<br/>[User.js]"]
end

subgraph group_alerts["Expiry alerts"]
  node_alert_routes["Alert routes<br/>[alertRoutes.js]"]
  node_alert_service["Alert service<br/>[alertService.js]"]
end

node_client(("API client"))
node_nutrition_api{{"Nutrition provider"}}
node_gemini{{"Google Gemini"}}
node_mongo[("MongoDB<br/>[db.js]")]
node_sms_provider{{"SMS provider"}}

node_client -->|"requests"| node_server
node_server -->|"mounts"| node_food_routes
node_server -->|"mounts"| node_goal_routes
node_server -->|"mounts"| node_recipe_routes
node_server -->|"mounts"| node_grocery_routes
node_server -->|"mounts"| node_intake_routes
node_server -->|"mounts"| node_auth_routes
node_server -->|"mounts"| node_vision_routes
node_server -->|"mounts"| node_alert_routes
node_server -->|"connects"| node_mongo
node_food_controller -->|"reads/writes"| node_food_model
node_food_controller -->|"checks status"| node_expiry_service
node_food_controller -->|"requests nutrition"| node_nutrition_service
node_nutrition_service -.->|"fetches data"| node_nutrition_api
node_food_controller -->|"updates stats"| node_user_model
node_food_controller -->|"adds depleted food"| node_grocery_model
node_grocery_controller -->|"reads/writes"| node_grocery_model
node_goal_controller -->|"saves goals"| node_goal_model
node_goal_controller -->|"reads inventory"| node_food_model
node_goal_controller -->|"requests macros"| node_ai_service
node_ai_service -.->|"generates suggestions"| node_gemini
node_recipe_service -.->|"uses AI"| node_ai_service
node_vision_routes -->|"scans image"| node_ai_service
node_ai_service -.->|"identifies items"| node_gemini
node_intake_controller -->|"reads/writes"| node_intake_model
node_auth_controller -->|"reads/writes"| node_user_model
node_alert_routes -->|"triggers alerts"| node_alert_service
node_alert_service -->|"checks inventory"| node_food_model
node_alert_service -->|"checks status"| node_expiry_service
node_server -->|"schedules checks"| node_alert_service
node_alert_service -.->|"sends SMS"| node_sms_provider

click node_server "https://github.com/shounak151/smart-fridge-backend/blob/main/server.js"
click node_food_routes "https://github.com/shounak151/smart-fridge-backend/blob/main/routes/foodRoutes.js"
click node_goal_routes "https://github.com/shounak151/smart-fridge-backend/blob/main/routes/goalRoutes.js"
click node_recipe_routes "https://github.com/shounak151/smart-fridge-backend/blob/main/routes/recipeRoutes.js"
click node_grocery_routes "https://github.com/shounak151/smart-fridge-backend/blob/main/routes/groceryRoutes.js"
click node_intake_routes "https://github.com/shounak151/smart-fridge-backend/blob/main/routes/intakeRoute.js"
click node_auth_routes "https://github.com/shounak151/smart-fridge-backend/blob/main/routes/authRoutes.js"
click node_vision_routes "https://github.com/shounak151/smart-fridge-backend/blob/main/routes/visionRoutes.js"
click node_food_controller "https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/foodController.js"
click node_food_model "https://github.com/shounak151/smart-fridge-backend/blob/main/models/Food.js"
click node_grocery_controller "https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/groceryController.js"
click node_grocery_model "https://github.com/shounak151/smart-fridge-backend/blob/main/models/GroceryList.js"
click node_expiry_service "https://github.com/shounak151/smart-fridge-backend/blob/main/services/expiryService.js"
click node_nutrition_service "https://github.com/shounak151/smart-fridge-backend/blob/main/services/nutritionService.js"
click node_goal_controller "https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/goalController.js"
click node_goal_model "https://github.com/shounak151/smart-fridge-backend/blob/main/models/UserGoal.js"
click node_recipe_service "https://github.com/shounak151/smart-fridge-backend/blob/main/services/recipeService.js"
click node_ai_service "https://github.com/shounak151/smart-fridge-backend/blob/main/services/geminiService.js"
click node_intake_controller "https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/intakeController.js"
click node_intake_model "https://github.com/shounak151/smart-fridge-backend/blob/main/models/Intake.js"
click node_auth_controller "https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/authController.js"
click node_user_model "https://github.com/shounak151/smart-fridge-backend/blob/main/models/User.js"
click node_mongo "https://github.com/shounak151/smart-fridge-backend/blob/main/config/db.js"
click node_alert_routes "https://github.com/shounak151/smart-fridge-backend/blob/main/routes/alertRoutes.js"
click node_alert_service "https://github.com/shounak151/smart-fridge-backend/blob/main/services/alertService.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_server,node_food_routes,node_goal_routes,node_recipe_routes,node_grocery_routes,node_intake_routes,node_auth_routes,node_vision_routes,node_client toneBlue
class node_food_controller,node_food_model,node_grocery_controller,node_grocery_model,node_expiry_service,node_nutrition_service,node_mongo toneAmber
class node_goal_controller,node_goal_model,node_recipe_service,node_ai_service,node_intake_controller,node_intake_model toneMint
class node_auth_controller,node_user_model toneRose
class node_alert_routes,node_alert_service,node_nutrition_api,node_gemini,node_sms_provider toneIndigo
```

## Components

### API entry

- [Express server](https://github.com/shounak151/smart-fridge-backend/blob/main/server.js): `server.js`
- [Food routes](https://github.com/shounak151/smart-fridge-backend/blob/main/routes/foodRoutes.js): `routes/foodRoutes.js`
- [Goal routes](https://github.com/shounak151/smart-fridge-backend/blob/main/routes/goalRoutes.js): `routes/goalRoutes.js`
- [Recipe routes](https://github.com/shounak151/smart-fridge-backend/blob/main/routes/recipeRoutes.js): `routes/recipeRoutes.js`
- [Grocery routes](https://github.com/shounak151/smart-fridge-backend/blob/main/routes/groceryRoutes.js): `routes/groceryRoutes.js`
- [Intake routes](https://github.com/shounak151/smart-fridge-backend/blob/main/routes/intakeRoute.js): `routes/intakeRoute.js`
- [Auth routes](https://github.com/shounak151/smart-fridge-backend/blob/main/routes/authRoutes.js): `routes/authRoutes.js`
- [Vision routes](https://github.com/shounak151/smart-fridge-backend/blob/main/routes/visionRoutes.js): `routes/visionRoutes.js`

### Fridge inventory

- [Food operations](https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/foodController.js): `controllers/foodController.js`
- [Food records](https://github.com/shounak151/smart-fridge-backend/blob/main/models/Food.js): `models/Food.js`
- [Grocery operations](https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/groceryController.js): `controllers/groceryController.js`
- [Grocery lists](https://github.com/shounak151/smart-fridge-backend/blob/main/models/GroceryList.js): `models/GroceryList.js`
- [Expiry status](https://github.com/shounak151/smart-fridge-backend/blob/main/services/expiryService.js): `services/expiryService.js`
- [Nutrition lookup](https://github.com/shounak151/smart-fridge-backend/blob/main/services/nutritionService.js): `services/nutritionService.js`

### Food planning

- [Goal suggestions](https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/goalController.js): `controllers/goalController.js`
- [User goals](https://github.com/shounak151/smart-fridge-backend/blob/main/models/UserGoal.js): `models/UserGoal.js`
- [Recipe service](https://github.com/shounak151/smart-fridge-backend/blob/main/services/recipeService.js): `services/recipeService.js`
- [Gemini service](https://github.com/shounak151/smart-fridge-backend/blob/main/services/geminiService.js): `services/geminiService.js`
- [Intake operations](https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/intakeController.js): `controllers/intakeController.js`
- [Intake records](https://github.com/shounak151/smart-fridge-backend/blob/main/models/Intake.js): `models/Intake.js`

### Accounts and tracking

- [Authentication](https://github.com/shounak151/smart-fridge-backend/blob/main/controllers/authController.js): `controllers/authController.js`
- [User records](https://github.com/shounak151/smart-fridge-backend/blob/main/models/User.js): `models/User.js`

### Expiry alerts

- [Alert routes](https://github.com/shounak151/smart-fridge-backend/blob/main/routes/alertRoutes.js): `routes/alertRoutes.js`
- [Alert service](https://github.com/shounak151/smart-fridge-backend/blob/main/services/alertService.js): `services/alertService.js`

### Other components

- **API client**
- **Nutrition provider**
- **Google Gemini**
- [MongoDB](https://github.com/shounak151/smart-fridge-backend/blob/main/config/db.js): `config/db.js`
- **SMS provider**

## Connections

- API client → Express server: requests
- Express server → Food routes: mounts
- Express server → Goal routes: mounts
- Express server → Recipe routes: mounts
- Express server → Grocery routes: mounts
- Express server → Intake routes: mounts
- Express server → Auth routes: mounts
- Express server → Vision routes: mounts
- Express server → Alert routes: mounts
- Express server → MongoDB: connects
- Food operations → Food records: reads/writes
- Food operations → Expiry status: checks status
- Food operations → Nutrition lookup: requests nutrition
- Nutrition lookup → Nutrition provider: fetches data
- Food operations → User records: updates stats
- Food operations → Grocery lists: adds depleted food
- Grocery operations → Grocery lists: reads/writes
- Goal suggestions → User goals: saves goals
- Goal suggestions → Food records: reads inventory
- Goal suggestions → Gemini service: requests macros
- Gemini service → Google Gemini: generates suggestions
- Recipe service → Gemini service: uses AI
- Vision routes → Gemini service: scans image
- Gemini service → Google Gemini: identifies items
- Intake operations → Intake records: reads/writes
- Authentication → User records: reads/writes
- Alert routes → Alert service: triggers alerts
- Alert service → Food records: checks inventory
- Alert service → Expiry status: checks status
- Express server → Alert service: schedules checks
- Alert service → SMS provider: sends SMS
