# sshgurkiratsingh/istc_major_project architecture

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

- Interactive diagram: https://gitdiagram.com/sshgurkiratsingh/istc_major_project
- Repository: https://github.com/sshgurkiratsingh/istc_major_project

## Overview

1. This repository is a multi-part campus project, not a single app. It contains three main runtime surfaces: a Next.js frontend, a Node/Express backend, and an ESP32 firmware project for the physical drink dispenser.

2. The frontend is the primary user interface and is organized by route groups. The important boundaries are `/user/[tableID]` for table-specific customer ordering, `/admin` for staff operations, `/customMusic` for Spotify search, `/mqttDashboard` for broker message inspection, and `/marks` for the exam/marks module. Shared UI lives under `app/component`.

3. The customer flow starts from a table QR code that opens `/user/{tableID}`. That page renders the ordering experience, cart, checkout, mobile input, RFID login, and the AI chat panel. It uses `APIconfig.ts` to talk to the backend rather than embedding business logic locally.

4. The admin side is a separate operational console. It consumes the same backend data but focuses on table occupancy, order lifecycle, user CRUD, RFID assignment, and order history/reporting. This is a staff-only control plane, distinct from the customer ordering path.

5. The backend is an Express API server and is the system’s main orchestration layer. Its route modules split responsibilities cleanly: `itemListRoute.js` handles menu, cart, orders, tables, and reports; `userRoute.js` handles phone/RFID users and cart sync; `llmRoute.js` wraps the AI assistant; `mqttData.js` bridges MQTT publish/logging; and `spotifyRoutes.js` handles Spotify search and playback control.

6. Persistence is centralized through Prisma with MongoDB. The schema is small and domain-focused: `FoodItem` and `AddOn` represent the menu, `UserCart` stores user identity plus saved cart state, and `Order` stores table orders, payment status, lifecycle state, and history. That means both customer and admin UI are reading/writing the same operational database.

7. The real-time hardware boundary is MQTT. The backend publishes drink dispense commands to the ESP32, and the ESP32 subscribes to the dispenser topic to drive relays. The firmware also publishes status/buzzer-related feedback, so MQTT is the integration bus between software orders and the physical machine.

8. The ESP32 project is a separate embedded application built with PlatformIO. Its `main.cpp` is responsible for Wi‑Fi connection, MQTT client behavior, relay control for drink pumps/valves, button inputs for manual dispensing, and LED/status signaling. It is a hardware endpoint, not a web client.

9. Two external service integrations are first-class architecture concerns: OpenAI for the chat assistant and Spotify Web API for music search/playback. The assistant route uses current menu/cart/order context so it can answer transaction-aware questions, while Spotify routes and frontend music pages provide playback and queue management.

10. The repository also contains two secondary frontend modules that are independent of the café order path. The `marks` area loads PDFs and JSON from `public/` to support exam/question-paper viewing and mark-sheet generation, while `customMusic` provides a focused Spotify search UI. These appear to be co-located modules within the same frontend app rather than separate deployments.

11. A small `cacheManager.js` module suggests the backend uses local file-based caching for some data, likely to reduce repeated fetches or expensive recomputation. This is a supporting utility, not a core domain boundary.

12. `backend/jumbleWord.cpp` is a standalone C++ program and is not part of the café system runtime. It should be treated as an unrelated utility/demo file when drawing the architecture diagram.

13. For a diagram, the key top-level boundaries are: browser/tablet frontend, admin frontend, backend API, MongoDB persistence, MQTT broker, ESP32 hardware, and external APIs (OpenAI, Spotify). The main data path is customer order → backend validation/persistence → MQTT command dispatch → dispenser execution, with admin and chat/music features reading from the same backend state.

