# karthikeyan7333/nutrition-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/karthikeyan7333/nutrition-tracker
- Repository: https://github.com/karthikeyan7333/nutrition-tracker

## Overview

#### Purpose and Entry Points
Nutrition Tracker is a MERN application for authenticated nutrition, hydration, goals, and progress tracking, preserving an earlier AI-assisted food-entry experience. Development starts both services through the root package scripts; runtime entry points are `backend/server.js` for Express and `frontend/src/main.tsx` for the Vite React client.

#### Frontend Application Shell
The React SPA mounts the application and owns browser-side navigation, authenticated UI state, and dashboard composition. `frontend/src/App.tsx` routes users between login/register and the dashboard; `frontend/src/pages/DashboardContainer.tsx` coordinates the primary tracker screen. Vercel serves the built SPA and rewrites browser-route refreshes via `frontend/vercel.json`.

#### Client API Boundary
The frontend uses a centralized Axios client in `frontend/src/lib/api.ts` to call backend `/api` endpoints. Locally, Vite proxies these calls to Express; in production, `VITE_API_BASE_URL` targets the Render backend. UI components such as `frontend/src/components/AddFoodCard.tsx`, `frontend/src/components/WaterTracker.tsx`, and `frontend/src/components/GoalEditor.tsx` submit and refresh domain data through this boundary, never accessing database or Gemini credentials.

#### Express API and Request Pipeline
`backend/server.js` initializes Express, database connectivity, middleware, and route mounting. Route modules partition public authentication from protected tracker resources: `backend/routes/authRoutes.js`, `backend/routes/foodLogRoutes.js`, and `backend/routes/progressRoutes.js`. JWT validation in `backend/middleware/auth.js` establishes the user identity before protected controllers execute; `backend/middleware/errorHandler.js` centralizes failed-request handling.

#### Domain Controllers and Persistence
Controllers implement API behavior for account access and user-scoped tracking records: `backend/controllers/authController.js`, `backend/controllers/foodLogController.js`, `backend/controllers/goalController.js`, `backend/controllers/waterLogController.js`, and `backend/controllers/progressController.js`. Mongoose models define MongoDB Atlas persistence for identities and tracker entities in `backend/models/User.js`, `backend/models/FoodLog.js`, `backend/models/Goal.js`, and `backend/models/WaterLog.js`. Database configuration is isolated in `backend/config/database.js`.

#### AI Food Analysis
Food creation can cross an internal service boundary to Gemini through `backend/services/geminiService.js`. The backend retains the Gemini key, prompt/schema behavior, and nutrition fallback behavior; controllers consume the service rather than exposing Gemini directly to the client. This keeps AI output subject to server-side validation, user association, and persistent food-log workflows.

#### Infrastructure, Deployment, and Migration
MongoDB Atlas is the system of record; Render hosts the Express service using `render.yaml`, and Vercel hosts the frontend. Environment handling is split between `backend/config/env.js`, backend secrets, and build-time frontend API configuration. Legacy JSON data in `data/db.json` is not runtime storage; `backend/scripts/migrateJsonData.js` performs an optional idempotent import into Atlas.

