# chandrakantamandal/bite-eat architecture

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

- Interactive diagram: https://gitdiagram.com/chandrakantamandal/bite-eat
- Repository: https://github.com/chandrakantamandal/bite-eat

## Overview

1. **High-level shape**
   - BiteEat is split into a **React/Vite frontend** in `client/` and an **Express/MongoDB backend** in `server/`.
   - The browser talks to the API over HTTP, and authenticated requests rely on **cookies carrying JWT auth state**.

2. **Frontend shell and navigation**
   - The client entrypoint (`main.jsx`) mounts the app, and `AppRoutes.jsx` centralizes route selection and protection.
   - `ProtectedRoute.jsx` gates access based on authentication and account type, so the UI can separate **normal users** from **food partners**.
   - `AppLoader.jsx` is used as a themed loading state during route transitions and auth checks.

3. **Frontend feature boundaries**
   - `src/pages/auth/` contains the complete auth flow: choose role, login/register screens for both account types, plus auth context/hook/service layers.
   - `src/pages/general/` holds user-facing screens like **Home**, **Saved**, and **AccountProfile**.
   - `src/pages/food-partner/` holds partner-only screens like **CreateFood** and **Profile**, plus a separate context/hook/service stack.
   - `src/components/` contains reusable UI pieces like `ReelFeed` and `BottomNav`, which are part of the main browsing experience.

4. **Frontend state/data flow pattern**
   - The repo uses a consistent layering of **service → context → hook → UI** for both auth and food features.
   - `auth.api.js` and `food.api.js` are the network boundaries; they call backend endpoints via Axios.
   - `auth.context.jsx` / `FoodContext.jsx` store session and feature state, while `useAuth.js` / `useFood.js` expose that state to pages and components.

5. **User browsing experience**
   - The core user loop is: fetch food posts, render them in `ReelFeed`, and allow **like/save** interactions.
   - `Home` is the main feed entry point, `Saved` is the saved-items view, and `AccountProfile` is the shared account management page.
   - `BottomNav` provides the persistent navigation for the user-facing flow.

6. **Food partner workflow**
   - Food partners use `CreateFood` to publish posts and `Profile` to manage their account view.
   - The partner flow is distinct from the user flow all the way from registration/login screens to routing and context.
   - Video creation is the main partner write path; it is not just text content.

7. **Backend app structure**
   - `server.js` is the runtime entrypoint, while `src/app.js` configures the Express app.
   - `src/db/db.js` handles MongoDB connection setup.
   - Routes are split cleanly by domain: `auth.routes.js` and `food.routes.js`, each backed by dedicated controllers.

8. **Authentication backend**
   - `auth.controller.js` handles registration, login, logout, and `me` endpoints for both users and food partners.
   - The existence of `blacklistToken.model.js` indicates logout/invalidation is tracked server-side, not just by clearing the client cookie.
   - `auth.middlerwares.js` provides auth protection for endpoints that need a verified session.

9. **Food backend**
   - `food.controllers.js` powers the feed and interaction APIs: listing posts, creating posts, liking, saving, and fetching partner-specific food items.
   - `food.model.js` is the main content record, likely linking posts to their owner account and to engagement state.
   - The route surface matches the feature set exposed by the frontend: browse, interact, and create.

10. **Upload and storage boundary**
   - `services/storage.services.js` is the external integration point for **ImageKit** uploads.
   - `multer` is used as the multipart ingestion layer before files are sent to storage.
   - This means the create-food flow crosses three layers: frontend upload form, backend upload handling, and third-party media storage.

11. **Persistence model**
   - MongoDB via Mongoose backs the main entities: `user.model.js`, `foodpartner.modle.js`, `food.model.js`, and token blacklist state.
   - The backend therefore persists both **identity/account data** and **content/feed data** in the same database, but in separate collections.

