# akash2xd/akash-scafe architecture

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

- Interactive diagram: https://gitdiagram.com/akash2xd/akash-scafe
- Repository: https://github.com/akash2xd/akash-scafe

## Overview

1. **Repository shape**
   - This is a two-tier application: a **React frontend** in `frontend/` and an **Express + MongoDB backend** in `backend/`.
   - The product is a café ordering system, not just a marketing site: users can browse items, build a cart, place orders, review items, and track orders; admins can manage inventory and orders.

2. **Frontend application shell**
   - The frontend is a **Vite React** app (`main.jsx`, `App.jsx`, `vite.config.js`), despite the README mentioning Next.js.
   - Global styling lives in `src/index.css`, and the app includes shared UI helpers like `Loader`, `ToastContainer`, and `ScrollToTop`.
   - Static media is a major part of the UI: menu imagery and promo video assets are stored in both `public/assets` and `src/assets`.

3. **Frontend state and cross-cutting concerns**
   - Shared application state is organized through React context:
     - `AuthContext` for login/session state
     - `CartContext` for basket contents and checkout prep
     - `LoadingContext` for UI loading state
     - `SocketContext` for real-time updates
   - This suggests the frontend is designed around global state rather than page-local state only.

4. **Customer-facing UI flow**
   - The customer experience is composed from modular components such as `HeroSection`, `Dishes`, `DishCard`, `AddOnModal`, `Cart`, `CheckoutPage`, `DeliveryForm`, `MyOrders`, `RatingPage`, and `Review`.
   - The structure implies a flow of: browse menu → inspect item/add-ons → add to cart → checkout → provide delivery details → view orders / submit ratings.

5. **Content and informational pages**
   - The app also includes policy and support pages: `PrivacyPolicyPage`, `TermsPage`, `ShippingDeliveryPage`, `CancellationRefundPage`, and `ContactSection`.
   - These are wrapped by `PolicyLayout`, indicating a separate layout pattern for legal/help content versus the main ordering flow.

6. **Admin-facing surface**
   - Admin functionality is isolated into dedicated components: `AdminLogin`, `AdminDashboard`, `AdminInventory`, `AdminOrderDashboard`, and `AdminInvoices`.
   - This is a separate operational lane from the customer UI, likely used for product management, order handling, and billing oversight.

7. **Backend API structure**
   - The backend is organized by domain with route and controller layers:
     - `auth`, `admin`, `product`, `cart`, `order`, `payment`, `delivery`, and `review`
   - Controllers mirror those domains in `src/controllers/`, which keeps business logic separated from route wiring.
   - There are also route variants like `productRoutes.js` and `reviewRoutes.js`, suggesting either legacy naming or alternate route grouping.

8. **Backend data model layer**
   - MongoDB models are defined for the core entities:
     - `User`
     - `Product`
     - `Order`
     - `Review`
   - This model set matches the app’s main business objects: accounts, catalog items, purchases, and feedback.

9. **Backend infrastructure and boundaries**
   - `config/db.js` handles database connectivity.
   - `middlewares/authMiddleware.js` protects authenticated/admin-only actions.
   - `config/mailer.js` and `utils/smsSender.js` indicate outbound notifications via email and SMS.
   - `seed.js` provides initial data loading, which matters for bootstrapping menu/catalog content.

10. **Operational data flow**
   - The likely end-to-end flow is:
     - frontend requests catalog data from product endpoints
     - cart state is built client-side and may sync to backend
     - checkout creates an order and payment intent/result
     - backend triggers delivery/order notifications and status updates
     - frontend reads updated order state via API and possibly sockets
   - This architecture splits interactive UI state from durable server-side order state.

11. **External services and integrations**
   - MongoDB is the primary persistence layer.
   - Email and SMS are first-class integration points for customer communication.
   - Real-time socket support on the frontend implies live order or status updates are part of the system design, even though the backend socket implementation is not visible in the tree.