Main entry points: [`backend/server.js`](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/server.js) (Express server), [`backend/controllers/foodLogController.js`](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/controllers/foodLogController.js) (Domain controllers), [`backend/routes/foodLogRoutes.js`](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/routes/foodLogRoutes.js) (Tracker routes), [`backend/scripts/migrateJsonData.js`](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/scripts/migrateJsonData.js) (Legacy JSON migration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React Client"]
  node_vite["Vite entry<br/>browser entry<br/>[main.tsx]"]
  node_app["App routes<br/>React shell<br/>[App.tsx]"]
  node_dashboard["Dashboard<br/>page coordinator"]
  node_tracker_ui["Tracker controls<br/>React components<br/>[AddFoodCard.tsx]"]
  node_api_client["Axios API client<br/>client boundary<br/>[api.ts]"]
  node_vercel["Vercel SPA hosting<br/>deployment config<br/>[vercel.json]"]
end

subgraph group_api["Express API"]
  node_server["Express server<br/>API entry<br/>[server.js]"]
  node_auth_routes["Auth routes<br/>public routes<br/>[authRoutes.js]"]
  node_tracker_routes["Tracker routes<br/>protected routes<br/>[foodLogRoutes.js]"]
  node_jwt["JWT middleware<br/>auth middleware<br/>[auth.js]"]
  node_error_handler["Error handler<br/>error middleware<br/>[errorHandler.js]"]
  node_controllers["Domain controllers<br/>controller layer"]
  node_gemini_service["Gemini analysis<br/>server service<br/>[geminiService.js]"]
end

subgraph group_platform["Data &amp; Deployment"]
  node_database_config["Database connection<br/>Mongoose config<br/>[database.js]"]
  node_models["Tracker models<br/>Mongoose models<br/>[User.js]"]
  node_atlas[("MongoDB Atlas<br/>system of record")]
  node_render["Render service<br/>deployment config<br/>[render.yaml]"]
  node_migration["Legacy JSON migration<br/>optional import<br/>[migrateJsonData.js]"]
  node_legacy_data["Legacy JSON data<br/>migration source<br/>[db.json]"]
end

node_vite -->|"mounts"| node_app
node_app -->|"routes authenticated users"| node_dashboard
node_dashboard -->|"composes"| node_tracker_ui
node_tracker_ui -->|"submits and refreshes"| node_api_client
node_api_client -->|"/api requests"| node_server
node_vercel -->|"serves build"| node_vite
node_render -->|"hosts"| node_server
node_server -->|"mounts"| node_auth_routes
node_server -->|"mounts"| node_tracker_routes
node_server -->|"uses"| node_error_handler
node_tracker_routes -->|"validates identity"| node_jwt
node_auth_routes -->|"dispatches"| node_controllers
node_tracker_routes -->|"dispatches after auth"| node_controllers
node_controllers -->|"reads and writes"| node_models
node_controllers -->|"analyzes food entries"| node_gemini_service
node_server -->|"connects through"| node_database_config
node_database_config -->|"connects"| node_atlas
node_models -->|"persists"| node_atlas
node_migration -->|"imports from"| node_legacy_data
node_migration -->|"writes imported records"| node_atlas

click node_vite "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/src/main.tsx"
click node_app "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/src/App.tsx"
click node_dashboard "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/src/pages/DashboardContainer.tsx"
click node_tracker_ui "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/src/components/AddFoodCard.tsx"
click node_api_client "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/src/lib/api.ts"
click node_vercel "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/vercel.json"
click node_server "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/server.js"
click node_auth_routes "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/routes/authRoutes.js"
click node_tracker_routes "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/routes/foodLogRoutes.js"
click node_jwt "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/middleware/auth.js"
click node_error_handler "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/middleware/errorHandler.js"
click node_controllers "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/controllers/foodLogController.js"
click node_gemini_service "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/services/geminiService.js"
click node_database_config "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/config/database.js"
click node_models "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/models/User.js"
click node_render "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/render.yaml"
click node_migration "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/scripts/migrateJsonData.js"
click node_legacy_data "https://github.com/karthikeyan7333/nutrition-tracker/blob/main/data/db.json"

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_vite,node_app,node_dashboard,node_tracker_ui,node_api_client,node_vercel toneBlue
class node_server,node_auth_routes,node_tracker_routes,node_jwt,node_error_handler,node_controllers,node_gemini_service toneAmber
class node_database_config,node_models,node_atlas,node_render,node_migration,node_legacy_data toneMint
```

## Components

### React Client

- [Vite entry](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/src/main.tsx): browser entry · `frontend/src/main.tsx`
- [App routes](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/src/App.tsx): React shell · `frontend/src/App.tsx`
- [Dashboard](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/src/pages/DashboardContainer.tsx): page coordinator · `frontend/src/pages/DashboardContainer.tsx`
- [Tracker controls](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/src/components/AddFoodCard.tsx): React components · Food, water, and goal controls submit through the API client. · `frontend/src/components/AddFoodCard.tsx`
- [Axios API client](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/src/lib/api.ts): client boundary · Uses Vite proxy locally and configured Render URL in production. · `frontend/src/lib/api.ts`
- [Vercel SPA hosting](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/frontend/vercel.json): deployment config · Serves the client build and rewrites browser routes. · `frontend/vercel.json`

### Express API

- [Express server](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/server.js): API entry · Initializes middleware, database connection, and route mounting. · `backend/server.js`
- [Auth routes](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/routes/authRoutes.js): public routes · `backend/routes/authRoutes.js`
- [Tracker routes](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/routes/foodLogRoutes.js): protected routes · Food logs and progress route modules expose user-scoped tracker APIs. · `backend/routes/foodLogRoutes.js`
- [JWT middleware](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/middleware/auth.js): auth middleware · `backend/middleware/auth.js`
- [Error handler](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/middleware/errorHandler.js): error middleware · `backend/middleware/errorHandler.js`
- [Domain controllers](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/controllers/foodLogController.js): controller layer · Handles account access plus food, goal, water, and progress operations. · `backend/controllers/foodLogController.js`
- [Gemini analysis](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/services/geminiService.js): server service · Keeps AI prompts, credentials, and nutrition fallback on the server. · `backend/services/geminiService.js`

### Data & Deployment

- [Database connection](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/config/database.js): Mongoose config · `backend/config/database.js`
- [Tracker models](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/models/User.js): Mongoose models · User, food log, goal, and water log schemas. · `backend/models/User.js`
- **MongoDB Atlas**: system of record
- [Render service](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/render.yaml): deployment config · Hosts the Express API. · `render.yaml`
- [Legacy JSON migration](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/backend/scripts/migrateJsonData.js): optional import · Idempotently imports legacy records into Atlas. · `backend/scripts/migrateJsonData.js`
- [Legacy JSON data](https://github.com/karthikeyan7333/nutrition-tracker/blob/main/data/db.json): migration source · Not used as runtime storage. · `data/db.json`

## Connections

- Vite entry → App routes: mounts
- App routes → Dashboard: routes authenticated users
- Dashboard → Tracker controls: composes
- Tracker controls → Axios API client: submits and refreshes
- Axios API client → Express server: /api requests
- Vercel SPA hosting → Vite entry: serves build
- Render service → Express server: hosts
- Express server → Auth routes: mounts
- Express server → Tracker routes: mounts
- Express server → Error handler: uses
- Tracker routes → JWT middleware: validates identity
- Auth routes → Domain controllers: dispatches
- Tracker routes → Domain controllers: dispatches after auth
- Domain controllers → Tracker models: reads and writes
- Domain controllers → Gemini analysis: analyzes food entries
- Express server → Database connection: connects through
- Database connection → MongoDB Atlas: connects
- Tracker models → MongoDB Atlas: persists
- Legacy JSON migration → Legacy JSON data: imports from
- Legacy JSON migration → MongoDB Atlas: writes imported records