12. **Cross-cutting runtime constraints**
   - The frontend is developed with **Vite** and runs on `http://localhost:5173`.
   - The backend is configured for **CORS from the Vite origin**, and the API runs on `http://localhost:3000` by default.
   - Environment variables cover MongoDB, JWT, and ImageKit credentials, so those are required infrastructure dependencies for the system to function.

13. **What to show in an architecture diagram**
   - A useful diagram should emphasize four boundaries: **client UI**, **client state/network layer**, **Express API**, and **MongoDB/ImageKit**.
   - The main flows are:  
     - auth request → JWT cookie/session → protected route rendering  
     - feed request → food API → MongoDB → ReelFeed  
     - create-food upload → multer/ImageKit → stored media URL → food document

Main entry points: [`client/src/routes/AppRoutes.jsx`](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/routes/AppRoutes.jsx) (Routes), [`server/src/controllers/auth.controller.js`](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/controllers/auth.controller.js) (Auth controller), [`server/src/app.js`](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/app.js) (Express app), [`client/src/pages/auth`](https://github.com/chandrakantamandal/bite-eat/tree/main/client/src/pages/auth) (Auth stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_client_entry["App entry<br/>Vite mount<br/>[main.jsx]"]
  node_client_routes["Routes<br/>route shell<br/>[AppRoutes.jsx]"]
  node_client_protected["Protected route<br/>auth gate<br/>[ProtectedRoute.jsx]"]
  node_client_loader(("App loader<br/>ui state<br/>[AppLoader.jsx]"))
  node_client_auth_stack["Auth stack<br/>feature layer"]
  node_client_general_pages["User pages<br/>screens"]
  node_client_partner_stack["Partner stack<br/>feature layer"]
  node_client_feed["Reel feed<br/>feed ui<br/>[ReelFeed.jsx]"]
  node_client_nav["Bottom nav<br/>navigation ui<br/>[BottomNav.jsx]"]
  node_client_auth_api["Auth API<br/>HTTP client<br/>[auth.api.js]"]
  node_client_auth_ctx["Auth context<br/>session state<br/>[auth.context.jsx]"]
  node_client_auth_hook["useAuth<br/>hook<br/>[useAuth.js]"]
  node_client_food_api["Food API<br/>HTTP client<br/>[food.api.js]"]
  node_client_food_ctx["Food context<br/>feature state<br/>[FoodContext.jsx]"]
  node_client_food_hook["useFood<br/>hook<br/>[useFood.js]"]
end

subgraph group_server["Server"]
  node_server_entry["Server entry<br/>Node runtime<br/>[server.js]"]
  node_server_app["Express app<br/>API shell<br/>[app.js]"]
  node_server_db[("Mongo connect<br/>database setup<br/>[db.js]")]
  node_server_auth_ctrl["Auth controller<br/>auth API<br/>[auth.controller.js]"]
  node_server_food_ctrl["Food controller<br/>feed API"]
  node_server_auth_mw["Auth middleware<br/>session guard"]
  node_server_auth_routes["Auth routes<br/>route set<br/>[auth.routes.js]"]
  node_server_food_routes["Food routes<br/>route set<br/>[food.routes.js]"]
  node_server_user_model[("User model<br/>Mongoose model<br/>[user.model.js]")]
  node_server_partner_model[("Partner model<br/>Mongoose model")]
  node_server_food_model[("Food model<br/>Mongoose model<br/>[food.model.js]")]
  node_server_blacklist[("Token blacklist<br/>Mongoose model")]
  node_server_storage["Storage service<br/>media upload"]
end

subgraph group_external["External"]
  node_external_mongo[("MongoDB<br/>datastore")]
  node_external_imagekit[("ImageKit<br/>media CDN")]
  node_external_browser(("Browser<br/>runtime"))
end

node_external_browser -->|"loads"| node_client_entry
node_client_entry -->|"mounts"| node_client_routes
node_client_routes -->|"guards"| node_client_protected
node_client_routes -->|"shows"| node_client_loader
node_client_routes -->|"auth pages"| node_client_auth_stack
node_client_routes -->|"user pages"| node_client_general_pages
node_client_routes -->|"partner pages"| node_client_partner_stack
node_client_general_pages -->|"renders"| node_client_feed
node_client_general_pages -->|"uses"| node_client_nav
node_client_auth_stack -->|"requests"| node_client_auth_api
node_client_auth_stack -->|"stores"| node_client_auth_ctx
node_client_auth_hook -->|"reads"| node_client_auth_ctx
node_client_partner_stack -->|"requests"| node_client_food_api
node_client_partner_stack -->|"stores"| node_client_food_ctx
node_client_food_hook -->|"reads"| node_client_food_ctx
node_client_auth_api -->|"HTTP"| node_server_auth_routes
node_client_food_api -->|"HTTP"| node_server_food_routes
node_server_entry -->|"starts"| node_server_app
node_server_app -->|"connects"| node_server_db
node_server_app -->|"mounts"| node_server_auth_routes
node_server_app -->|"mounts"| node_server_food_routes
node_server_auth_routes -->|"delegates"| node_server_auth_ctrl
node_server_food_routes -->|"delegates"| node_server_food_ctrl
node_server_auth_ctrl -->|"protects"| node_server_auth_mw
node_server_auth_ctrl -->|"reads/writes"| node_server_user_model
node_server_auth_ctrl -->|"reads/writes"| node_server_partner_model
node_server_auth_ctrl -->|"invalidates"| node_server_blacklist
node_server_food_ctrl -->|"reads/writes"| node_server_food_model
node_server_food_ctrl -->|"uploads"| node_server_storage
node_server_storage -->|"stores media"| node_external_imagekit
node_server_user_model -->|"persists"| node_external_mongo
node_server_partner_model -->|"persists"| node_external_mongo
node_server_food_model -->|"persists"| node_external_mongo
node_server_blacklist -->|"persists"| node_external_mongo
node_client_auth_ctx -->|"session state"| node_client_protected
node_client_food_ctx -->|"feed state"| node_client_feed

click node_client_entry "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/main.jsx"
click node_client_routes "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/routes/AppRoutes.jsx"
click node_client_protected "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/routes/ProtectedRoute.jsx"
click node_client_loader "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/components/AppLoader.jsx"
click node_client_auth_stack "https://github.com/chandrakantamandal/bite-eat/tree/main/client/src/pages/auth"
click node_client_general_pages "https://github.com/chandrakantamandal/bite-eat/tree/main/client/src/pages/general"
click node_client_partner_stack "https://github.com/chandrakantamandal/bite-eat/tree/main/client/src/pages/food-partner"
click node_client_feed "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/components/ReelFeed.jsx"
click node_client_nav "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/components/BottomNav.jsx"
click node_client_auth_api "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/auth/services/auth.api.js"
click node_client_auth_ctx "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/auth/auth.context.jsx"
click node_client_auth_hook "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/auth/hook/useAuth.js"
click node_client_food_api "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/food-partner/services/food.api.js"
click node_client_food_ctx "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/food-partner/FoodContext.jsx"
click node_client_food_hook "https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/food-partner/hooks/useFood.js"
click node_server_entry "https://github.com/chandrakantamandal/bite-eat/blob/main/server/server.js"
click node_server_app "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/app.js"
click node_server_db "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/db/db.js"
click node_server_auth_ctrl "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/controllers/auth.controller.js"
click node_server_food_ctrl "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/controllers/food.controllers.js"
click node_server_auth_mw "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/middlewares/auth.middlerwares.js"
click node_server_auth_routes "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/routes/auth.routes.js"
click node_server_food_routes "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/routes/food.routes.js"
click node_server_user_model "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/models/user.model.js"
click node_server_partner_model "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/models/foodpartner.modle.js"
click node_server_food_model "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/models/food.model.js"
click node_server_blacklist "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/models/blacklistToken.model.js"
click node_server_storage "https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/services/storage.services.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_client_entry,node_client_routes,node_client_protected,node_client_loader,node_client_auth_stack,node_client_general_pages,node_client_partner_stack,node_client_feed,node_client_nav,node_client_auth_api,node_client_auth_ctx,node_client_auth_hook,node_client_food_api,node_client_food_ctx,node_client_food_hook toneBlue
class node_server_entry,node_server_app,node_server_db,node_server_auth_ctrl,node_server_food_ctrl,node_server_auth_mw,node_server_auth_routes,node_server_food_routes,node_server_user_model,node_server_partner_model,node_server_food_model,node_server_blacklist,node_server_storage toneAmber
class node_external_mongo,node_external_imagekit,node_external_browser toneMint
```

## Components

### Client

React/Vite frontend with route, state, and feature pages

- [App entry](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/main.jsx): Vite mount · Bootstraps the React app in the browser · `client/src/main.jsx`
- [Routes](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/routes/AppRoutes.jsx): route shell · Central route selection and access control · `client/src/routes/AppRoutes.jsx`
- [Protected route](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/routes/ProtectedRoute.jsx): auth gate · Blocks or allows pages by session and account type · `client/src/routes/ProtectedRoute.jsx`
- [App loader](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/components/AppLoader.jsx): ui state · Shared loading view for auth and navigation transitions · `client/src/components/AppLoader.jsx`
- [Auth stack](https://github.com/chandrakantamandal/bite-eat/tree/main/client/src/pages/auth): feature layer · Login and register flows with auth state and network calls · `client/src/pages/auth`
- [User pages](https://github.com/chandrakantamandal/bite-eat/tree/main/client/src/pages/general): screens · Home, saved items, and account profile screens · `client/src/pages/general`
- [Partner stack](https://github.com/chandrakantamandal/bite-eat/tree/main/client/src/pages/food-partner): feature layer · Food partner create and profile flows with feature state and requests · `client/src/pages/food-partner`
- [Reel feed](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/components/ReelFeed.jsx): feed ui · Renders food posts and engagement actions in the main browsing loop · `client/src/components/ReelFeed.jsx`
- [Bottom nav](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/components/BottomNav.jsx): navigation ui · Persistent navigation for user-facing browsing · `client/src/components/BottomNav.jsx`
- [Auth API](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/auth/services/auth.api.js): HTTP client · Axios boundary for authentication requests · `client/src/pages/auth/services/auth.api.js`
- [Auth context](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/auth/auth.context.jsx): session state · Stores auth session and account identity · `client/src/pages/auth/auth.context.jsx`
- [useAuth](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/auth/hook/useAuth.js): hook · Exposes auth state and actions to UI · `client/src/pages/auth/hook/useAuth.js`
- [Food API](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/food-partner/services/food.api.js): HTTP client · Axios boundary for feed and create-food requests · `client/src/pages/food-partner/services/food.api.js`
- [Food context](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/food-partner/FoodContext.jsx): feature state · Stores partner feature state and food-related data · `client/src/pages/food-partner/FoodContext.jsx`
- [useFood](https://github.com/chandrakantamandal/bite-eat/blob/main/client/src/pages/food-partner/hooks/useFood.js): hook · Exposes food feature state and actions to UI · `client/src/pages/food-partner/hooks/useFood.js`

### Server

Express API, controllers, models, and integrations

- [Server entry](https://github.com/chandrakantamandal/bite-eat/blob/main/server/server.js): Node runtime · Starts the API process · `server/server.js`
- [Express app](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/app.js): API shell · Configures middleware and routes · `server/src/app.js`
- [Mongo connect](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/db/db.js): database setup · Initializes the MongoDB connection · `server/src/db/db.js`
- [Auth controller](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/controllers/auth.controller.js): auth API · Handles register, login, logout, and me endpoints · `server/src/controllers/auth.controller.js`
- [Food controller](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/controllers/food.controllers.js): feed API · Handles listing, creating, liking, saving, and partner food endpoints · `server/src/controllers/food.controllers.js`
- [Auth middleware](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/middlewares/auth.middlerwares.js): session guard · Verifies protected requests and session state · `server/src/middlewares/auth.middlerwares.js`
- [Auth routes](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/routes/auth.routes.js): route set · Authentication endpoint surface · `server/src/routes/auth.routes.js`
- [Food routes](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/routes/food.routes.js): route set · Feed and creation endpoint surface · `server/src/routes/food.routes.js`
- [User model](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/models/user.model.js): Mongoose model · Stores normal user account data · `server/src/models/user.model.js`
- [Partner model](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/models/foodpartner.modle.js): Mongoose model · Stores food partner account data · `server/src/models/foodpartner.modle.js`
- [Food model](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/models/food.model.js): Mongoose model · Stores food posts and engagement data · `server/src/models/food.model.js`
- [Token blacklist](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/models/blacklistToken.model.js): Mongoose model · Tracks invalidated JWT sessions server-side · `server/src/models/blacklistToken.model.js`
- [Storage service](https://github.com/chandrakantamandal/bite-eat/blob/main/server/src/services/storage.services.js): media upload · Integrates multipart uploads with ImageKit storage · `server/src/services/storage.services.js`

### External

Infrastructure and third-party services

- **MongoDB**: datastore · Persistent backing store for accounts, posts, and token blacklist state
- **ImageKit**: media CDN · External media storage and delivery for uploaded food content
- **Browser**: runtime · Client runtime that renders the React app and sends requests

## Connections

- Browser → App entry: loads · The browser loads the React/Vite application
- App entry → Routes: mounts · App entry mounts the route shell
- Routes → Protected route: guards · Protected routes gate user and partner pages
- Routes → App loader: shows · Route transitions and auth checks can display the loader
- Routes → Auth stack: auth pages · Routes include the login and registration flow
- Routes → User pages: user pages · Routes include user-facing screens
- Routes → Partner stack: partner pages · Routes include food partner screens
- User pages → Reel feed: renders · Home uses the feed UI to display food posts
- User pages → Bottom nav: uses · User pages share persistent navigation
- Auth stack → Auth API: requests · Auth screens call the auth HTTP client
- Auth stack → Auth context: stores · Auth flow writes session state into context
- useAuth → Auth context: reads · The hook exposes auth context to components
- Partner stack → Food API: requests · Partner screens call the food HTTP client
- Partner stack → Food context: stores · Partner flow writes feature state into context
- useFood → Food context: reads · The hook exposes food feature state to components
- Auth API → Auth routes: HTTP · Auth requests go to the backend auth routes
- Food API → Food routes: HTTP · Food requests go to the backend food routes
- Server entry → Express app: starts · Server entry boots the Express app
- Express app → Mongo connect: connects · App startup initializes MongoDB connectivity
- Express app → Auth routes: mounts · Express mounts the auth route set
- Express app → Food routes: mounts · Express mounts the food route set
- Auth routes → Auth controller: delegates · Auth routes are handled by the auth controller
- Food routes → Food controller: delegates · Food routes are handled by the food controller
- Auth controller → Auth middleware: protects · Protected auth flows use session verification
- Auth controller → User model: reads/writes · User login and registration persist account records
- Auth controller → Partner model: reads/writes · Partner login and registration persist partner records
- Auth controller → Token blacklist: invalidates · Logout records revoked tokens server-side
- Food controller → Food model: reads/writes · Food controller manages post and engagement documents
- Food controller → Storage service: uploads · Create-food flow sends media through the storage service
- Storage service → ImageKit: stores media · Uploaded files are stored and delivered via ImageKit
- User model → MongoDB: persists · User accounts are stored in MongoDB
- Partner model → MongoDB: persists · Partner accounts are stored in MongoDB
- Food model → MongoDB: persists · Food posts are stored in MongoDB
- Token blacklist → MongoDB: persists · Blacklisted tokens are stored in MongoDB
- Auth context → Protected route: session state · Protected routing consumes auth session state
- Food context → Reel feed: feed state · Feed and create-food views consume food state