12. **What to emphasize in a diagram**
   - Show a clear boundary between **customer/admin React UI** and the **Express API**.
   - Inside the backend, separate **routes**, **controllers**, **models**, and **integrations**.
   - On the frontend, emphasize **context providers** and **feature components** rather than page-only routing.
   - Highlight the order lifecycle as the central business flow connecting catalog, cart, payment, delivery, and admin operations.

Main entry points: [`backend/src/controllers`](https://github.com/akash2xd/akash-scafe/tree/main/backend/src/controllers) (Controllers), [`frontend/src/components/Dishes.jsx`](https://github.com/akash2xd/akash-scafe/blob/main/frontend/src/components/Dishes.jsx) (Customer flow), [`frontend/src/main.jsx`](https://github.com/akash2xd/akash-scafe/blob/main/frontend/src/main.jsx) (App shell), [`frontend/src/context`](https://github.com/akash2xd/akash-scafe/tree/main/frontend/src/context) (Contexts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_fe_shell["App shell<br/>Vite React entry<br/>[main.jsx]"]
  node_fe_contexts{{"Contexts<br/>React context"}}
  node_fe_customer["Customer flow<br/>UI features<br/>[Dishes.jsx]"]
  node_fe_admin["Admin surface<br/>UI features<br/>[AdminDashboard.jsx]"]
  node_fe_policy["Policy pages<br/>Content layout<br/>[PolicyLayout.jsx]"]
  node_fe_assets[("Media assets<br/>Static media")]
end

subgraph group_backend["Backend"]
  node_be_server["API server<br/>Express app<br/>[server.js]"]
  node_be_routes["Routes<br/>HTTP routing"]
  node_be_controllers["Controllers<br/>business logic"]
  node_be_models[("Models")]
  node_be_auth{{"Auth guard<br/>middleware<br/>[authMiddleware.js]"}}
  node_be_db["Mongo config<br/>database config<br/>[db.js]"]
  node_be_notifications["Notifications<br/>integrations<br/>[mailer.js]"]
  node_be_seed["Seed data<br/>bootstrap<br/>[seed.js]"]
  node_be_auth_route["Auth API<br/>route module<br/>[auth.js]"]
  node_be_catalog_route["Catalog API<br/>route module<br/>[product.js]"]
  node_be_order_route["Order API<br/>route module<br/>[order.js]"]
  node_be_admin_route["Admin API<br/>route module<br/>[admin.js]"]
  node_be_review_route["Review API<br/>route module<br/>[reviewRoutes.js]"]
end

node_fe_shell -->|"provides state"| node_fe_contexts
node_fe_shell -->|"renders"| node_fe_customer
node_fe_shell -->|"renders"| node_fe_admin
node_fe_shell -->|"routes to"| node_fe_policy
node_fe_customer -->|"uses media"| node_fe_assets
node_fe_admin -->|"calls"| node_be_admin_route
node_fe_customer -->|"fetches catalog"| node_be_catalog_route
node_fe_customer -->|"checks out"| node_be_order_route
node_fe_customer -->|"submits reviews"| node_be_review_route
node_fe_contexts -->|"auth state"| node_be_auth_route
node_fe_contexts -->|"syncs cart"| node_be_order_route
node_be_server -->|"mounts"| node_be_routes
node_be_routes -->|"delegates"| node_be_controllers
node_be_controllers -->|"reads/writes"| node_be_models
node_be_controllers -->|"protects"| node_be_auth
node_be_server -->|"connects"| node_be_db
node_be_controllers -->|"sends alerts"| node_be_notifications
node_be_seed -.->|"loads"| node_be_models
node_be_catalog_route -->|"uses"| node_be_controllers
node_be_order_route -->|"uses"| node_be_controllers
node_be_admin_route -->|"uses"| node_be_controllers
node_be_review_route -->|"uses"| node_be_controllers

click node_fe_shell "https://github.com/akash2xd/akash-scafe/blob/main/frontend/src/main.jsx"
click node_fe_contexts "https://github.com/akash2xd/akash-scafe/tree/main/frontend/src/context"
click node_fe_customer "https://github.com/akash2xd/akash-scafe/blob/main/frontend/src/components/Dishes.jsx"
click node_fe_admin "https://github.com/akash2xd/akash-scafe/blob/main/frontend/src/components/AdminDashboard.jsx"
click node_fe_policy "https://github.com/akash2xd/akash-scafe/blob/main/frontend/src/components/PolicyLayout.jsx"
click node_fe_assets "https://github.com/akash2xd/akash-scafe/tree/main/frontend/src/assets"
click node_be_server "https://github.com/akash2xd/akash-scafe/blob/main/backend/src/server.js"
click node_be_routes "https://github.com/akash2xd/akash-scafe/tree/main/backend/src/routes"
click node_be_controllers "https://github.com/akash2xd/akash-scafe/tree/main/backend/src/controllers"
click node_be_models "https://github.com/akash2xd/akash-scafe/tree/main/backend/src/models"
click node_be_auth "https://github.com/akash2xd/akash-scafe/blob/main/backend/src/middlewares/authMiddleware.js"
click node_be_db "https://github.com/akash2xd/akash-scafe/blob/main/backend/src/config/db.js"
click node_be_notifications "https://github.com/akash2xd/akash-scafe/blob/main/backend/src/config/mailer.js"
click node_be_seed "https://github.com/akash2xd/akash-scafe/blob/main/backend/src/seed.js"
click node_be_auth_route "https://github.com/akash2xd/akash-scafe/blob/main/backend/src/routes/auth.js"
click node_be_catalog_route "https://github.com/akash2xd/akash-scafe/blob/main/backend/src/routes/product.js"
click node_be_order_route "https://github.com/akash2xd/akash-scafe/blob/main/backend/src/routes/order.js"
click node_be_admin_route "https://github.com/akash2xd/akash-scafe/blob/main/backend/src/routes/admin.js"
click node_be_review_route "https://github.com/akash2xd/akash-scafe/blob/main/backend/src/routes/reviewRoutes.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_fe_shell,node_fe_contexts,node_fe_customer,node_fe_admin,node_fe_policy,node_fe_assets toneBlue
class node_be_server,node_be_routes,node_be_controllers,node_be_models,node_be_auth,node_be_db,node_be_notifications,node_be_seed,node_be_auth_route,node_be_catalog_route,node_be_order_route,node_be_admin_route,node_be_review_route toneAmber
```

## Components

### Frontend

React/Vite customer and admin UI

- [App shell](https://github.com/akash2xd/akash-scafe/blob/main/frontend/src/main.jsx): Vite React entry · Frontend bootstrapping and global styles · `frontend/src/main.jsx`
- [Contexts](https://github.com/akash2xd/akash-scafe/tree/main/frontend/src/context): React context · Auth, cart, loading, and socket state · `frontend/src/context`
- [Customer flow](https://github.com/akash2xd/akash-scafe/blob/main/frontend/src/components/Dishes.jsx): UI features · Browse menu, cart, checkout, orders, and reviews · `frontend/src/components/Dishes.jsx`
- [Admin surface](https://github.com/akash2xd/akash-scafe/blob/main/frontend/src/components/AdminDashboard.jsx): UI features · Admin login, dashboard, inventory, orders, and invoices · `frontend/src/components/AdminDashboard.jsx`
- [Policy pages](https://github.com/akash2xd/akash-scafe/blob/main/frontend/src/components/PolicyLayout.jsx): Content layout · Legal, support, and informational pages · `frontend/src/components/PolicyLayout.jsx`
- [Media assets](https://github.com/akash2xd/akash-scafe/tree/main/frontend/src/assets): Static media · Menu imagery, gallery media, and promo video · `frontend/src/assets`

### Backend

Express API, data, and integrations

- [API server](https://github.com/akash2xd/akash-scafe/blob/main/backend/src/server.js): Express app · Backend entrypoint and HTTP server · `backend/src/server.js`
- [Routes](https://github.com/akash2xd/akash-scafe/tree/main/backend/src/routes): HTTP routing · Domain route wiring for auth, catalog, cart, orders, payments, and admin · `backend/src/routes`
- [Controllers](https://github.com/akash2xd/akash-scafe/tree/main/backend/src/controllers): business logic · Request handling for core domains · `backend/src/controllers`
- [Models](https://github.com/akash2xd/akash-scafe/tree/main/backend/src/models): MongoDB models · User, product, order, and review documents · `backend/src/models`
- [Auth guard](https://github.com/akash2xd/akash-scafe/blob/main/backend/src/middlewares/authMiddleware.js): middleware · Authentication and authorization checks · `backend/src/middlewares/authMiddleware.js`
- [Mongo config](https://github.com/akash2xd/akash-scafe/blob/main/backend/src/config/db.js): database config · Database connection setup · `backend/src/config/db.js`
- [Notifications](https://github.com/akash2xd/akash-scafe/blob/main/backend/src/config/mailer.js): integrations · Email and SMS outbound messaging · `backend/src/config/mailer.js`
- [Seed data](https://github.com/akash2xd/akash-scafe/blob/main/backend/src/seed.js): bootstrap · Initial catalog and data loading · `backend/src/seed.js`
- [Auth API](https://github.com/akash2xd/akash-scafe/blob/main/backend/src/routes/auth.js): route module · Login and session endpoints · `backend/src/routes/auth.js`
- [Catalog API](https://github.com/akash2xd/akash-scafe/blob/main/backend/src/routes/product.js): route module · Product browsing and menu endpoints · `backend/src/routes/product.js`
- [Order API](https://github.com/akash2xd/akash-scafe/blob/main/backend/src/routes/order.js): route module · Cart, order, and payment endpoints · `backend/src/routes/order.js`
- [Admin API](https://github.com/akash2xd/akash-scafe/blob/main/backend/src/routes/admin.js): route module · Admin operations for inventory and orders · `backend/src/routes/admin.js`
- [Review API](https://github.com/akash2xd/akash-scafe/blob/main/backend/src/routes/reviewRoutes.js): route module · Customer review endpoints · `backend/src/routes/reviewRoutes.js`

## Connections

- App shell → Contexts: provides state · App shell composes global providers
- App shell → Customer flow: renders · Main UI mounts ordering flow
- App shell → Admin surface: renders · Admin area is part of the same frontend
- App shell → Policy pages: routes to · Legal and support pages use a separate layout
- Customer flow → Media assets: uses media · Menu and promo visuals come from static assets
- Admin surface → Admin API: calls · Admin UI operates through admin endpoints
- Customer flow → Catalog API: fetches catalog · Menu browsing reads product data from API
- Customer flow → Order API: checks out · Cart and order submission flow to backend
- Customer flow → Review API: submits reviews · Ratings and feedback are persisted server-side
- Contexts → Auth API: auth state · Login/session context depends on auth endpoints
- Contexts → Order API: syncs cart · Cart and socket state coordinate with order lifecycle
- API server → Routes: mounts · Server wires route modules
- Routes → Controllers: delegates · Routes forward requests to domain controllers
- Controllers → Models: reads/writes · Controllers persist and query MongoDB models
- Controllers → Auth guard: protects · Sensitive actions are guarded by middleware
- API server → Mongo config: connects · Server initializes MongoDB connection
- Controllers → Notifications: sends alerts · Orders and delivery events can trigger email/SMS
- Seed data → Models: loads · Bootstrap data populates core collections
- Catalog API → Controllers: uses · Product routes map to product controller logic
- Order API → Controllers: uses · Order/payment/cart routes map to corresponding controllers
- Admin API → Controllers: uses · Admin endpoints reuse admin controller logic
- Review API → Controllers: uses · Review routes map to review controller logic