Main entry points: [`backend/index.js`](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/index.js) (API server), [`frontend/app/layout.tsx`](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/layout.tsx) (App shell), [`frontend/app/user/[tableID]/page.tsx`](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/user/[tableID]/page.tsx) (Customer order), [`frontend/app/admin/page.tsx`](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/admin/page.tsx) (Admin console)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_shell["App shell<br/>nextjs app<br/>[layout.tsx]"]
  node_customer_order["Customer order<br/>route group<br/>[page.tsx]"]
  node_customer_checkout["Checkout<br/>ui flow<br/>[CheckoutPage.tsx]"]
  node_customer_chat["AI chat<br/>assistant UI<br/>[LlmChat.tsx]"]
  node_admin_console["Admin console<br/>staff ui<br/>[page.tsx]"]
  node_admin_tables["Table status<br/>admin view<br/>[page.tsx]"]
  node_admin_users["User admin<br/>admin view<br/>[page.tsx]"]
  node_admin_history["Order history<br/>admin view<br/>[page.tsx]"]
  node_music_ui["Music search<br/>feature page<br/>[page.tsx]"]
  node_mqtt_ui["MQTT dashboard<br/>diagnostic ui<br/>[page.tsx]"]
  node_marks_ui["Marks module<br/>content app<br/>[page.tsx]"]
end

subgraph group_backend["Backend"]
  node_api_server["API server<br/>express app<br/>[index.js]"]
  node_menu_orders["Menu & orders<br/>route module<br/>[itemListRoute.js]"]
  node_users_route["Users & carts<br/>route module<br/>[userRoute.js]"]
  node_assistant_route["LLM assistant<br/>route module<br/>[llmRoute.js]"]
  node_mqtt_bridge["MQTT bridge<br/>route module<br/>[mqttData.js]"]
  node_spotify_route["Spotify API<br/>route module<br/>[spotifyRoutes.js]"]
  node_cache_mgr["Cache manager<br/>support module<br/>[cacheManager.js]"]
  node_prisma_db[("Prisma data<br/>schema<br/>[schema.prisma]")]
end

subgraph group_firmware["ESP32 Firmware"]
  node_esp32_fw["ESP32 firmware<br/>embedded app<br/>[main.cpp]"]
end

subgraph group_external["External Systems"]
  node_mqtt_broker{{"MQTT broker<br/>message bus"}}
  node_mongo_db[("MongoDB<br/>database")]
  node_openai_api(("OpenAI<br/>external api"))
  node_spotify_api(("Spotify Web API<br/>external api"))
end

node_frontend_shell -->|"renders"| node_customer_order
node_frontend_shell -->|"renders"| node_admin_console
node_frontend_shell -->|"renders"| node_music_ui
node_frontend_shell -->|"renders"| node_mqtt_ui
node_frontend_shell -->|"renders"| node_marks_ui
node_customer_order -->|"includes"| node_customer_checkout
node_customer_order -->|"includes"| node_customer_chat
node_customer_order -->|"calls"| node_api_server
node_admin_console -->|"navigates"| node_admin_tables
node_admin_console -->|"navigates"| node_admin_users
node_admin_console -->|"navigates"| node_admin_history
node_admin_tables -->|"calls"| node_api_server
node_admin_users -->|"calls"| node_api_server
node_admin_history -->|"calls"| node_api_server
node_api_server -->|"routes"| node_menu_orders
node_api_server -->|"routes"| node_users_route
node_api_server -->|"routes"| node_assistant_route
node_api_server -->|"routes"| node_mqtt_bridge
node_api_server -->|"routes"| node_spotify_route
node_api_server -.->|"uses"| node_cache_mgr
node_menu_orders -->|"persists"| node_prisma_db
node_users_route -->|"persists"| node_prisma_db
node_assistant_route -->|"invokes"| node_openai_api
node_assistant_route -->|"reads"| node_prisma_db
node_spotify_route -->|"invokes"| node_spotify_api
node_mqtt_bridge -->|"publishes"| node_mqtt_broker
node_esp32_fw -->|"subscribes"| node_mqtt_broker
node_mqtt_broker -->|"delivers"| node_esp32_fw
node_esp32_fw -->|"publishes"| node_mqtt_broker
node_prisma_db -->|"stores"| node_mongo_db

click node_frontend_shell "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/layout.tsx"
click node_customer_order "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/user/[tableID]/page.tsx"
click node_customer_checkout "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/user/[tableID]/CheckoutPage.tsx"
click node_customer_chat "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/user/[tableID]/LlmChat.tsx"
click node_admin_console "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/admin/page.tsx"
click node_admin_tables "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/admin/tableStatus/page.tsx"
click node_admin_users "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/admin/users/page.tsx"
click node_admin_history "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/admin/orderHistory/page.tsx"
click node_music_ui "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/customMusic/page.tsx"
click node_mqtt_ui "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/mqttDashboard/page.tsx"
click node_marks_ui "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/marks/page.tsx"
click node_api_server "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/index.js"
click node_menu_orders "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/routes/itemListRoute.js"
click node_users_route "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/routes/userRoute.js"
click node_assistant_route "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/routes/llmRoute.js"
click node_mqtt_bridge "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/routes/mqttData.js"
click node_spotify_route "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/routes/spotifyRoutes.js"
click node_cache_mgr "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/customModule/cacheManager.js"
click node_prisma_db "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/prisma/schema.prisma"
click node_esp32_fw "https://github.com/sshgurkiratsingh/istc_major_project/blob/main/ESP32 Code/Drink_Dis_V0.1/src/main.cpp"

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_frontend_shell,node_customer_order,node_customer_checkout,node_customer_chat,node_admin_console,node_admin_tables,node_admin_users,node_admin_history,node_music_ui,node_mqtt_ui,node_marks_ui toneBlue
class node_api_server,node_menu_orders,node_users_route,node_assistant_route,node_mqtt_bridge,node_spotify_route,node_cache_mgr,node_prisma_db toneAmber
class node_esp32_fw toneMint
class node_mqtt_broker,node_mongo_db,node_openai_api,node_spotify_api toneRose
```

## Components

### Frontend

Next.js app with customer, admin, music, MQTT, and marks surfaces.

- [App shell](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/layout.tsx): nextjs app · Root layout, providers, and shared UI building blocks. · `frontend/app/layout.tsx`
- [Customer order](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/user/[tableID]/page.tsx): route group · Table-scoped ordering flow with cart, checkout, login, and chat. · `frontend/app/user/[tableID]/page.tsx`
- [Checkout](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/user/[tableID]/CheckoutPage.tsx): ui flow · Order finalization and payment-oriented interaction. · `frontend/app/user/[tableID]/CheckoutPage.tsx`
- [AI chat](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/user/[tableID]/LlmChat.tsx): assistant UI · Chat panel for transaction-aware menu and order help. · `frontend/app/user/[tableID]/LlmChat.tsx`
- [Admin console](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/admin/page.tsx): staff ui · Operational entry point for staff workflows. · `frontend/app/admin/page.tsx`
- [Table status](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/admin/tableStatus/page.tsx): admin view · Occupancy and table lifecycle monitoring. · `frontend/app/admin/tableStatus/page.tsx`
- [User admin](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/admin/users/page.tsx): admin view · User CRUD and RFID assignment management. · `frontend/app/admin/users/page.tsx`
- [Order history](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/admin/orderHistory/page.tsx): admin view · Order reporting and lifecycle inspection. · `frontend/app/admin/orderHistory/page.tsx`
- [Music search](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/customMusic/page.tsx): feature page · Spotify search and playback control UI. · `frontend/app/customMusic/page.tsx`
- [MQTT dashboard](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/mqttDashboard/page.tsx): diagnostic ui · Message inspection and broker connectivity tools. · `frontend/app/mqttDashboard/page.tsx`
- [Marks module](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/frontend/app/marks/page.tsx): content app · Exam PDF and JSON-based marks/question-paper workflows. · `frontend/app/marks/page.tsx`

### Backend

Express API, Prisma persistence layer, and integration routes.

- [API server](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/index.js): express app · Main orchestration layer for orders, users, chat, MQTT, and Spotify. · `backend/index.js`
- [Menu & orders](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/routes/itemListRoute.js): route module · Menu, cart, table, order, and report operations. · `backend/routes/itemListRoute.js`
- [Users & carts](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/routes/userRoute.js): route module · Phone/RFID users and cart synchronization. · `backend/routes/userRoute.js`
- [LLM assistant](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/routes/llmRoute.js): route module · OpenAI-backed chat orchestration with context from menu and orders. · `backend/routes/llmRoute.js`
- [MQTT bridge](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/routes/mqttData.js): route module · Publish and log drink dispenser commands and broker data. · `backend/routes/mqttData.js`
- [Spotify API](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/routes/spotifyRoutes.js): route module · Search and playback control for music features. · `backend/routes/spotifyRoutes.js`
- [Cache manager](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/customModule/cacheManager.js): support module · Local file-based caching for repeated or expensive backend data. · `backend/customModule/cacheManager.js`
- [Prisma data](https://github.com/sshgurkiratsingh/istc_major_project/blob/main/backend/prisma/schema.prisma): schema · MongoDB-backed schema for food items, add-ons, carts, and orders. · `backend/prisma/schema.prisma`

### ESP32 Firmware

PlatformIO embedded controller for the physical dispenser.

- [ESP32 firmware](https://github.com/sshgurkiratsingh/istc_major_project/blob/HEAD/ESP32%20Code/Drink_Dis_V0.1/src/main.cpp): embedded app · PlatformIO firmware for Wi-Fi, MQTT, relay, button, and status control. · `ESP32 Code/Drink_Dis_V0.1/src/main.cpp`

### External Systems

Third-party APIs, broker, and database boundary.

- **MQTT broker**: message bus · Integration bus between backend commands and dispenser hardware.
- **MongoDB**: database · Operational persistence for shared frontend and backend state.
- **OpenAI**: external api · Generative assistant provider.
- **Spotify Web API**: external api · Music search and playback provider.

## Connections

- App shell → Customer order: renders · Application shell hosts the main customer route group.
- App shell → Admin console: renders · Application shell hosts the staff console.
- App shell → Music search: renders · Shell also serves the music module.
- App shell → MQTT dashboard: renders · Shell also serves the MQTT dashboard.
- App shell → Marks module: renders · Shell also serves the marks module.
- Customer order → Checkout: includes · Ordering flow hands off to checkout.
- Customer order → AI chat: includes · Ordering flow embeds AI assistance.
- Customer order → API server: calls · Customer UI uses backend APIs through APIconfig.
- Admin console → Table status: navigates · Staff console links to table monitoring.
- Admin console → User admin: navigates · Staff console links to user management.
- Admin console → Order history: navigates · Staff console links to order history.
- Table status → API server: calls · Admin views consume the same operational backend.
- User admin → API server: calls · User CRUD and RFID assignment go through the API.
- Order history → API server: calls · Reporting reads backend order state.
- API server → Menu & orders: routes · Order, menu, table, and report orchestration.
- API server → Users & carts: routes · User and cart operations.
- API server → LLM assistant: routes · Chat assistant orchestration.
- API server → MQTT bridge: routes · MQTT publish and broker logging.
- API server → Spotify API: routes · Music search and playback control.
- API server → Cache manager: uses · Shared cache support for backend data.
- Menu & orders → Prisma data: persists · Menu and order data are stored through Prisma.
- Users & carts → Prisma data: persists · User and cart state are stored through Prisma.
- LLM assistant → OpenAI: invokes · Assistant calls the generative model provider.
- LLM assistant → Prisma data: reads · Assistant uses menu, cart, and order context.
- Spotify API → Spotify Web API: invokes · Backend proxies Spotify search and playback requests.
- MQTT bridge → MQTT broker: publishes · Backend publishes dispenser commands and logs.
- ESP32 firmware → MQTT broker: subscribes · Firmware listens for dispense commands over MQTT.
- MQTT broker → ESP32 firmware: delivers · Broker carries command and status messages to hardware.
- ESP32 firmware → MQTT broker: publishes · Firmware sends status and buzzer feedback.
- Prisma data → MongoDB: stores · Prisma schema is backed by MongoDB.
